Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1 | /* ---------------------------------------------------------------------------- |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 2 | * ATMEL Microcontroller Software Support |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 3 | * ---------------------------------------------------------------------------- |
| 4 | * Copyright (c) 2008, Atmel Corporation |
| 5 | * |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * - Redistributions of source code must retain the above copyright notice, |
| 12 | * this list of conditions and the disclaimer below. |
| 13 | * |
| 14 | * Atmel's name may not be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * ---------------------------------------------------------------------------- |
| 28 | */ |
| 29 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 30 | //------------------------------------------------------------------------------ |
| 31 | /// \unit |
| 32 | /// |
| 33 | /// !Purpose |
| 34 | /// |
| 35 | /// CCID driver |
| 36 | /// |
| 37 | /// !Usage |
| 38 | /// |
| 39 | /// Explanation on the usage of the code made available through the header file. |
| 40 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 41 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 42 | //------------------------------------------------------------------------------ |
| 43 | // Headers |
| 44 | //------------------------------------------------------------------------------ |
| 45 | |
| 46 | #include <board.h> |
| 47 | #include <USBDDriver.h> |
| 48 | #include <USBRequests.h> |
| 49 | #include <USBDescriptors.h> |
| 50 | //#include <usb/device/dfu/dfu.h> |
| 51 | #include <cciddriverdescriptors.h> |
| 52 | |
| 53 | // FIXME: Remove DFU related stuff |
| 54 | /* no DFU bootloader is being used */ |
| 55 | #define DFU_NUM_IF 0 |
| 56 | #define DFU_IF_DESCRIPTORS_STRUCT |
| 57 | #define DFU_IF_DESCRIPTORS |
| 58 | |
| 59 | #define DFU_NUM_STRINGS 0 |
| 60 | #define DFU_STRING_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 61 | |
| 62 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 63 | //------------------------------------------------------------------------------ |
| 64 | // Local definition |
| 65 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 66 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 67 | /// Constants: IDs: Device product ID. |
| 68 | //#define CCIDDriverDescriptors_PRODUCTID 0x6129 |
| 69 | #define CCIDDriverDescriptors_PRODUCTID SIMTRACE_PRODUCT_ID |
| 70 | /// Constants: IDs: Device vendor ID. |
| 71 | #define CCIDDriverDescriptors_VENDORID ATMEL_VENDOR_ID |
| 72 | //#define CCIDDriverDescriptors_VENDORID 0x03EB |
| 73 | /// Constants: IDs: Device release number. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 74 | #define CCIDDriverDescriptors_RELEASE 0x0100 |
| 75 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 76 | /// Returns the minimum between two values. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 77 | #define MIN(a, b) ((a < b) ? a : b) |
| 78 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 79 | //------------------------------------------------------------------------------ |
| 80 | // Types |
| 81 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 82 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 83 | /// CCIDDriverConfiguration Descriptors |
| 84 | /// List of descriptors that make up the configuration descriptors of a |
| 85 | /// device using the CCID driver. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 86 | typedef struct { |
| 87 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 88 | /// Configuration descriptor |
| 89 | USBConfigurationDescriptor configuration; |
| 90 | /// Interface descriptor |
| 91 | USBInterfaceDescriptor interface; |
| 92 | /// CCID descriptor |
| 93 | CCIDDescriptor ccid; |
| 94 | /// Bulk OUT endpoint descriptor |
| 95 | USBEndpointDescriptor bulkOut; |
| 96 | /// Bulk IN endpoint descriptor |
| 97 | USBEndpointDescriptor bulkIn; |
| 98 | /// Interrupt OUT endpoint descriptor |
| 99 | USBEndpointDescriptor interruptIn; |
| 100 | DFU_IF_DESCRIPTORS_STRUCT |
| 101 | } __attribute__ ((packed)) CCIDDriverConfigurationDescriptors; |
| 102 | |
| 103 | //------------------------------------------------------------------------------ |
| 104 | // Types |
| 105 | //------------------------------------------------------------------------------ |
| 106 | |
| 107 | /// Driver structure for an CCID device |
| 108 | typedef struct { |
| 109 | |
| 110 | /// Standard USB device driver instance |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 111 | USBDDriver usbdDriver; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 112 | /// CCID message |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 113 | S_ccid_bulk_in_header sCcidMessage; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 114 | /// CCID command |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 115 | S_ccid_bulk_out_header sCcidCommand; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 116 | /// Interrupt message answer |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 117 | unsigned char BufferINT[4]; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 118 | /// Buffer data of message |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 119 | unsigned char ProtocolDataStructure[10]; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 120 | /// Protocol used |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 121 | unsigned char bProtocol; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 122 | /// SlotStatus |
| 123 | /// Bit 0 = Slot 0 current state |
| 124 | /// Bit 1 = Slot 0 changed status |
| 125 | /// Bit 2 = Slot 1 current state |
| 126 | /// Bit 3 = Slot 1 changed status |
| 127 | /// Bit 4 = Slot 2 current state |
| 128 | /// Bit 5 = Slot 2 changed status |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 129 | unsigned char SlotStatus; |
| 130 | |
| 131 | } CCIDDriver; |
| 132 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 133 | //------------------------------------------------------------------------------ |
| 134 | // Local variables |
| 135 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 136 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 137 | /// Static instance of the CCID device driver. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 138 | static CCIDDriver ccidDriver; |
| 139 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 140 | /// Standard USB device descriptor. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 141 | static const USBDeviceDescriptor deviceDescriptor = { |
| 142 | |
| 143 | sizeof(USBDeviceDescriptor), |
| 144 | USBGenericDescriptor_DEVICE, |
| 145 | USBDeviceDescriptor_USB2_00, |
| 146 | 0, |
| 147 | 0, |
| 148 | 0, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 149 | BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 150 | CCIDDriverDescriptors_VENDORID, |
| 151 | CCIDDriverDescriptors_PRODUCTID, |
| 152 | CCIDDriverDescriptors_RELEASE, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 153 | 1, // Index of manufacturer description |
| 154 | 2, // Index of product description |
| 155 | 3, // Index of serial number description |
| 156 | 1 // One possible configuration |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 160 | /// List of configuration descriptors. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 161 | static const CCIDDriverConfigurationDescriptors configurationDescriptorsFS = { |
| 162 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 163 | // Standard USB configuration descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 164 | { |
| 165 | sizeof(USBConfigurationDescriptor), |
| 166 | USBGenericDescriptor_CONFIGURATION, |
| 167 | sizeof(CCIDDriverConfigurationDescriptors), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 168 | 1+DFU_NUM_IF, // One interface in this configuration |
| 169 | 1, // This is configuration #1 |
| 170 | 0, // No associated string descriptor |
| 171 | BOARD_USB_BMATTRIBUTES, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 172 | USBConfigurationDescriptor_POWER(100) |
| 173 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 174 | // CCID interface descriptor |
| 175 | // Table 4.3-1 Interface Descriptor |
| 176 | // Interface descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 177 | { |
| 178 | sizeof(USBInterfaceDescriptor), |
| 179 | USBGenericDescriptor_INTERFACE, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 180 | 0, // Interface 0 |
| 181 | 0, // No alternate settings |
| 182 | 3, // uses bulk-IN, bulk-OUT and interrupt–IN |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 183 | SMART_CARD_DEVICE_CLASS, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 184 | 0, // Subclass code |
| 185 | 0, // bulk transfers optional interrupt-IN |
| 186 | 0 // No associated string descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 187 | }, |
| 188 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 189 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 190 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 191 | CCID1_10, // bcdCCID: CCID version |
| 192 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 193 | VOLTS_5_0, // bVoltageSupport |
| 194 | (1 << PROTOCOL_TO), // dwProtocols |
| 195 | 3580, // dwDefaultClock |
| 196 | 3580, // dwMaxClock |
| 197 | 0, // bNumClockSupported |
| 198 | 9600, // dwDataRate : 9600 bauds |
| 199 | 9600, // dwMaxDataRate : 9600 bauds |
| 200 | 0, // bNumDataRatesSupported |
| 201 | 0xfe, // dwMaxIFSD |
| 202 | 0, // dwSynchProtocols |
| 203 | 0, // dwMechanical |
| 204 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 205 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 206 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 207 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 208 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 209 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 210 | 0, // wLcdLayout: no LCD |
| 211 | 0, // bPINSupport: No PIN |
| 212 | 1 // bMaxCCIDBusySlot |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 213 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 214 | // Bulk-OUT endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 215 | { |
| 216 | sizeof(USBEndpointDescriptor), |
| 217 | USBGenericDescriptor_ENDPOINT, |
| 218 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
| 219 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 220 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 221 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 222 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 223 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 224 | // Bulk-IN endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 225 | { |
| 226 | sizeof(USBEndpointDescriptor), |
| 227 | USBGenericDescriptor_ENDPOINT, |
| 228 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
| 229 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 230 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 231 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 232 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 233 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 234 | // Notification endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 235 | { |
| 236 | sizeof(USBEndpointDescriptor), |
| 237 | USBGenericDescriptor_ENDPOINT, |
| 238 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
| 239 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 240 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 241 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 242 | 0x10 |
| 243 | }, |
| 244 | DFU_IF_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 245 | }; |
| 246 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 247 | #ifdef BOARD_USB_UDPHS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 248 | static const CCIDDriverConfigurationDescriptors configurationDescriptorsHS = { |
| 249 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 250 | // Standard USB configuration descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 251 | { |
| 252 | sizeof(USBConfigurationDescriptor), |
| 253 | USBGenericDescriptor_CONFIGURATION, |
| 254 | sizeof(CCIDDriverConfigurationDescriptors), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 255 | 1+DFU_NUM_IF, // One interface in this configuration |
| 256 | 1, // This is configuration #1 |
| 257 | 0, // No associated string descriptor |
| 258 | BOARD_USB_BMATTRIBUTES, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 259 | USBConfigurationDescriptor_POWER(100) |
| 260 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 261 | // CCID interface descriptor |
| 262 | // Table 4.3-1 Interface Descriptor |
| 263 | // Interface descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 264 | { |
| 265 | sizeof(USBInterfaceDescriptor), |
| 266 | USBGenericDescriptor_INTERFACE, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 267 | 0, // Interface 0 |
| 268 | 0, // No alternate settings |
| 269 | 3, // uses bulk-IN, bulk-OUT and interrupt–IN |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 270 | SMART_CARD_DEVICE_CLASS, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 271 | 0, // Subclass code |
| 272 | 0, // bulk transfers optional interrupt-IN |
| 273 | 0 // No associated string descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 274 | }, |
| 275 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 276 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 277 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 278 | CCID1_10, // bcdCCID: CCID version |
| 279 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 280 | VOLTS_5_0, // bVoltageSupport |
| 281 | (1 << PROTOCOL_TO), // dwProtocols |
| 282 | 3580, // dwDefaultClock |
| 283 | 3580, // dwMaxClock |
| 284 | 0, // bNumClockSupported |
| 285 | 9600, // dwDataRate : 9600 bauds |
| 286 | 9600, // dwMaxDataRate : 9600 bauds |
| 287 | 0, // bNumDataRatesSupported |
| 288 | 0xfe, // dwMaxIFSD |
| 289 | 0, // dwSynchProtocols |
| 290 | 0, // dwMechanical |
| 291 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 292 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 293 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 294 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 295 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 296 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 297 | 0, // wLcdLayout: no LCD |
| 298 | 0, // bPINSupport: No PIN |
| 299 | 1 // bMaxCCIDBusySlot |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 300 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 301 | // Bulk-OUT endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 302 | { |
| 303 | sizeof(USBEndpointDescriptor), |
| 304 | USBGenericDescriptor_ENDPOINT, |
| 305 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
| 306 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 307 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 308 | USBEndpointDescriptor_MAXBULKSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 309 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 310 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 311 | // Bulk-IN endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 312 | { |
| 313 | sizeof(USBEndpointDescriptor), |
| 314 | USBGenericDescriptor_ENDPOINT, |
| 315 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
| 316 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 317 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 318 | USBEndpointDescriptor_MAXBULKSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 319 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 320 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 321 | // Notification endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 322 | { |
| 323 | sizeof(USBEndpointDescriptor), |
| 324 | USBGenericDescriptor_ENDPOINT, |
| 325 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
| 326 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 327 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 328 | USBEndpointDescriptor_MAXINTERRUPTSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 329 | 0x10 |
| 330 | }, |
| 331 | DFU_IF_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 332 | }; |
| 333 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 334 | /// Qualifier descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 335 | const USBDeviceQualifierDescriptor deviceQualifierDescriptor = { |
| 336 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 337 | sizeof(USBDeviceQualifierDescriptor), // Size of this descriptor in bytes |
| 338 | USBGenericDescriptor_DEVICEQUALIFIER, // Qualifier Descriptor Type |
| 339 | USBDeviceDescriptor_USB2_00, // USB specification 2.00 |
| 340 | 0x00, // Class is specified in interface |
| 341 | 0x00, // Subclass is specified in interface |
| 342 | 0x00, // Protocol is specified in interface |
| 343 | BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0), |
| 344 | 0x01, // One possible configuration |
| 345 | 0x00 // Reserved for future use, must be zero |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 346 | }; |
| 347 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 348 | /// OtherSpeed configuration descriptor in Full Speed mode |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 349 | static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationFS = { |
| 350 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 351 | // Standard USB configuration descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 352 | { |
| 353 | sizeof(USBConfigurationDescriptor), |
| 354 | USBGenericDescriptor_OTHERSPEEDCONFIGURATION, |
| 355 | sizeof(CCIDDriverConfigurationDescriptors), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 356 | 1+DFU_NUM_IF, // One interface in this configuration |
| 357 | 1, // This is configuration #1 |
| 358 | 0, // No associated string descriptor |
| 359 | BOARD_USB_BMATTRIBUTES, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 360 | USBConfigurationDescriptor_POWER(100) |
| 361 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 362 | // CCID interface descriptor |
| 363 | // Table 4.3-1 Interface Descriptor |
| 364 | // Interface descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 365 | { |
| 366 | sizeof(USBInterfaceDescriptor), |
| 367 | USBGenericDescriptor_INTERFACE, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 368 | 0, // Interface 0 |
| 369 | 0, // No alternate settings |
| 370 | 3, // uses bulk-IN, bulk-OUT and interrupt–IN |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 371 | SMART_CARD_DEVICE_CLASS, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 372 | 0, // Subclass code |
| 373 | 0, // bulk transfers optional interrupt-IN |
| 374 | 0 // No associated string descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 375 | }, |
| 376 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 377 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 378 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 379 | CCID1_10, // bcdCCID: CCID version |
| 380 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 381 | VOLTS_5_0, // bVoltageSupport |
| 382 | (1 << PROTOCOL_TO), // dwProtocols |
| 383 | 3580, // dwDefaultClock |
| 384 | 3580, // dwMaxClock |
| 385 | 0, // bNumClockSupported |
| 386 | 9600, // dwDataRate : 9600 bauds |
| 387 | 9600, // dwMaxDataRate : 9600 bauds |
| 388 | 0, // bNumDataRatesSupported |
| 389 | 0xfe, // dwMaxIFSD |
| 390 | 0, // dwSynchProtocols |
| 391 | 0, // dwMechanical |
| 392 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 393 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 394 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 395 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 396 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 397 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 398 | 0, // wLcdLayout: no LCD |
| 399 | 0, // bPINSupport: No PIN |
| 400 | 1 // bMaxCCIDBusySlot |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 401 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 402 | // Bulk-OUT endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 403 | { |
| 404 | sizeof(USBEndpointDescriptor), |
| 405 | USBGenericDescriptor_ENDPOINT, |
| 406 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
| 407 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 408 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 409 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 410 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 411 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 412 | // Bulk-IN endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 413 | { |
| 414 | sizeof(USBEndpointDescriptor), |
| 415 | USBGenericDescriptor_ENDPOINT, |
| 416 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
| 417 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 418 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 419 | USBEndpointDescriptor_MAXBULKSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 420 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 421 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 422 | // Notification endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 423 | { |
| 424 | sizeof(USBEndpointDescriptor), |
| 425 | USBGenericDescriptor_ENDPOINT, |
| 426 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
| 427 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 428 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 429 | USBEndpointDescriptor_MAXINTERRUPTSIZE_FS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 430 | 0x10 |
| 431 | }, |
| 432 | DFU_IF_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 433 | }; |
| 434 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 435 | /// OtherSpeed configuration descriptor in High Speed mode |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 436 | static const CCIDDriverConfigurationDescriptors sOtherSpeedConfigurationHS = { |
| 437 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 438 | // Standard USB configuration descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 439 | { |
| 440 | sizeof(USBConfigurationDescriptor), |
| 441 | USBGenericDescriptor_OTHERSPEEDCONFIGURATION, |
| 442 | sizeof(CCIDDriverConfigurationDescriptors), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 443 | 1+DFU_NUM_IF, // One interface in this configuration |
| 444 | 1, // This is configuration #1 |
| 445 | 0, // No associated string descriptor |
| 446 | BOARD_USB_BMATTRIBUTES, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 447 | USBConfigurationDescriptor_POWER(100) |
| 448 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 449 | // CCID interface descriptor |
| 450 | // Table 4.3-1 Interface Descriptor |
| 451 | // Interface descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 452 | { |
| 453 | sizeof(USBInterfaceDescriptor), |
| 454 | USBGenericDescriptor_INTERFACE, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 455 | 0, // Interface 0 |
| 456 | 0, // No alternate settings |
| 457 | 3, // uses bulk-IN, bulk-OUT and interrupt–IN |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 458 | SMART_CARD_DEVICE_CLASS, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 459 | 0, // Subclass code |
| 460 | 0, // bulk transfers optional interrupt-IN |
| 461 | 0 // No associated string descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 462 | }, |
| 463 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 464 | sizeof(CCIDDescriptor), // bLength: Size of this descriptor in bytes |
| 465 | CCID_DECRIPTOR_TYPE, // bDescriptorType:Functional descriptor type |
| 466 | CCID1_10, // bcdCCID: CCID version |
| 467 | 0, // bMaxSlotIndex: Value 0 indicates that one slot is supported |
| 468 | VOLTS_5_0, // bVoltageSupport |
| 469 | (1 << PROTOCOL_TO), // dwProtocols |
| 470 | 3580, // dwDefaultClock |
| 471 | 3580, // dwMaxClock |
| 472 | 0, // bNumClockSupported |
| 473 | 9600, // dwDataRate : 9600 bauds |
| 474 | 9600, // dwMaxDataRate : 9600 bauds |
| 475 | 0, // bNumDataRatesSupported |
| 476 | 0xfe, // dwMaxIFSD |
| 477 | 0, // dwSynchProtocols |
| 478 | 0, // dwMechanical |
| 479 | //0x00010042, // dwFeatures: Short APDU level exchanges |
| 480 | CCID_FEATURES_AUTO_CLOCK | CCID_FEATURES_AUTO_BAUD | |
| 481 | CCID_FEATURES_AUTO_PCONF | CCID_FEATURES_AUTO_PNEGO | CCID_FEATURES_EXC_TPDU, |
| 482 | 0x0000010F, // dwMaxCCIDMessageLength: For extended APDU level the value shall be between 261 + 10 |
| 483 | 0xFF, // bClassGetResponse: Echoes the class of the APDU |
| 484 | 0xFF, // bClassEnvelope: Echoes the class of the APDU |
| 485 | 0, // wLcdLayout: no LCD |
| 486 | 0, // bPINSupport: No PIN |
| 487 | 1 // bMaxCCIDBusySlot |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 488 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 489 | // Bulk-OUT endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 490 | { |
| 491 | sizeof(USBEndpointDescriptor), |
| 492 | USBGenericDescriptor_ENDPOINT, |
| 493 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_OUT, CCID_EPT_DATA_OUT ), |
| 494 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 495 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_OUT), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 496 | USBEndpointDescriptor_MAXBULKSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 497 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 498 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 499 | // Bulk-IN endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 500 | { |
| 501 | sizeof(USBEndpointDescriptor), |
| 502 | USBGenericDescriptor_ENDPOINT, |
| 503 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_DATA_IN ), |
| 504 | USBEndpointDescriptor_BULK, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 505 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_DATA_IN), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 506 | USBEndpointDescriptor_MAXBULKSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 507 | 0x00 // Does not apply to Bulk endpoints |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 508 | }, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 509 | // Notification endpoint descriptor |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 510 | { |
| 511 | sizeof(USBEndpointDescriptor), |
| 512 | USBGenericDescriptor_ENDPOINT, |
| 513 | USBEndpointDescriptor_ADDRESS( USBEndpointDescriptor_IN, CCID_EPT_NOTIFICATION ), |
| 514 | USBEndpointDescriptor_INTERRUPT, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 515 | MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(CCID_EPT_NOTIFICATION), |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 516 | USBEndpointDescriptor_MAXINTERRUPTSIZE_HS), |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 517 | 0x10 |
| 518 | }, |
| 519 | DFU_IF_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 520 | }; |
| 521 | #endif |
| 522 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 523 | /// Language ID string descriptor. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 524 | static const unsigned char languageIdDescriptor[] = { |
| 525 | |
| 526 | USBStringDescriptor_LENGTH(1), |
| 527 | USBGenericDescriptor_STRING, |
| 528 | USBStringDescriptor_ENGLISH_US |
| 529 | }; |
| 530 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 531 | /// Manufacturer name. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 532 | static const unsigned char manufacturerDescriptor[] = { |
| 533 | |
| 534 | USBStringDescriptor_LENGTH(5), |
| 535 | USBGenericDescriptor_STRING, |
| 536 | USBStringDescriptor_UNICODE('A'), |
| 537 | USBStringDescriptor_UNICODE('T'), |
| 538 | USBStringDescriptor_UNICODE('M'), |
| 539 | USBStringDescriptor_UNICODE('E'), |
| 540 | USBStringDescriptor_UNICODE('L') |
| 541 | }; |
| 542 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 543 | /// Product name. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 544 | static const unsigned char productDescriptor[] = { |
| 545 | |
| 546 | USBStringDescriptor_LENGTH(23), |
| 547 | USBGenericDescriptor_STRING, |
| 548 | USBStringDescriptor_UNICODE('A'), |
| 549 | USBStringDescriptor_UNICODE('T'), |
| 550 | USBStringDescriptor_UNICODE('M'), |
| 551 | USBStringDescriptor_UNICODE('E'), |
| 552 | USBStringDescriptor_UNICODE('L'), |
| 553 | USBStringDescriptor_UNICODE(' '), |
| 554 | USBStringDescriptor_UNICODE('A'), |
| 555 | USBStringDescriptor_UNICODE('T'), |
| 556 | USBStringDescriptor_UNICODE('9'), |
| 557 | USBStringDescriptor_UNICODE('1'), |
| 558 | USBStringDescriptor_UNICODE(' '), |
| 559 | USBStringDescriptor_UNICODE('C'), |
| 560 | USBStringDescriptor_UNICODE('C'), |
| 561 | USBStringDescriptor_UNICODE('I'), |
| 562 | USBStringDescriptor_UNICODE('D'), |
| 563 | USBStringDescriptor_UNICODE(' '), |
| 564 | USBStringDescriptor_UNICODE('D'), |
| 565 | USBStringDescriptor_UNICODE('R'), |
| 566 | USBStringDescriptor_UNICODE('I'), |
| 567 | USBStringDescriptor_UNICODE('V'), |
| 568 | USBStringDescriptor_UNICODE('E'), |
| 569 | USBStringDescriptor_UNICODE('R'), |
| 570 | USBStringDescriptor_UNICODE(' ') |
| 571 | }; |
| 572 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 573 | /// Product serial number. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 574 | static const unsigned char serialNumberDescriptor[] = { |
| 575 | |
| 576 | USBStringDescriptor_LENGTH(12), |
| 577 | USBGenericDescriptor_STRING, |
| 578 | USBStringDescriptor_UNICODE('0'), |
| 579 | USBStringDescriptor_UNICODE('1'), |
| 580 | USBStringDescriptor_UNICODE('2'), |
| 581 | USBStringDescriptor_UNICODE('3'), |
| 582 | USBStringDescriptor_UNICODE('4'), |
| 583 | USBStringDescriptor_UNICODE('5'), |
| 584 | USBStringDescriptor_UNICODE('6'), |
| 585 | USBStringDescriptor_UNICODE('7'), |
| 586 | USBStringDescriptor_UNICODE('8'), |
| 587 | USBStringDescriptor_UNICODE('9'), |
| 588 | USBStringDescriptor_UNICODE('A'), |
| 589 | USBStringDescriptor_UNICODE('F') |
| 590 | }; |
| 591 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 592 | /// Array of pointers to string descriptors. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 593 | static const unsigned char *stringDescriptors[] = { |
| 594 | |
| 595 | languageIdDescriptor, |
| 596 | manufacturerDescriptor, |
| 597 | productDescriptor, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 598 | serialNumberDescriptor, |
| 599 | DFU_STRING_DESCRIPTORS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 600 | }; |
| 601 | |
| 602 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 603 | /// List of standard descriptors for the serial driver. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 604 | const USBDDriverDescriptors ccidDriverDescriptors = { |
| 605 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 606 | &deviceDescriptor, // FS |
| 607 | (USBConfigurationDescriptor *) &configurationDescriptorsFS , |
| 608 | #ifdef BOARD_USB_UDPHS |
| 609 | (USBDeviceQualifierDescriptor *) &deviceQualifierDescriptor, // FS |
| 610 | { (USBConfigurationDescriptor *) &sOtherSpeedConfigurationFS }, |
| 611 | &deviceDescriptor, // HS |
| 612 | { (USBConfigurationDescriptor *) &configurationDescriptorsHS }, |
| 613 | (USBDeviceQualifierDescriptor *) &deviceQualifierDescriptor, // HS |
| 614 | { (USBConfigurationDescriptor *) &sOtherSpeedConfigurationHS }, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 615 | #else |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 616 | 0, // No qualifier descriptor FS |
| 617 | 0, // No other-speed configuration FS |
| 618 | 0, // No device descriptor HS |
| 619 | 0, // No configuration HS |
| 620 | 0, // No qualifier descriptor HS |
| 621 | 0, // No other-speed configuration HS |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 622 | #endif |
| 623 | stringDescriptors, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 624 | 4+DFU_NUM_STRINGS // Four string descriptors in array |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 625 | }; |
| 626 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 627 | //------------------------------------------------------------------------------ |
| 628 | // Internal functions |
| 629 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 630 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 631 | //------------------------------------------------------------------------------ |
| 632 | /// Response Pipe, Bulk-IN Messages |
| 633 | /// Return the Slot Status to the host |
| 634 | /// Answer to: |
| 635 | /// PC_to_RDR_IccPowerOff |
| 636 | /// PC_to_RDR_GetSlotStatus |
| 637 | /// PC_to_RDR_IccClock |
| 638 | /// PC_to_RDR_T0APDU |
| 639 | /// PC_to_RDR_Mechanical |
| 640 | /// PC_to_RDR_Abort and Class specific ABORT request |
| 641 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 642 | static void RDRtoPCSlotStatus( void ) |
| 643 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 644 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 645 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 646 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 647 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_SLOTSTATUS; |
| 648 | ccidDriver.sCcidMessage.wLength = 0; |
| 649 | ccidDriver.sCcidMessage.bStatus = ccidDriver.SlotStatus; |
| 650 | ccidDriver.sCcidMessage.bError = 0; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 651 | // 00h Clock running |
| 652 | // 01h Clock stopped in state L |
| 653 | // 02h Clock stopped in state H |
| 654 | // 03h Clock stopped in an unknown state |
| 655 | // All other values are Reserved for Future Use. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 656 | ccidDriver.sCcidMessage.bSpecific = 0; |
| 657 | } |
| 658 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 659 | //------------------------------------------------------------------------------ |
| 660 | /// Response Pipe, Bulk-IN Messages |
| 661 | /// Answer to PC_to_RDR_IccPowerOn |
| 662 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 663 | static void RDRtoPCDatablock_ATR( void ) |
| 664 | { |
| 665 | unsigned char i; |
| 666 | unsigned char Atr[ATR_SIZE_MAX]; |
| 667 | unsigned char length; |
Christina Quast | 8d0f4a6 | 2015-01-15 14:53:38 +0100 | [diff] [blame] | 668 | uint32_t status; |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 669 | |
Christina Quast | 8d0f4a6 | 2015-01-15 14:53:38 +0100 | [diff] [blame] | 670 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 671 | |
Christina Quast | 8d0f4a6 | 2015-01-15 14:53:38 +0100 | [diff] [blame] | 672 | status = ISO7816_Datablock_ATR( Atr, &length ); |
| 673 | if (status == 0) { |
| 674 | TRACE_DEBUG("Timeout occured while reading ATR"); |
| 675 | // FIXME: react properly to timeout.. |
| 676 | // return; |
| 677 | } |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 678 | |
| 679 | if( length > 5 ) { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 680 | ccidDriver.ProtocolDataStructure[1] = Atr[5]&0x0F; // TD(1) |
| 681 | ccidDriver.bProtocol = Atr[5]&0x0F; // TD(1) |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 684 | // S_ccid_protocol_t0 |
| 685 | // bmFindexDindex |
| 686 | ccidDriver.ProtocolDataStructure[0] = Atr[2]; // TA(1) |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 687 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 688 | // bmTCCKST0 |
| 689 | // For T=0 ,B0 – 0b, B7-2 – 000000b |
| 690 | // B1 – Convention used (b1=0 for direct, b1=1 for inverse) |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 691 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 692 | // bGuardTimeT0 |
| 693 | // Extra Guardtime between two characters. Add 0 to 254 etu to the normal |
| 694 | // guardtime of 12etu. FFh is the same as 00h. |
| 695 | ccidDriver.ProtocolDataStructure[2] = Atr[4]; // TC(1) |
| 696 | // AT91C_BASE_US0->US_TTGR = 0; // TC1 |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 697 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 698 | // bWaitingIntegerT0 |
| 699 | // WI for T=0 used to define WWT |
| 700 | ccidDriver.ProtocolDataStructure[3] = Atr[7]; // TC(2) |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 701 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 702 | // bClockStop |
| 703 | // ICC Clock Stop Support |
| 704 | // 00 = Stopping the Clock is not allowed |
| 705 | // 01 = Stop with Clock signal Low |
| 706 | // 02 = Stop with Clock signal High |
| 707 | // 03 = Stop with Clock either High or Low |
| 708 | ccidDriver.ProtocolDataStructure[4] = 0x00; // 0 to 3 |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 709 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 710 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 711 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_DATABLOCK; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 712 | ccidDriver.sCcidMessage.wLength = length; // Size of ATR |
| 713 | ccidDriver.sCcidMessage.bSizeToSend += length; // Size of ATR |
| 714 | // bChainParameter: 00 the response APDU begins and ends in this command |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 715 | ccidDriver.sCcidMessage.bSpecific = 0; |
| 716 | |
| 717 | for( i=0; i<length; i++ ) { |
| 718 | |
| 719 | ccidDriver.sCcidMessage.abData[i] = Atr[i]; |
| 720 | } |
| 721 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 722 | // Set the slot to an active status |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 723 | ccidDriver.sCcidMessage.bStatus = 0; |
| 724 | ccidDriver.sCcidMessage.bError = 0; |
| 725 | } |
| 726 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 727 | //------------------------------------------------------------------------------ |
| 728 | /// Response Pipe, Bulk-IN Messages |
| 729 | /// In other cases, the response message has the following format: |
| 730 | /// The response data will contain the optional data returned by the ICC, |
| 731 | /// followed by the 2 byte-size status words SW1-SW2. |
| 732 | /// |
| 733 | /// Answer to: |
| 734 | /// PC_to_RDR_XfrBlock |
| 735 | /// PC_to_RDR_Secure |
| 736 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 737 | static void RDRtoPCDatablock( void ) |
| 738 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 739 | //TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 740 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 741 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 742 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_DATABLOCK; |
| 743 | ccidDriver.sCcidMessage.bSizeToSend += ccidDriver.sCcidMessage.wLength; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 744 | // bChainParameter: 00 the response APDU begins and ends in this command |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 745 | ccidDriver.sCcidMessage.bSpecific = 0; |
| 746 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 747 | // Set the slot to an active status |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 748 | ccidDriver.sCcidMessage.bStatus = 0; |
| 749 | ccidDriver.sCcidMessage.bError = 0; |
| 750 | } |
| 751 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 752 | //------------------------------------------------------------------------------ |
| 753 | /// Response Pipe, Bulk-IN Messages |
| 754 | /// Answer to: |
| 755 | /// PC_to_RDR_GetParameters |
| 756 | /// PC_to_RDR_ResetParameters |
| 757 | /// PC_to_RDR_SetParameters |
| 758 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 759 | static void RDRtoPCParameters( void ) |
| 760 | { |
| 761 | unsigned int i; |
| 762 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 763 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 764 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 765 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 766 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_PARAMETERS; |
| 767 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 768 | //ccidDriver.sCcidMessage.bStatus = 0; |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 769 | ccidDriver.sCcidMessage.bError = 0; |
| 770 | |
| 771 | if( ccidDriver.ProtocolDataStructure[1] == PROTOCOL_TO ) { |
| 772 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 773 | // T=0 |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 774 | ccidDriver.sCcidMessage.wLength = sizeof(S_ccid_protocol_t0); |
| 775 | ccidDriver.sCcidMessage.bSpecific = PROTOCOL_TO; |
| 776 | } |
| 777 | else { |
| 778 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 779 | // T=1 |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 780 | ccidDriver.sCcidMessage.wLength = sizeof(S_ccid_protocol_t1); |
| 781 | ccidDriver.sCcidMessage.bSpecific = PROTOCOL_T1; |
| 782 | } |
| 783 | |
| 784 | ccidDriver.sCcidMessage.bSizeToSend += ccidDriver.sCcidMessage.wLength; |
| 785 | |
| 786 | for( i=0; i<ccidDriver.sCcidMessage.wLength; i++ ) { |
| 787 | ccidDriver.sCcidMessage.abData[i] = ccidDriver.ProtocolDataStructure[i]; |
| 788 | } |
| 789 | |
| 790 | } |
| 791 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 792 | //------------------------------------------------------------------------------ |
| 793 | /// Response Pipe, Bulk-IN Messages |
| 794 | /// Answer to: |
| 795 | /// PC_to_RDR_Escape |
| 796 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 797 | static void RDRtoPCEscape( unsigned char length, unsigned char *data_send_from_CCID ) |
| 798 | { |
| 799 | unsigned int i; |
| 800 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 801 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 802 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 803 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 804 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_ESCAPE; |
| 805 | |
| 806 | ccidDriver.sCcidMessage.wLength = length; |
| 807 | |
| 808 | ccidDriver.sCcidMessage.bStatus = 0; |
| 809 | ccidDriver.sCcidMessage.bError = 0; |
| 810 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 811 | ccidDriver.sCcidMessage.bSpecific = 0; // bRFU |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 812 | |
| 813 | for( i=0; i<length; i++ ) { |
| 814 | ccidDriver.sCcidMessage.abData[i] = data_send_from_CCID[i]; |
| 815 | } |
| 816 | } |
| 817 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 818 | //------------------------------------------------------------------------------ |
| 819 | /// Response Pipe, Bulk-IN Messages |
| 820 | /// Answer to: |
| 821 | /// PC_to_RDR_SetDataRateAndClockFrequency |
| 822 | //------------------------------------------------------------------------------ |
| 823 | static void RDRtoPCDataRateAndClockFrequency( unsigned int dwClockFrequency, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 824 | unsigned int dwDataRate ) |
| 825 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 826 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 827 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 828 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 829 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_DATARATEANDCLOCKFREQUENCY; |
| 830 | |
| 831 | ccidDriver.sCcidMessage.wLength = 8; |
| 832 | |
| 833 | ccidDriver.sCcidMessage.bStatus = 0; |
| 834 | ccidDriver.sCcidMessage.bError = 0; |
| 835 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 836 | ccidDriver.sCcidMessage.bSpecific = 0; // bRFU |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 837 | |
| 838 | ccidDriver.sCcidMessage.abData[0] = dwClockFrequency; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 839 | |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 840 | ccidDriver.sCcidMessage.abData[4] = dwDataRate; |
| 841 | } |
| 842 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 843 | //------------------------------------------------------------------------------ |
| 844 | /// Command Pipe, Bulk-OUT Messages |
| 845 | /// Power On Command - Cold Reset & Warm Reset |
| 846 | /// Return the ATR to the host |
| 847 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 848 | static void PCtoRDRIccPowerOn( void ) |
| 849 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 850 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 851 | |
| 852 | if( CCID_FEATURES_AUTO_VOLT == (configurationDescriptorsFS.ccid.dwFeatures & CCID_FEATURES_AUTO_VOLT) ) { |
| 853 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 854 | // bPowerSelect = ccidDriver.sCcidCommand.bSpecific_0; |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 855 | ccidDriver.sCcidCommand.bSpecific_0 = VOLTS_AUTO; |
| 856 | } |
| 857 | |
Christina Quast | f6bf349 | 2015-01-15 14:42:04 +0100 | [diff] [blame] | 858 | ISO7816_warm_reset(); |
| 859 | // ISO7816_cold_reset(); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 860 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 861 | // for emulation only //JCB |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 862 | if ( ccidDriver.sCcidCommand.bSpecific_0 != VOLTS_5_0 ) { |
| 863 | |
| 864 | TRACE_ERROR("POWER_NOT_SUPPORTED\n\r"); |
| 865 | } |
| 866 | |
| 867 | else { |
| 868 | |
| 869 | RDRtoPCDatablock_ATR(); |
| 870 | |
| 871 | } |
| 872 | } |
| 873 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 874 | //------------------------------------------------------------------------------ |
| 875 | /// Command Pipe, Bulk-OUT Messages |
| 876 | /// Power Off Command - Set the ICC in an inactive state |
| 877 | /// Return the slot status to the host |
| 878 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 879 | static void PCtoRDRIccPowerOff( void ) |
| 880 | { |
| 881 | unsigned char bStatus; |
| 882 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 883 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 884 | |
| 885 | ISO7816_IccPowerOff(); |
| 886 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 887 | //JCB stub |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 888 | bStatus = ICC_BS_PRESENT_NOTACTIVATED; |
| 889 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 890 | // Set the slot to an inactive status |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 891 | ccidDriver.sCcidMessage.bStatus = 0; |
| 892 | ccidDriver.sCcidMessage.bError = 0; |
| 893 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 894 | // if error, see Table 6.1-2 errors |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 895 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 896 | // Return the slot status to the host |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 897 | RDRtoPCSlotStatus(); |
| 898 | } |
| 899 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 900 | //------------------------------------------------------------------------------ |
| 901 | /// Command Pipe, Bulk-OUT Messages |
| 902 | /// Get slot status |
| 903 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 904 | static void PCtoRDRGetSlotStatus( void ) |
| 905 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 906 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 907 | |
| 908 | ccidDriver.sCcidMessage.bStatus = 0; |
| 909 | ccidDriver.sCcidMessage.bError = 0; |
| 910 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 911 | // Return the slot status to the host |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 912 | RDRtoPCSlotStatus(); |
| 913 | } |
| 914 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 915 | //------------------------------------------------------------------------------ |
| 916 | /// Command Pipe, Bulk-OUT Messages |
| 917 | /// If the command header is valid, an APDU command is received and can be read |
| 918 | /// by the application |
| 919 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 920 | static void PCtoRDRXfrBlock( void ) |
| 921 | { |
| 922 | unsigned char indexMessage = 0; |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 923 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 924 | //TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 925 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 926 | // Check the block length |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 927 | if ( ccidDriver.sCcidCommand.wLength > (configurationDescriptorsFS.ccid.dwMaxCCIDMessageLength-10) ) { |
| 928 | |
| 929 | ccidDriver.sCcidMessage.bStatus = 1; |
| 930 | ccidDriver.sCcidMessage.bError = 0; |
| 931 | } |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 932 | // check bBWI |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 933 | else if ( 0 != ccidDriver.sCcidCommand.bSpecific_0 ) { |
| 934 | |
| 935 | TRACE_ERROR("Bad bBWI\n\r"); |
| 936 | } |
| 937 | else { |
| 938 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 939 | // APDU or TPDU |
| 940 | switch(configurationDescriptorsFS.ccid.dwFeatures |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 941 | & (CCID_FEATURES_EXC_TPDU|CCID_FEATURES_EXC_SAPDU|CCID_FEATURES_EXC_APDU)) { |
| 942 | |
| 943 | case CCID_FEATURES_EXC_TPDU: |
| 944 | if (ccidDriver.ProtocolDataStructure[1] == PROTOCOL_TO) { |
| 945 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 946 | // Send commande APDU |
| 947 | indexMessage = ISO7816_XfrBlockTPDU_T0( ccidDriver.sCcidCommand.APDU , |
| 948 | ccidDriver.sCcidMessage.abData, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 949 | ccidDriver.sCcidCommand.wLength ); |
| 950 | } |
| 951 | else { |
| 952 | if (ccidDriver.ProtocolDataStructure[1] == PROTOCOL_T1) { |
| 953 | TRACE_INFO("Not supported T=1\n\r"); |
| 954 | } |
| 955 | else { |
| 956 | TRACE_INFO("Not supported\n\r"); |
| 957 | } |
| 958 | } |
| 959 | break; |
| 960 | |
| 961 | case CCID_FEATURES_EXC_APDU: |
| 962 | TRACE_INFO("Not supported\n\r"); |
| 963 | break; |
| 964 | |
| 965 | default: |
| 966 | break; |
| 967 | } |
| 968 | |
| 969 | } |
| 970 | |
| 971 | ccidDriver.sCcidMessage.wLength = indexMessage; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 972 | TRACE_DEBUG("USB: 0x%X, 0x%X, 0x%X, 0x%X, 0x%X\n\r", ccidDriver.sCcidMessage.abData[0], |
| 973 | ccidDriver.sCcidMessage.abData[1], |
| 974 | ccidDriver.sCcidMessage.abData[2], |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 975 | ccidDriver.sCcidMessage.abData[3], |
| 976 | ccidDriver.sCcidMessage.abData[4] ); |
| 977 | RDRtoPCDatablock(); |
| 978 | |
| 979 | } |
| 980 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 981 | //------------------------------------------------------------------------------ |
| 982 | /// Command Pipe, Bulk-OUT Messages |
| 983 | /// return parameters by the command: RDR_to_PC_Parameters |
| 984 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 985 | static void PCtoRDRGetParameters( void ) |
| 986 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 987 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 988 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 989 | // We support only one slot |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 990 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 991 | // bmIccStatus |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 992 | if( ISO7816_StatusReset() ) { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 993 | // 0: An ICC is present and active (power is on and stable, RST is inactive |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 994 | ccidDriver.sCcidMessage.bStatus = 0; |
| 995 | } |
| 996 | else { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 997 | // 1: An ICC is present and inactive (not activated or shut down by hardware error) |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 998 | ccidDriver.sCcidMessage.bStatus = 1; |
| 999 | } |
| 1000 | |
| 1001 | RDRtoPCParameters(); |
| 1002 | } |
| 1003 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1004 | //------------------------------------------------------------------------------ |
| 1005 | /// Command Pipe, Bulk-OUT Messages |
| 1006 | /// This command resets the slot parameters to their default values |
| 1007 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1008 | static void PCtoRDRResetParameters( void ) |
| 1009 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1010 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1011 | |
| 1012 | ccidDriver.SlotStatus = ICC_NOT_PRESENT; |
| 1013 | ccidDriver.sCcidMessage.bStatus = ccidDriver.SlotStatus; |
| 1014 | |
| 1015 | RDRtoPCParameters(); |
| 1016 | } |
| 1017 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1018 | //------------------------------------------------------------------------------ |
| 1019 | /// Command Pipe, Bulk-OUT Messages |
| 1020 | /// This command is used to change the parameters for a given slot. |
| 1021 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1022 | static void PCtoRDRSetParameters( void ) |
| 1023 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1024 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1025 | |
| 1026 | ccidDriver.SlotStatus = ccidDriver.sCcidCommand.bSlot; |
| 1027 | ccidDriver.sCcidMessage.bStatus = ccidDriver.SlotStatus; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1028 | // Not all feature supported |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1029 | |
| 1030 | RDRtoPCParameters(); |
| 1031 | } |
| 1032 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1033 | //------------------------------------------------------------------------------ |
| 1034 | /// Command Pipe, Bulk-OUT Messages |
| 1035 | /// This command allows the CCID manufacturer to define and access extended |
| 1036 | /// features. |
| 1037 | /// Information sent via this command is processed by the CCID control logic. |
| 1038 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1039 | static void PCtoRDREscape( void ) |
| 1040 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1041 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1042 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1043 | // If needed by the user |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1044 | ISO7816_Escape(); |
| 1045 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1046 | // stub, return all value send |
| 1047 | RDRtoPCEscape( ccidDriver.sCcidCommand.wLength, ccidDriver.sCcidCommand.APDU); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1050 | //------------------------------------------------------------------------------ |
| 1051 | /// Command Pipe, Bulk-OUT Messages |
| 1052 | /// This command stops or restarts the clock. |
| 1053 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1054 | static void PCtoRDRICCClock( void ) |
| 1055 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1056 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1057 | |
| 1058 | if( 0 == ccidDriver.sCcidCommand.bSpecific_0 ) { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1059 | // restarts the clock |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1060 | ISO7816_RestartClock(); |
| 1061 | } |
| 1062 | else { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1063 | // stop clock in the state shown in the bClockStop field |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1064 | ISO7816_StopClock(); |
| 1065 | } |
| 1066 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1067 | RDRtoPCSlotStatus( ); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1070 | //------------------------------------------------------------------------------ |
| 1071 | /// Command Pipe, Bulk-OUT Messages |
| 1072 | /// This command changes the parameters used to perform the transportation of |
| 1073 | /// APDU messages by the T=0 protocol. |
| 1074 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1075 | static void PCtoRDRtoAPDU( void ) |
| 1076 | { |
| 1077 | unsigned char bmChanges; |
| 1078 | unsigned char bClassGetResponse; |
| 1079 | unsigned char bClassEnvelope; |
| 1080 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1081 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1082 | |
| 1083 | if( configurationDescriptorsFS.ccid.dwFeatures == (CCID_FEATURES_EXC_SAPDU|CCID_FEATURES_EXC_APDU) ) { |
| 1084 | |
| 1085 | bmChanges = ccidDriver.sCcidCommand.bSpecific_0; |
| 1086 | bClassGetResponse = ccidDriver.sCcidCommand.bSpecific_1; |
| 1087 | bClassEnvelope = ccidDriver.sCcidCommand.bSpecific_2; |
| 1088 | |
| 1089 | ISO7816_toAPDU(); |
| 1090 | } |
| 1091 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1092 | RDRtoPCSlotStatus(); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1095 | //------------------------------------------------------------------------------ |
| 1096 | /// Command Pipe, Bulk-OUT Messages |
| 1097 | /// This is a command message to allow entering the PIN for verification or |
| 1098 | /// modification. |
| 1099 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1100 | static void PCtoRDRSecure( void ) |
| 1101 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1102 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1103 | |
| 1104 | TRACE_DEBUG("For user\n\r"); |
| 1105 | } |
| 1106 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1107 | //------------------------------------------------------------------------------ |
| 1108 | /// Command Pipe, Bulk-OUT Messages |
| 1109 | /// This command is used to manage motorized type CCID functionality. |
| 1110 | /// The Lock Card function is used to hold the ICC. |
| 1111 | /// This prevents an ICC from being easily removed from the CCID. |
| 1112 | /// The Unlock Card function is used to remove the hold initiated by the Lock |
| 1113 | /// Card function |
| 1114 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1115 | static void PCtoRDRMechanical( void ) |
| 1116 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1117 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1118 | TRACE_DEBUG("Not implemented\n\r"); |
| 1119 | |
| 1120 | RDRtoPCSlotStatus(); |
| 1121 | } |
| 1122 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1123 | //------------------------------------------------------------------------------ |
| 1124 | /// Command Pipe, Bulk-OUT Messages |
| 1125 | /// This command is used with the Control pipe Abort request to tell the CCID |
| 1126 | /// to stop any current transfer at the specified slot and return to a state |
| 1127 | /// where the slot is ready to accept a new command pipe Bulk-OUT message. |
| 1128 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1129 | static void PCtoRDRAbort( void ) |
| 1130 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1131 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1132 | |
| 1133 | RDRtoPCSlotStatus(); |
| 1134 | } |
| 1135 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1136 | //------------------------------------------------------------------------------ |
| 1137 | /// Command Pipe, Bulk-OUT Messages |
| 1138 | /// This command is used to manually set the data rate and clock frequency of |
| 1139 | /// a specific slot. |
| 1140 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1141 | static void PCtoRDRSetDataRateAndClockFrequency( void ) |
| 1142 | { |
| 1143 | unsigned int dwClockFrequency; |
| 1144 | unsigned int dwDataRate; |
| 1145 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1146 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1147 | |
| 1148 | dwClockFrequency = ccidDriver.sCcidCommand.APDU[0] |
| 1149 | + (ccidDriver.sCcidCommand.APDU[1]<<8) |
| 1150 | + (ccidDriver.sCcidCommand.APDU[2]<<16) |
| 1151 | + (ccidDriver.sCcidCommand.APDU[3]<<24); |
| 1152 | |
| 1153 | dwDataRate = ccidDriver.sCcidCommand.APDU[4] |
| 1154 | + (ccidDriver.sCcidCommand.APDU[5]<<8) |
| 1155 | + (ccidDriver.sCcidCommand.APDU[6]<<16) |
| 1156 | + (ccidDriver.sCcidCommand.APDU[7]<<24); |
| 1157 | |
| 1158 | ISO7816_SetDataRateandClockFrequency( dwClockFrequency, dwDataRate ); |
| 1159 | |
| 1160 | RDRtoPCDataRateAndClockFrequency( dwClockFrequency, dwDataRate ); |
| 1161 | |
| 1162 | } |
| 1163 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1164 | //------------------------------------------------------------------------------ |
| 1165 | /// Report the CMD_NOT_SUPPORTED error to the host |
| 1166 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1167 | static void vCCIDCommandNotSupported( void ) |
| 1168 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1169 | // Command not supported |
| 1170 | // vCCIDReportError(CMD_NOT_SUPPORTED); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1171 | |
| 1172 | TRACE_DEBUG("CMD_NOT_SUPPORTED\n\r"); |
| 1173 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1174 | // Header fields settings |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1175 | ccidDriver.sCcidMessage.bMessageType = RDR_TO_PC_SLOTSTATUS; |
| 1176 | ccidDriver.sCcidMessage.wLength = 0; |
| 1177 | ccidDriver.sCcidMessage.bSpecific = 0; |
| 1178 | |
| 1179 | ccidDriver.sCcidMessage.bStatus |= ICC_CS_FAILED; |
| 1180 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1181 | // Send the response to the host |
| 1182 | //vCCIDSendResponse(); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1185 | //------------------------------------------------------------------------------ |
| 1186 | /// Sent CCID response on USB |
| 1187 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1188 | static void vCCIDSendResponse( void ) |
| 1189 | { |
| 1190 | unsigned char bStatus; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1191 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1192 | |
| 1193 | do { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1194 | bStatus = USBD_Write( CCID_EPT_DATA_IN, (void*)&ccidDriver.sCcidMessage, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1195 | ccidDriver.sCcidMessage.bSizeToSend, 0, 0 ); |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1196 | |
| 1197 | TRACE_DEBUG("bStatus: 0x%x\n\r", bStatus); |
| 1198 | |
| 1199 | } while (bStatus != USBD_STATUS_SUCCESS); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1203 | //------------------------------------------------------------------------------ |
| 1204 | /// Description: CCID Command dispatcher |
| 1205 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1206 | static void CCIDCommandDispatcher( void ) |
| 1207 | { |
| 1208 | unsigned char MessageToSend = 0; |
| 1209 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1210 | TRACE_DEBUG("Command: 0x%X 0x%x 0x%X 0x%X 0x%X 0x%X 0x%X\n\r\n\r", |
| 1211 | (unsigned int)ccidDriver.sCcidCommand.bMessageType, |
| 1212 | (unsigned int)ccidDriver.sCcidCommand.wLength, |
| 1213 | (unsigned int)ccidDriver.sCcidCommand.bSlot, |
| 1214 | (unsigned int)ccidDriver.sCcidCommand.bSeq, |
| 1215 | (unsigned int)ccidDriver.sCcidCommand.bSpecific_0, |
| 1216 | (unsigned int)ccidDriver.sCcidCommand.bSpecific_1, |
| 1217 | (unsigned int)ccidDriver.sCcidCommand.bSpecific_2); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1218 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1219 | // Check the slot number |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1220 | if ( ccidDriver.sCcidCommand.bSlot > 0 ) { |
| 1221 | |
| 1222 | TRACE_ERROR("BAD_SLOT_NUMBER\n\r"); |
| 1223 | } |
| 1224 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1225 | printf("typ=0x%X\n\r", ccidDriver.sCcidCommand.bMessageType); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1226 | TRACE_DEBUG("typ=0x%X\n\r", ccidDriver.sCcidCommand.bMessageType); |
| 1227 | |
| 1228 | ccidDriver.sCcidMessage.bStatus = 0; |
| 1229 | |
| 1230 | ccidDriver.sCcidMessage.bSeq = ccidDriver.sCcidCommand.bSeq; |
| 1231 | ccidDriver.sCcidMessage.bSlot = ccidDriver.sCcidCommand.bSlot; |
| 1232 | |
| 1233 | ccidDriver.sCcidMessage.bSizeToSend = sizeof(S_ccid_bulk_in_header)-(ABDATA_SIZE+1); |
| 1234 | |
| 1235 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1236 | // Command dispatcher |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1237 | switch ( ccidDriver.sCcidCommand.bMessageType ) { |
| 1238 | |
| 1239 | case PC_TO_RDR_ICCPOWERON: |
| 1240 | PCtoRDRIccPowerOn(); |
| 1241 | MessageToSend = 1; |
| 1242 | break; |
| 1243 | |
| 1244 | case PC_TO_RDR_ICCPOWEROFF: |
| 1245 | PCtoRDRIccPowerOff(); |
| 1246 | MessageToSend = 1; |
| 1247 | break; |
| 1248 | |
| 1249 | case PC_TO_RDR_GETSLOTSTATUS: |
| 1250 | PCtoRDRGetSlotStatus(); |
| 1251 | MessageToSend = 1; |
| 1252 | break; |
| 1253 | |
| 1254 | case PC_TO_RDR_XFRBLOCK: |
| 1255 | PCtoRDRXfrBlock(); |
| 1256 | MessageToSend = 1; |
| 1257 | break; |
| 1258 | |
| 1259 | case PC_TO_RDR_GETPARAMETERS: |
| 1260 | PCtoRDRGetParameters(); |
| 1261 | MessageToSend = 1; |
| 1262 | break; |
| 1263 | |
| 1264 | case PC_TO_RDR_RESETPARAMETERS: |
| 1265 | PCtoRDRResetParameters(); |
| 1266 | MessageToSend = 1; |
| 1267 | break; |
| 1268 | |
| 1269 | case PC_TO_RDR_SETPARAMETERS: |
| 1270 | PCtoRDRSetParameters(); |
| 1271 | MessageToSend = 1; |
| 1272 | break; |
| 1273 | |
| 1274 | case PC_TO_RDR_ESCAPE: |
| 1275 | PCtoRDREscape(); |
| 1276 | MessageToSend = 1; |
| 1277 | break; |
| 1278 | |
| 1279 | case PC_TO_RDR_ICCCLOCK: |
| 1280 | PCtoRDRICCClock(); |
| 1281 | MessageToSend = 1; |
| 1282 | break; |
| 1283 | |
| 1284 | case PC_TO_RDR_T0APDU: |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1285 | // Only CCIDs reporting a short or extended APDU level in the dwFeatures |
| 1286 | // field of the CCID class descriptor may take this command into account. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1287 | if( (CCID_FEATURES_EXC_SAPDU == (CCID_FEATURES_EXC_SAPDU&configurationDescriptorsFS.ccid.dwFeatures)) |
| 1288 | || (CCID_FEATURES_EXC_APDU == (CCID_FEATURES_EXC_APDU &configurationDescriptorsFS.ccid.dwFeatures)) ) { |
| 1289 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1290 | // command supported |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1291 | PCtoRDRtoAPDU(); |
| 1292 | } |
| 1293 | else { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1294 | // command not supported |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1295 | TRACE_DEBUG("PC_TO_RDR_T0APDU\n\r"); |
| 1296 | vCCIDCommandNotSupported(); |
| 1297 | } |
| 1298 | MessageToSend = 1; |
| 1299 | break; |
| 1300 | |
| 1301 | case PC_TO_RDR_SECURE: |
| 1302 | PCtoRDRSecure(); |
| 1303 | MessageToSend = 1; |
| 1304 | break; |
| 1305 | |
| 1306 | case PC_TO_RDR_MECHANICAL: |
| 1307 | PCtoRDRMechanical(); |
| 1308 | MessageToSend = 1; |
| 1309 | break; |
| 1310 | |
| 1311 | case PC_TO_RDR_ABORT: |
| 1312 | PCtoRDRAbort(); |
| 1313 | MessageToSend = 1; |
| 1314 | break; |
| 1315 | |
| 1316 | case PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY: |
| 1317 | PCtoRDRSetDataRateAndClockFrequency(); |
| 1318 | MessageToSend = 1; |
| 1319 | break; |
| 1320 | |
| 1321 | default: |
| 1322 | TRACE_DEBUG("default: 0x%X\n\r", ccidDriver.sCcidCommand.bMessageType); |
| 1323 | vCCIDCommandNotSupported(); |
| 1324 | MessageToSend = 1; |
| 1325 | break; |
| 1326 | |
| 1327 | } |
| 1328 | |
| 1329 | if( MessageToSend == 1 ) { |
| 1330 | vCCIDSendResponse(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1335 | //------------------------------------------------------------------------------ |
| 1336 | /// SETUP request handler for a CCID device |
| 1337 | /// \param pRequest Pointer to a USBGenericRequest instance |
| 1338 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1339 | static void CCID_RequestHandler(const USBGenericRequest *pRequest) |
| 1340 | { |
| 1341 | TRACE_DEBUG("CCID_RHl\n\r"); |
| 1342 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1343 | // Check if this is a class request |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1344 | if (USBGenericRequest_GetType(pRequest) == USBGenericRequest_CLASS) { |
| 1345 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1346 | // Check if the request is supported |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1347 | switch (USBGenericRequest_GetRequest(pRequest)) { |
| 1348 | |
| 1349 | case CCIDGenericRequest_ABORT: |
| 1350 | TRACE_DEBUG("CCIDGenericRequest_ABORT\n\r"); |
| 1351 | break; |
| 1352 | |
| 1353 | case CCIDGenericRequest_GET_CLOCK_FREQUENCIES: |
| 1354 | TRACE_DEBUG("Not supported\n\r"); |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1355 | // A CCID with bNumClockSupported equal to 00h does not have |
| 1356 | // to support this request |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1357 | break; |
| 1358 | |
| 1359 | case CCIDGenericRequest_GET_DATA_RATES: |
| 1360 | TRACE_DEBUG("Not supported\n\r"); |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1361 | // A CCID with bNumDataRatesSupported equal to 00h does not have |
| 1362 | // to support this request. |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | default: |
| 1366 | TRACE_WARNING( "CCIDDriver_RequestHandler: Unsupported request (%d)\n\r", |
| 1367 | USBGenericRequest_GetRequest(pRequest)); |
| 1368 | USBD_Stall(0); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | else if (USBGenericRequest_GetType(pRequest) == USBGenericRequest_STANDARD) { |
| 1373 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1374 | // Forward request to the standard handler |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1375 | USBDDriver_RequestHandler(&(ccidDriver.usbdDriver), pRequest); |
| 1376 | } |
| 1377 | else { |
| 1378 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1379 | // Unsupported request type |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1380 | TRACE_WARNING( "CCIDDriver_RequestHandler: Unsupported request type (%d)\n\r", |
| 1381 | USBGenericRequest_GetType(pRequest)); |
| 1382 | USBD_Stall(0); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1387 | //------------------------------------------------------------------------------ |
| 1388 | // Exported functions |
| 1389 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1390 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1391 | //------------------------------------------------------------------------------ |
| 1392 | /// Optional callback re-implementation |
| 1393 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1394 | #if !defined(NOAUTOCALLBACK) |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1395 | // not static function |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1396 | void USBDCallbacks_RequestReceived(const USBGenericRequest *request) |
| 1397 | { |
| 1398 | CCID_RequestHandler(request); |
| 1399 | } |
| 1400 | #endif |
| 1401 | |
| 1402 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1403 | //------------------------------------------------------------------------------ |
| 1404 | /// Handles SmartCart request |
| 1405 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1406 | void CCID_SmartCardRequest( void ) |
| 1407 | { |
| 1408 | unsigned char bStatus; |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1409 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1410 | |
| 1411 | do { |
| 1412 | |
| 1413 | bStatus = CCID_Read( (void*)&ccidDriver.sCcidCommand, |
| 1414 | sizeof(S_ccid_bulk_out_header), |
| 1415 | (TransferCallback)&CCIDCommandDispatcher, |
| 1416 | (void*)0 ); |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1417 | // TRACE_DEBUG("bStat: %x\n\r", bStatus); |
| 1418 | } |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1419 | while (bStatus != USBD_STATUS_SUCCESS); |
| 1420 | |
| 1421 | } |
| 1422 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1423 | //------------------------------------------------------------------------------ |
| 1424 | /// Initializes the CCID device driver. |
| 1425 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1426 | void CCIDDriver_Initialize( void ) |
| 1427 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1428 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1429 | USBDDriver_Initialize(&(ccidDriver.usbdDriver), |
| 1430 | &ccidDriverDescriptors, |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1431 | 0); // Multiple interface settings not supported |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1432 | USBD_Init(); |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1433 | TRACE_DEBUG("%s", "leaving"); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1436 | //------------------------------------------------------------------------------ |
| 1437 | /// Reads data from the Data OUT endpoint |
| 1438 | /// \param pBuffer Buffer to store the received data |
| 1439 | /// \param dLength data buffer length |
| 1440 | /// \param fCallback Optional callback function |
| 1441 | /// \param pArgument Optional parameter for the callback function |
| 1442 | /// \return USBD_STATUS_LOCKED or USBD_STATUS_SUCCESS |
| 1443 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1444 | unsigned char CCID_Read(void *pBuffer, |
| 1445 | unsigned int dLength, |
| 1446 | TransferCallback fCallback, |
| 1447 | void *pArgument) |
| 1448 | { |
| 1449 | return USBD_Read(CCID_EPT_DATA_OUT, pBuffer, dLength, fCallback, pArgument); |
| 1450 | } |
| 1451 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1452 | //------------------------------------------------------------------------------ |
| 1453 | /// Sends data through the Data IN endpoint |
| 1454 | /// \param pBuffer Buffer holding the data to transmit |
| 1455 | /// \param dLength Length of data buffer |
| 1456 | /// \param fCallback Optional callback function |
| 1457 | /// \param pArgument Optional parameter for the callback function |
| 1458 | /// \return USBD_STATUS_LOCKED or USBD_STATUS_SUCCESS |
| 1459 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1460 | unsigned char CCID_Write(void *pBuffer, |
| 1461 | unsigned int dLength, |
| 1462 | TransferCallback fCallback, |
| 1463 | void *pArgument) |
| 1464 | { |
| 1465 | return USBD_Write(CCID_EPT_DATA_IN, pBuffer, dLength, fCallback, pArgument); |
| 1466 | } |
| 1467 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1468 | //------------------------------------------------------------------------------ |
| 1469 | /// Sends data through the interrupt endpoint, ICC insertion event |
| 1470 | /// RDR_to_PC_NotifySlotChange |
| 1471 | /// \return USBD_STATUS_LOCKED or USBD_STATUS_SUCCESS |
| 1472 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1473 | unsigned char CCID_Insertion( void ) |
| 1474 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1475 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1476 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1477 | // Build the Interrupt-IN message |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1478 | ccidDriver.BufferINT[0] = RDR_TO_PC_NOTIFYSLOTCHANGE; |
| 1479 | ccidDriver.BufferINT[1] = ICC_INSERTED_EVENT; |
| 1480 | ccidDriver.SlotStatus = ICC_INSERTED_EVENT; |
| 1481 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1482 | // Notify the host that a ICC is inserted |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1483 | return USBD_Write( CCID_EPT_NOTIFICATION, ccidDriver.BufferINT, 2, 0, 0 ); |
| 1484 | } |
| 1485 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1486 | //------------------------------------------------------------------------------ |
| 1487 | /// Sends data through the interrupt endpoint, ICC removal event |
| 1488 | /// RDR_to_PC_NotifySlotChange |
| 1489 | /// \return USBD_STATUS_LOCKED or USBD_STATUS_SUCCESS |
| 1490 | //------------------------------------------------------------------------------ |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1491 | unsigned char CCID_Removal( void ) |
| 1492 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1493 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1494 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1495 | // Build the Interrupt-IN message |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1496 | ccidDriver.BufferINT[0] = RDR_TO_PC_NOTIFYSLOTCHANGE; |
| 1497 | ccidDriver.BufferINT[1] = ICC_NOT_PRESENT; |
| 1498 | ccidDriver.SlotStatus = ICC_NOT_PRESENT; |
| 1499 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1500 | // Notify the host that a ICC is inserted |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1501 | return USBD_Write( CCID_EPT_NOTIFICATION, ccidDriver.BufferINT, 2, 0, 0 ); |
| 1502 | } |
| 1503 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1504 | //------------------------------------------------------------------------------ |
| 1505 | /// Interrupt-IN Messages |
| 1506 | /// This message is sent when any bit in the bHardwareErrorCode field is set. |
| 1507 | /// If this message is sent when there is no “outstanding” command, the bSeq |
| 1508 | /// field will be undefined. |
| 1509 | /// \param bSlot ICC slot number |
| 1510 | /// \param bSeq Sequence number of the bulk OUT command when the hardware error |
| 1511 | /// occured |
| 1512 | /// \param bHardwareErrorCode Hardware error code |
| 1513 | /// \return USBD_STATUS_LOCKED or USBD_STATUS_SUCCESS |
| 1514 | //------------------------------------------------------------------------------ |
| 1515 | unsigned char RDRtoPCHardwareError( unsigned char bSlot, |
| 1516 | unsigned char bSeq, |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1517 | unsigned char bHardwareErrorCode ) |
| 1518 | { |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1519 | TRACE_DEBUG("."); |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1520 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1521 | // Build the Interrupt-IN message |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1522 | ccidDriver.BufferINT[0] = RDR_TO_PC_HARDWAREERROR; |
| 1523 | ccidDriver.BufferINT[1] = bSlot; |
| 1524 | ccidDriver.BufferINT[2] = bSeq; |
| 1525 | ccidDriver.BufferINT[3] = bHardwareErrorCode; |
| 1526 | |
Christina Quast | f51e0d2 | 2015-01-03 21:51:24 +0100 | [diff] [blame] | 1527 | // Notify the host that a ICC is inserted |
Christina Quast | b123d74 | 2014-12-23 13:03:36 +0100 | [diff] [blame] | 1528 | return USBD_Write( CCID_EPT_NOTIFICATION, ccidDriver.BufferINT, 4, 0, 0 ); |
| 1529 | } |
| 1530 | |
| 1531 | |