1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device CCID Class                                                   */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /**************************************************************************/
23 /*                                                                        */
24 /*  COMPONENT DEFINITION                                   RELEASE        */
25 /*                                                                        */
26 /*    ux_device_class_ccid.h                              PORTABLE C      */
27 /*                                                           6.2.1        */
28 /*  AUTHOR                                                                */
29 /*                                                                        */
30 /*    Chaoqiong Xiao, Microsoft Corporation                               */
31 /*                                                                        */
32 /*  DESCRIPTION                                                           */
33 /*                                                                        */
34 /*    This file defines the equivalences for the USBX Device Class CCID   */
35 /*    (Smart-Card Integrated Circuit(s) Card) component.                  */
36 /*                                                                        */
37 /*  RELEASE HISTORY                                                       */
38 /*                                                                        */
39 /*    DATE              NAME                      DESCRIPTION             */
40 /*                                                                        */
41 /*  04-25-2022     Chaoqiong Xiao           Initial Version 6.1.11        */
42 /*  03-08-2023     Chaoqiong Xiao           Modified comment(s),          */
43 /*                                            added standalone support,   */
44 /*                                            resulting in version 6.2.1  */
45 /*                                                                        */
46 /**************************************************************************/
47 
48 #ifndef UX_DEVICE_CLASS_CCID_H
49 #define UX_DEVICE_CLASS_CCID_H
50 
51 /* Determine if a C++ compiler is being used.  If so, ensure that standard
52    C is used to process the API information.  */
53 
54 #ifdef   __cplusplus
55 
56 /* Yes, C++ compiler is present.  Use standard C.  */
57 extern   "C" {
58 #endif
59 
60 #if !defined(UX_DEVICE_STANDALONE)
61 
62 /* Define CCID max number of slots, 32 for 32 bit data width.  */
63 #define UX_DEVICE_CLASS_CCID_MAX_N_SLOTS                                    (4*8)
64 #else
65 
66 /* To optimize the max number of slots fixed to 1.  */
67 #define UX_DEVICE_CLASS_CCID_MAX_N_SLOTS                                    1
68 #endif
69 
70 /* Thread stack size, for RTOS mode only.  */
71 #define UX_DEVICE_CLASS_CCID_THREAD_STACK_SIZE                              UX_THREAD_STACK_SIZE
72 #define UX_DEVICE_CLASS_CCID_NOTIFY_THREAD_STACK_SIZE                       UX_THREAD_STACK_SIZE
73 #define UX_DEVICE_CLASS_CCID_RUNNER_THREAD_STACK_SIZE                       UX_THREAD_STACK_SIZE
74 
75 /* Define CCID Class USB Class constants.  */
76 #define UX_DEVICE_CLASS_CCID_CLASS                                          0x0B
77 
78 #define UX_DEVICE_CLASS_CCID_SUBCLASS                                       0
79 
80 #define UX_DEVICE_CLASS_CCID_PROTOCOL                                       0
81 
82 #define UX_DEVICE_CLASS_CCID_BCD_CCID_1_10                                  0x0110
83 
84 #define UX_DEVICE_CLASS_CCID_VOLTAGE_SUPPORT_5_0                            1u
85 #define UX_DEVICE_CLASS_CCID_VOLTAGE_SUPPORT_3_0                            2u
86 #define UX_DEVICE_CLASS_CCID_VOLTAGE_SUPPORT_1_8                            4u
87 
88 #define UX_DEVICE_CLASS_CCID_PROTOCOLS_T0                                   1u
89 #define UX_DEVICE_CLASS_CCID_PROTOCOLS_T1                                   2u
90 
91 #define UX_DEVICE_CLASS_CCID_SYNCH_PROTOCOLS_2_WIRE                         1u
92 #define UX_DEVICE_CLASS_CCID_SYNCH_PROTOCOLS_3_WIRE                         2u
93 #define UX_DEVICE_CLASS_CCID_SYNCH_PROTOCOLS_I2C                            4u
94 
95 #define UX_DEVICE_CLASS_CCID_MECHANICAL_NO_SPECIAL                          0u
96 #define UX_DEVICE_CLASS_CCID_MECHANICAL_ACCEPT                              1u
97 #define UX_DEVICE_CLASS_CCID_MECHANICAL_EJECT                               2u
98 #define UX_DEVICE_CLASS_CCID_MECHANICAL_CAPTURE                             4u
99 #define UX_DEVICE_CLASS_CCID_MECHANICAL_LOCK_UNLOCK                         8u
100 
101 #define UX_DEVICE_CLASS_CCID_FEATURES_NO_SPECIAL                            0u
102 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_PARAMETER_ATR                    2u
103 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_ACTIVATION                       4u
104 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_VOLTAGE                          8u
105 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_CLOCK_FREQUENCY                  0x10u
106 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_BAUD_RATE                        0x20u
107 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_PARAMETER_NEGOTIATION            0x40u
108 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_PPS                              0x80u
109 #define UX_DEVICE_CLASS_CCID_FEATURES_CAN_SET_ICC_IN_CLOCK_STOP             0x100u
110 #define UX_DEVICE_CLASS_CCID_FEATURES_NAD_NOT_0_ACCEPTED                    0x200u
111 #define UX_DEVICE_CLASS_CCID_FEATURES_AUTO_IFSD_EXCHANGE_1ST                0x400u
112 #define UX_DEVICE_CLASS_CCID_FEATURES_TPUD_EXCHANGES                        0x10000u
113 #define UX_DEVICE_CLASS_CCID_FEATURES_SHORT_APUD_EXCHANGES                  0x20000u
114 #define UX_DEVICE_CLASS_CCID_FEATURES_SHORT_AND_EXTENDED_APUD_EXCHANGES     0x40000u
115 #define UX_DEVICE_CLASS_CCID_FEATURES_WAKEUP_ON_INSERTION_REMOVAL           0x100000u
116 
117 #define UX_DEVICE_CLASS_CCID_LCD_LAYOUT_NO_LCD                              0
118 #define UX_DEVICE_CLASS_CCID_LCD_LAYOUT(n_lines,n_per_line)                 (((n_lines) << 8) | (n_per_line))
119 
120 #define UX_DEVICE_CLASS_CCID_PIN_SUPPORT_VERIFICATION                       1u
121 #define UX_DEVICE_CLASS_CCID_PIN_SUPPORT_MODIFICATION                       2u
122 
123 #define UX_DEVICE_CLASS_CCID_MAX_CCID_MESSAGE_EXT_APDU_MIN                  (261+10)
124 #define UX_DEVICE_CLASS_CCID_MAX_CCID_MESSAGE_EXT_APDU_MAX                  (65544+10)
125 
126 
127 /* Device CCID Requests */
128 #define UX_DEVICE_CLASS_CCID_ABORT                                          0x01
129 #define UX_DEVICE_CLASS_CCID_GET_CLOCK_FREQUENCIES                          0x02
130 #define UX_DEVICE_CLASS_CCID_GET_DATA_RATES                                 0x03
131 
132 
133 /* CCID message offsets, values.  */
134 
135 /* General.  */
136 #define UX_DEVICE_CLASS_CCID_MESSAGE_HEADER_LENGTH                          10
137 
138 #define UX_DEVICE_CLASS_CCID_OFFSET_MESSAGE_TYPE                            0
139 #define UX_DEVICE_CLASS_CCID_OFFSET_LENGTH                                  1
140 #define UX_DEVICE_CLASS_CCID_OFFSET_SLOT                                    5
141 #define UX_DEVICE_CLASS_CCID_OFFSET_SEQ                                     6
142 
143 #define UX_DEVICE_CLASS_CCID_OFFSET_DATA                                    10
144 
145 /* PC_to_RDR_IccPowerOn.  */
146 #define UX_DEVICE_CLASS_CCID_OFFSET_POWER_SELECT                            7
147 #define UX_DEVICE_CLASS_CCID_POWER_SELECT_AUTO                              0
148 #define UX_DEVICE_CLASS_CCID_POWER_SELECT_5_0_V                             1
149 #define UX_DEVICE_CLASS_CCID_POWER_SELECT_3_0_V                             2
150 #define UX_DEVICE_CLASS_CCID_POWER_SELECT_1_8_V                             3
151 
152 /* PC_to_RDR_XfrBlock/PC_to_RDR_Secure.  */
153 #define UX_DEVICE_CLASS_CCID_OFFSET_BWI                                     7
154 #define UX_DEVICE_CLASS_CCID_OFFSET_LEVEL_PARAMETER                         8
155 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_RFU                            0x00u
156 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_BEGIN_END                      0x00u
157 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_BEGIN_CONTINUE                 0x01u
158 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_CONTINUE_END                   0x02u
159 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_CONTINUE                       0x03u
160 #define UX_DEVICE_CLASS_CCID_LEVEL_PARAMETER_EMPTY_DATA                     0x10u
161 
162 /* PC_to_RDR_SetParameters.  */
163 #define UX_DEVICE_CLASS_CCID_OFFSET_SET_PARAMETERS_PROTOCOL_NUM             7
164 
165 #define UX_DEVICE_CLASS_CCID_PROTOCOL_T_0                                   0
166 #define UX_DEVICE_CLASS_CCID_PROTOCOL_T_1                                   1
167 #define UX_DEVICE_CLASS_CCID_PROTOCOL_2_WIRE                                0x80
168 #define UX_DEVICE_CLASS_CCID_PROTOCOL_3_WIRE                                0x81
169 #define UX_DEVICE_CLASS_CCID_PROTOCOL_I2C                                   0x82
170 
171 /* Parameters.  */
172 #define UX_DEVICE_CLASS_CCID_OFFSET_FI_DI                                   10
173 
174 #define UX_DEVICE_CLASS_CCID_OFFSET_TCCKS_T0                                11
175 #define UX_DEVICE_CLASS_CCID_OFFSET_GUARD_TIME_T0                           12
176 #define UX_DEVICE_CLASS_CCID_OFFSET_WAITING_INTEGER_T0                      13
177 #define UX_DEVICE_CLASS_CCID_OFFSET_CLOCK_STOP_T0                           14
178 
179 #define UX_DEVICE_CLASS_CCID_OFFSET_TCCKS_T1                                11
180 #define UX_DEVICE_CLASS_CCID_OFFSET_GUARD_TIME_T1                           12
181 #define UX_DEVICE_CLASS_CCID_OFFSET_WAITING_INTEGERS_T1                     13
182 #define UX_DEVICE_CLASS_CCID_OFFSET_CLOCK_STOP_T1                           14
183 #define UX_DEVICE_CLASS_CCID_OFFSET_IFSC                                    15
184 #define UX_DEVICE_CLASS_CCID_OFFSET_NAD_VALUE                               16
185 
186 /* PC_to_RDR_IccClock.  */
187 #define UX_DEVICE_CLASS_CCID_OFFSET_CLOCK_COMMAND                           7
188 #define UX_DEVICE_CLASS_CCID_CLOCK_COMMAND_RESTART                          0
189 #define UX_DEVICE_CLASS_CCID_CLOCK_COMMAND_STOP                             1
190 
191 /* PC_to_RDR_T0APDU.  */
192 #define UX_DEVICE_CLASS_CCID_OFFSET_CHANGES                                 7
193 #define UX_DEVICE_CLASS_CCID_OFFSET_CLASS_GET_RESPONSE                      8
194 #define UX_DEVICE_CLASS_CCID_OFFSET_CLASS_ENVELOPE                          9
195 #define UX_DEVICE_CLASS_CCID_CHANGE_CLASS_GET_RESPONSE                      (1u << 0)
196 #define UX_DEVICE_CLASS_CCID_CHANGE_CLASS_ENVELOPE                          (1u << 1)
197 
198 /* PC_to_RDR_Secure.  */
199 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_OPERATION                           10
200 #define UX_DEVICE_CLASS_CCID_PIN_VERIFICATION                               0
201 #define UX_DEVICE_CLASS_CCID_PIN_MODIFICATION                               1
202 #define UX_DEVICE_CLASS_CCID_PIN_TRANSFER                                   2
203 #define UX_DEVICE_CLASS_CCID_PIN_WAIT_ICC_RESP                              3
204 #define UX_DEVICE_CLASS_CCID_PIN_CANCEL                                     4
205 #define UX_DEVICE_CLASS_CCID_PIN_RESEND_I_BLOCK                             5
206 #define UX_DEVICE_CLASS_CCID_PIN_NEXT_APDU                                  6
207 
208 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_DATA                                11
209 
210 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_TIME_OUT                            11
211 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_FORMAT_STRING                       12
212 
213 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_FORMAT_TYPE_MASK                 (0x3u << 0)
214 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_BINARY                           (0x0u << 0)
215 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_BCD                              (0x1u << 0)
216 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_ASCII                            (0x2u << 0)
217 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_JUSTIFICATION                    (0x1u << 2)
218 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_LEFT_JUSTIFY                     (0x0u << 2)
219 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_RIGHT_JUSTIFY                    (0x1u << 2)
220 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_POSITION_MASK                    (0xFu << 3)
221 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_POSITION(v)                      (((v) >> 3) & 0xFu)
222 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_UNIT_TYPE                        (0x1u << 7)
223 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_UNIT_BITS                        (0x0u << 7)
224 #define UX_DEVICE_CLASS_CCID_FORMAT_STRING_UNIT_BYTES                       (0x1u << 7)
225 
226 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_PIN_BLOCK_STRING                    13
227 #define UX_DEVICE_CLASS_CCID_PIN_BLOCK_STRING_PIN_LENGTH_BITS_MASK          (0xFu << 3)
228 #define UX_DEVICE_CLASS_CCID_PIN_BLOCK_STRING_PIN_BLOCK_SIZE_BYTES_MASK     (0xFu << 0)
229 #define UX_DEVICE_CLASS_CCID_PIN_BLOCK_STRING_PIN_LENGTH_BITS(v)            ((v) >> 4) & 0xFu)
230 #define UX_DEVICE_CLASS_CCID_PIN_BLOCK_STRING_PIN_BLOCK_SIZE_BYTES(v)       ((v) >> 0) & 0xFu)
231 
232 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_PIN_LENGTH_FORMAT                   14
233 #define UX_DEVICE_CLASS_CCID_PIN_LENGTH_FORMAT_UNIT_TYPE                    (1u << 4)
234 #define UX_DEVICE_CLASS_CCID_PIN_LENGTH_FORMAT_UNIT_BITS                    (0u << 4)
235 #define UX_DEVICE_CLASS_CCID_PIN_LENGTH_FORMAT_UNIT_BYTES                   (1u << 4)
236 #define UX_DEVICE_CLASS_CCID_PIN_LENGTH_FORMAT_POSITION_MASK                (0xFu << 0)
237 #define UX_DEVICE_CLASS_CCID_PIN_LENGTH_FORMAT_POSITION(v)                  (((v) << 0) & 0xFu)
238 
239 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_TIME_OUT                     11
240 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_FORMAT_STRING                12
241 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_BLOCK_STRING             13
242 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_LENGTH_FORMAT            14
243 
244 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_MAX_EXTRA_DIGIT          15
245 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_MAX_EXTRA_DIGIT_MIN      16
246 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_MAX_EXTRA_DIGIT_MAX      15
247 
248 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_ENTRY_VALIDATION_CONDITION   17
249 #define UX_DEVICE_CLASS_CCID_PIN_ENTRY_VALIDATION_MAX_SIZE                  1u
250 #define UX_DEVICE_CLASS_CCID_PIN_ENTRY_VALIDATION_KEY_PRESS                 2u
251 #define UX_DEVICE_CLASS_CCID_PIN_ENTRY_VALIDATION_TIMEOUT                   4u
252 
253 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_NUMBER_MESSAGE               18
254 #define UX_DEVICE_CLASS_CCID_PIN_NUMBER_MESSAGE_NO                          0
255 #define UX_DEVICE_CLASS_CCID_PIN_NUMBER_MESSAGE_1                           0
256 #define UX_DEVICE_CLASS_CCID_PIN_NUMBER_MESSAGE_2                           0
257 #define UX_DEVICE_CLASS_CCID_PIN_NUMBER_MESSAGE_3                           0
258 #define UX_DEVICE_CLASS_CCID_PIN_NUMBER_MESSAGE_DEFAULT                     0xFF
259 
260 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_LANG_ID                      19
261 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_MSG_INDEX                    21
262 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_TEO_PROLOGUE                 22
263 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_VERIFI_PIN_APDU                     25
264 
265 #define UX_DEVICE_CLASS_CCID_PIN_MESSAGE_INSERT_PROMPT                      0
266 #define UX_DEVICE_CLASS_CCID_PIN_MESSAGE_MODIFY_PROMPT                      1
267 #define UX_DEVICE_CLASS_CCID_PIN_MESSAGE_NEW_CONFIRM_PROMPT                 2
268 
269 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_TIME_OUT                     11
270 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_FORMAT_STRING                12
271 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_BLOCK_STRING             13
272 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_LENGTH_FORMAT            14
273 
274 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_INSERTION_OFFSET_OLD         15
275 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_INSERTION_OFFSET_NEW         16
276 
277 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_MAX_EXTRA_DIGIT          17
278 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_MAX_EXTRA_DIGIT_MIN      18
279 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_MAX_EXTRA_DIGIT_MAX      17
280 
281 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_CONFIRM_PIN                  19
282 #define UX_DEVICE_CLASS_CCID_CONFIRM_PIN_CONFIRM_REQUESTED                  (1u << 0)
283 #define UX_DEVICE_CLASS_CCID_CONFIRM_PIN_ENTRY_REQUESTED                    (1u << 1)
284 
285 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_ENTRY_VALIDATION_CONDITION   20
286 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_NUMBER_MESSAGE               21
287 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_LANG_ID                      22
288 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_MSG_INDEX1                   24
289 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_MSG_INDEX2                   25
290 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_MSG_INDEX3                   26
291 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_TEO_PROLOGUE1                25
292 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_TEO_PROLOGUE2                26
293 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_TEO_PROLOGUE3                27
294 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_APDU1                    28
295 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_APDU2                    29
296 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_MODIFI_PIN_APDU3                    30
297 
298 #define UX_DEVICE_CLASS_CCID_OFFSET_PIN_NEXT_APDU_TEO_PROLOGUE              11
299 
300 /* PC_to_RDR_Mechanical.  */
301 #define UX_DEVICE_CLASS_CCID_OFFSET_FUNCTION                                7
302 #define UX_DEVICE_CLASS_CCID_FUNCTION_ACCEPT_CARD                           0x01
303 #define UX_DEVICE_CLASS_CCID_FUNCTION_EJECT_CARD                            0x02
304 #define UX_DEVICE_CLASS_CCID_FUNCTION_CAPTURE_CARD                          0x03
305 #define UX_DEVICE_CLASS_CCID_FUNCTION_LOCK_CARD                             0x04
306 #define UX_DEVICE_CLASS_CCID_FUNCTION_UNLOCK_CARD                           0x05
307 
308 /* PC_to_RDR_SetDataRateAndClockFrequency/RDR_to_PC_DataRateAndClockFrequency.  */
309 #define UX_DEVICE_CLASS_CCID_OFFSET_CLOCK_FREQUENCY                         10
310 #define UX_DEVICE_CLASS_CCID_OFFSET_DATA_RATE                               14
311 
312 /* RDR_to_PC_   */
313 #define UX_DEVICE_CLASS_CCID_OFFSET_STATUS                                  7
314 #define UX_DEVICE_CLASS_CCID_OFFSET_ERROR                                   8
315 
316 /* RDR_to_PC_DataBlock.  */
317 #define UX_DEVICE_CLASS_CCID_OFFSET_CHAIN_PARAMETER                         9
318 #define UX_DEVICE_CLASS_CCID_CHAIN_PARAMETER_BEGIN_END                      0x00
319 #define UX_DEVICE_CLASS_CCID_CHAIN_PARAMETER_BEGIN_CONTINUE                 0x01
320 #define UX_DEVICE_CLASS_CCID_CHAIN_PARAMETER_CONTINUE_END                   0x02
321 #define UX_DEVICE_CLASS_CCID_CHAIN_PARAMETER_CONTINUE                       0x03
322 #define UX_DEVICE_CLASS_CCID_CHAIN_PARAMETER_EMPTY                          0x10
323 
324 /* RDR_to_PC_SlotStatus.  */
325 #define UX_DEVICE_CLASS_CCID_OFFSET_CLOCK_STATUS                            9
326 
327 /* RDR_to_PC_Parameters.  */
328 #define UX_DEVICE_CLASS_CCID_OFFSET_PARAMETERS_PROTOCOL_NUM                 9
329 
330 #define UX_DEVICE_CLASS_CCID_PARAMETERS_T0_LENGTH                           5
331 #define UX_DEVICE_CLASS_CCID_PARAMETERS_T1_LENGTH                           7
332 
333 /* RDR_to_PC_NotifySlotChange.  */
334 #define UX_DEVICE_CLASS_CCID_OFFSET_SLOT_ICC_STATE                          1
335 
336 /* RDR_to_PC_HardwareError.  */
337 #define UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_SLOT                           1
338 #define UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_SEQ                            2
339 #define UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_CODE                           3
340 #define UX_DEVICE_CLASS_CCID_HW_ERROR_OVERCURRENT                           1
341 
342 
343 /* CCID bMessageTypes.  */
344 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_ON                         0x62
345 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_OFF                        0x63
346 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_GET_SLOT_STATUS                      0x64
347 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK                            0x6F
348 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_GET_PARAMETERS                       0x6C
349 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_RESET_PARAMETERS                     0x6D
350 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS                       0x61
351 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_ESCAPE                               0x6B
352 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_CLOCK                            0x6E
353 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU                              0x6A
354 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE                               0x69
355 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_MECHANICAL                           0x71
356 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_ABORT                                0x72
357 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQ         0x73
358 
359 #define UX_DEVICE_CLASS_CCID_N_COMMANDS                                     14
360 
361 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_BLOCK                           0x80
362 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_SLOT_STATUS                          0x81
363 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS                           0x82
364 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_ESCAPE                               0x83
365 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQ             0x84
366 
367 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_NOTIFY_SLOT_CHANGE                   0x50
368 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_HARDWARE_ERROR                       0x51
369 
370 #define UX_DEVICE_CLASS_CCID_COMMAND_ABORTABLE(bMessageType)                \
371     (((bMessageType) == 0x62) || ((bMessageType) == 0x6F) ||                \
372      ((bMessageType) == 0x6B) || ((bMessageType) == 0x69) ||                \
373      ((bMessageType) == 0x71) || ((bMessageType) == 0x72))
374 
375 #define UX_DEVICE_CLASS_CCID_COMMAND_HW_ERROR_CHECK(bMessageType)           \
376     (((bMessageType) != 0x63) && ((bMessageType) != 0x6B) &&                \
377      ((bMessageType) != 0x6A) && ((bMessageType) != 0x72) &&                \
378      ((bMessageType) != 0x73))
379 
380 #define UX_DEVICE_CLASS_CCID_COMMAND_AUTO_SEQUENCE_CHECK(bMessageType)      \
381     (((bMessageType) != 0x62) && ((bMessageType) != 0x65) &&                \
382      ((bMessageType) != 0x6B) && ((bMessageType) != 0x6A) &&                \
383      ((bMessageType) != 0x72) && ((bMessageType) != 0x73))
384 
385 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_DATA_BLOCK(m)                     \
386     ((m) == 0x62 || (m) == 0x6F || (m) == 0x69)
387 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_SLOT_STATUS(m)                    \
388     ((m) == 0x63 || (m) == 0x64 || (m) == 0x6E || (m) == 0x6A ||            \
389      (m) == 0x71 || (m) == 0x72 || (m) == 0x65)
390 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_PARAMETERS(m)                     \
391     ((m) == 0x6C || (m) == 0x6D || (m) == 0x61)
392 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_ESCAPE(m)                         \
393     ((m) == 0x6B)
394 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_DATA_RATE_AND_CLOCK_FREQ(m)       \
395     ((m) == 0x73)
396 
397 #define UX_DEVICE_CLASS_CCID_COMMAND_RESP_TYPE(m)                           \
398     (UX_DEVICE_CLASS_CCID_COMMAND_RESP_DATA_BLOCK(m) ? 0x80 :               \
399      UX_DEVICE_CLASS_CCID_COMMAND_RESP_SLOT_STATUS(m) ? 0x81 :              \
400      UX_DEVICE_CLASS_CCID_COMMAND_RESP_PARAMETERS(m) ? 0x82 :               \
401      UX_DEVICE_CLASS_CCID_COMMAND_RESP_ESCAPE(m) ? 0x83 :                   \
402      UX_DEVICE_CLASS_CCID_COMMAND_RESP_DATA_RATE_AND_CLOCK_FREQ(m) ? 0x84 : \
403      0)
404 
405 /* CCID Slot error binary code.  */
406 #define UX_DEVICE_CLASS_CCID_CMD_ABORTED                                    0xFF
407 #define UX_DEVICE_CLASS_CCID_ICC_MUTE                                       0xFE
408 #define UX_DEVICE_CLASS_CCID_XFR_PARITY_ERROR                               0xFD
409 #define UX_DEVICE_CLASS_CCID_XFR_OVERRUN                                    0xFC
410 #define UX_DEVICE_CLASS_CCID_HW_ERROR                                       0xFB
411 #define UX_DEVICE_CLASS_CCID_BAD_ATR_TS                                     0xF8
412 #define UX_DEVICE_CLASS_CCID_BAD_ATR_TCK                                    0xF7
413 #define UX_DEVICE_CLASS_CCID_ICC_PROTOCOL_NOT_SUPPORTED                     0xF6
414 #define UX_DEVICE_CLASS_CCID_ICC_CLASS_NOT_SUPPORTED                        0xF5
415 #define UX_DEVICE_CLASS_CCID_PROCEDURE_BYTE_CONFLICT                        0xF4
416 #define UX_DEVICE_CLASS_CCID_DEACTIVATED_PROTOCOL                           0xF3
417 #define UX_DEVICE_CLASS_CCID_BUSY_WITH_AUTO_SEQUENCE                        0xF2
418 #define UX_DEVICE_CLASS_CCID_PIN_TIMEOUT                                    0xF0
419 #define UX_DEVICE_CLASS_CCID_PIN_CANCELLED                                  0xEF
420 #define UX_DEVICE_CLASS_CCID_CMD_SLOT_BUSY                                  0xE0
421 
422 
423 /* CCID bStatus.  */
424 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_TIME_EXTENSION                     0x80
425 
426 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_ICC_ACTIVE                         (0x0u)
427 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_ICC_INACTIVE                       (0x1u)
428 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_ICC_NOT_PRESENT                    (0x2u)
429 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_ICC_MASK                           (0x3u)
430 
431 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_CMD_NO_ERROR                       (0x0u << 6)
432 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_CMD_FAILED                         (0x1u << 6)
433 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_CMD_TIME_EXTENSION                 (0x2u << 6)
434 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS_CMD_MASK                           (0x3u << 6)
435 
436 #define UX_DEVICE_CLASS_CCID_SLOT_STATUS(bmICCStatus, bmCommandStatus)      ((bmICCStatus) | ((bmCommandStatus) << 6))
437 #define UX_DEVICE_CLASS_CCID_ICC_ACTIVE                                     0
438 #define UX_DEVICE_CLASS_CCID_ICC_INACTIVE                                   1
439 #define UX_DEVICE_CLASS_CCID_ICC_NOT_PRESENT                                2
440 #define UX_DEVICE_CLASS_CCID_CMD_NO_ERROR                                   0
441 #define UX_DEVICE_CLASS_CCID_CMD_FAILED                                     1
442 #define UX_DEVICE_CLASS_CCID_CMD_TIME_EXTENSION                             2
443 
444 
445 /* CCID events.  */
446 #define UX_DEVICE_CLASS_CCID_EVENT_SLOT(n)                                  (1u<<(n))
447 
448 
449 /* CCID flags.  */
450 #define UX_DEVICE_CLASS_CCID_FLAG_ABORTABLE                                 0x80u
451 #define UX_DEVICE_CLASS_CCID_FLAG_BUSY                                      0x40u
452 
453 #define UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_CHANGE                             0x01u
454 #define UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_HW_ERROR                           0x02u
455 
456 #define UX_DEVICE_CLASS_CCID_FLAG_AUTO_SEQUENCING                           0x04u
457 #define UX_DEVICE_CLASS_CCID_FLAG_HW_ERROR                                  0x08u
458 
459 
460 #define UX_DEVICE_CLASS_CCID_COMMAND_FLAG_ABORTABLE(bMessageType)           \
461     (UX_DEVICE_CLASS_CCID_COMMAND_ABORTABLE(bMessageType) ?                 \
462      UX_DEVICE_CLASS_CCID_FLAG_ABORTABLE : 0)
463 
464 #define UX_DEVICE_CLASS_CCID_COMMAND_FLAG_AUTO_SEQUENCE_CHECK(bMessageType) \
465     (UX_DEVICE_CLASS_CCID_COMMAND_AUTO_SEQUENCE_CHECK(bMessageType) ?       \
466      UX_DEVICE_CLASS_CCID_FLAG_AUTO_SEQUENCING : 0)
467 
468 #define UX_DEVICE_CLASS_CCID_COMMAND_FLAG_HW_ERROR_CHECK(bMessageType)      \
469     (UX_DEVICE_CLASS_CCID_COMMAND_HW_ERROR_CHECK(bMessageType) ?            \
470      UX_DEVICE_CLASS_CCID_FLAG_HW_ERROR : 0)
471 
472 #define UX_DEVICE_CLASS_CCID_COMMAND_FLAGS(bMessageType)                    \
473     (UX_DEVICE_CLASS_CCID_COMMAND_FLAG_ABORTABLE(bMessageType) |            \
474      UX_DEVICE_CLASS_CCID_COMMAND_FLAG_AUTO_SEQUENCE_CHECK(bMessageType) |  \
475      UX_DEVICE_CLASS_CCID_COMMAND_FLAG_HW_ERROR_CHECK(bMessageType))
476 
477 
478 /* CCID message structures.  */
479 
480 /* General message for both PC_to_RDR and RDR_to_PC.  */
481 typedef struct UX_DEVICE_CLASS_CCID_MESSAGES_STRUCT
482 {
483     UCHAR       *ux_device_class_ccid_messages_pc_to_rdr;
484     UCHAR       *ux_device_class_ccid_messages_rdr_to_pc;
485     ULONG       ux_device_class_ccid_messages_rdr_to_pc_length; /* Total buffer length including header.  */
486 } UX_DEVICE_CLASS_CCID_MESSAGES;
487 
488 /* Define CCID message header.  */
489 typedef struct UX_DEVICE_CLASS_CCID_MESSAGE_HEADER_STRUCT
490 {
491     UCHAR       bMessageType;
492     UCHAR       dwLength[4];
493     UCHAR       bSlot;
494     UCHAR       bSeq;
495     UCHAR       bRFU[3];
496 } UX_DEVICE_CLASS_CCID_MESSAGE_HEADER;
497 #define UX_DEVICE_CLASS_CCID_MESSAGE_TYPE(msg)                      (((UX_DEVICE_CLASS_CCID_MESSAGE_HEADER*)(msg))->bMessageType)
498 #define UX_DEVICE_CLASS_CCID_MESSAGE_LENGTH_GET(msg)                _ux_utility_long_get(((UX_DEVICE_CLASS_CCID_MESSAGE_HEADER*)(msg))->dwLength)
499 #define UX_DEVICE_CLASS_CCID_MESSAGE_LENGTH_SET(msg,len)            _ux_utility_long_put(((UX_DEVICE_CLASS_CCID_MESSAGE_HEADER*)(msg))->dwLength, (len))
500 #define UX_DEVICE_CLASS_CCID_MESSAGE_SLOT(msg)                      (((UX_DEVICE_CLASS_CCID_MESSAGE_HEADER*)(msg))->bSlot)
501 #define UX_DEVICE_CLASS_CCID_MESSAGE_SEQ(msg)                       (((UX_DEVICE_CLASS_CCID_MESSAGE_HEADER*)(msg))->bSeq)
502 #define UX_DEVICE_CLASS_CCID_MESSAGE_DATA(msg)                      (((UCHAR *)(msg) + UX_DEVICE_CLASS_CCID_MESSAGE_HEADER_LENGTH))
503 
504 /* Define CCID PC_to_RDR_IccPowerOn.  */
505 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_ON_HEADER_STRUCT
506 {
507     UCHAR       bMessageType;
508     UCHAR       dwLength[4];
509     UCHAR       bSlot;
510     UCHAR       bSeq;
511     UCHAR       bPowerSelect;
512     UCHAR       bRFU[2];
513 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_ON_HEADER;
514 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_POWER_SELECT(msg)            (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_ON_HEADER*)(msg))->bPowerSelect)
515 
516 /* Define CCID PC_to_RDR_IccPowerOff.  */
517 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_POWER_OFF_HEADER;
518 
519 /* Define CCID PC_to_RDR_GetSlotStatus.  */
520 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_GET_SLOT_STATUS_HEADER;
521 
522 /* Define CCID PC_to_RDR_XfrBlock.  */
523 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK_HEADER_STRUCT
524 {
525     UCHAR       bMessageType;
526     UCHAR       dwLength[4];
527     UCHAR       bSlot;
528     UCHAR       bSeq;
529     UCHAR       bBWI;
530     USHORT      wLevelParameter;
531 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK_HEADER;
532 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_BWI(msg)                     (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK_HEADER*)(msg))->bBWI)
533 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_LEVEL_PARAMETER(msg)         (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK_HEADER*)(msg))->wLevelParameter)
534 
535 /* Define CCID PC_to_RDR_GetParameters.  */
536 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_GET_PARAMETERS_HEADER;
537 
538 /* Define CCID PC_to_RDR_ResetParameters.  */
539 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_RESET_PARAMETERS_HEADER;
540 
541 /* Define CCID PC_to_RDR_SetParameters.  */
542 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_HEADER_STRUCT
543 {
544     UCHAR       bMessageType;
545     UCHAR       dwLength[4];
546     UCHAR       bSlot;
547     UCHAR       bSeq;
548     UCHAR       bProtocolNum;
549     UCHAR       bRFU[2];
550 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_HEADER;
551 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PROTOCOL_NUM(msg)            (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_HEADER*)(msg))->bProtocolNum)
552 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T0_STRUCT
553 {
554     UCHAR       bMessageType;
555     UCHAR       dwLength[4];
556     UCHAR       bSlot;
557     UCHAR       bSeq;
558     UCHAR       bProtocolNum;
559     UCHAR       bRFU[2];
560     UCHAR       bmFindexDindex;
561     UCHAR       bmTCCKST0;
562     UCHAR       bGuardTimeT0;
563     UCHAR       bWaitingIntegerT0;
564     UCHAR       bClockStop;
565 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T0;
566 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T0_LENGTH     5
567 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T1_STRUCT
568 {
569     UCHAR       bMessageType;
570     UCHAR       dwLength[4];
571     UCHAR       bSlot;
572     UCHAR       bSeq;
573     UCHAR       bProtocolNum;
574     UCHAR       bRFU[2];
575     UCHAR       bmFindexDindex;
576     UCHAR       bmTCCKST1;
577     UCHAR       bGuardTimeT1;
578     UCHAR       bmWaitingIntegersT1;
579     UCHAR       bClockStop;
580     UCHAR       bIFSC;
581     UCHAR       bNadValue;
582 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T1;
583 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_PARAMETERS_T1_LENGTH     7
584 
585 /* Define CCID PC_to_RDR_Escape.  */
586 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_ESCAPE_HEADER;
587 
588 /* Define CCID PC_to_RDR_IccClock.  */
589 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_CLOCK_HEADER_STRUCT
590 {
591     UCHAR       bMessageType;
592     UCHAR       dwLength[4];
593     UCHAR       bSlot;
594     UCHAR       bSeq;
595     UCHAR       bClockCommand;
596     UCHAR       bRFU[2];
597 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_CLOCK_HEADER;
598 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_CLOCK_COMMAND(msg)           (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_ICC_CLOCK_HEADER*)(msg))->bClockCommand)
599 
600 /* Define CCID PC_to_RDR_T0APDU.  */
601 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_HEADER_STRUCT
602 {
603     UCHAR       bMessageType;
604     UCHAR       dwLength[4];
605     UCHAR       bSlot;
606     UCHAR       bSeq;
607     UCHAR       bmChanges;
608     UCHAR       bClassGetResponse;
609     UCHAR       bClassEnvelope;
610 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_HEADER;
611 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_CHANGES(msg)         (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_HEADER*)(msg))->bmChanges)
612 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_CLASS_GET_RESP(msg)  (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_HEADER*)(msg))->bClassGetResponse)
613 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_CLASS_ENVELOPE(msg)  (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_T0_APDU_HEADER*)(msg))->bClassEnvelope)
614 
615 /* Define CCID PC_to_RDR_Secure.  */
616 typedef UX_DEVICE_CLASS_CCID_PC_TO_RDR_XFR_BLOCK_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_HEADER;
617 
618 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_HEADER_STRUCT
619 {
620     UCHAR       bMessageType;
621     UCHAR       dwLength[4];
622     UCHAR       bSlot;
623     UCHAR       bSeq;
624     UCHAR       bBWI;
625     USHORT      wLevelParameter;
626     UCHAR       bPINOperation;
627 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_HEADER;
628 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_BWI(msg)                 (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_HEADER*)(msg))->bBWI)
629 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_LEVEL_PARAMETER(msg)     (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_HEADER*)(msg))->wLevelParameter)
630 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_OPERATION(msg)           (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_HEADER*)(msg))->bPINOperation)
631 
632 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_STRUCT
633 {
634     UCHAR       bMessageType;
635     UCHAR       dwLength[4];
636     UCHAR       bSlot;
637     UCHAR       bSeq;
638     UCHAR       bBWI;
639     USHORT      wLevelParameter;
640     UCHAR       bPINOperation;
641 
642     UCHAR       bTimeOut;
643     UCHAR       bmFormatString;
644     UCHAR       bmPINBlockString;
645     UCHAR       bmPINLengthFormat;
646 
647     UCHAR       wPINMaxExtraDigit[2]; /* XXYY, XX: min size, YY: max size.  */
648     UCHAR       bEntryValidationCondition;
649     UCHAR       bNumberMessage;
650     UCHAR       wLangId[2];
651     UCHAR       bMsgIndex;
652     UCHAR       bTeoPrologue[3];
653 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION;
654 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_TIMEOUT(msg)             (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION*)(msg))->bTimeOut)
655 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_FORMAT_STRING(msg)       (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION*)(msg))->bmFormatString)
656 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_BLOCK_STRING(msg)        (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION*)(msg))->bmPINBlockString)
657 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_LENGTH_FORMAT(msg)       (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION*)(msg))->bmPINLengthFormat)
658 
659 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_PIN_MAX_EXTRA_DIGIT(msg)            _ux_utility_short_get(((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->wPINMaxExtraDigit)
660 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_PIN_MIN_PIN_SIZE(msg)               (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->wPINMaxExtraDigit[1])
661 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_PIN_MAX_PIN_SIZE(msg)               (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->wPINMaxExtraDigit[0])
662 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_ENTRY_VALIDATION_CONDITION(msg)     (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->bEntryValidationCondition)
663 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_NUMBER_MESSAGE(msg)                 (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->bNumberMessage)
664 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_LANG_ID(msg)                        _ux_utility_short_get(((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->wLangId)
665 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_MESSAGE_INDEX(msg)                  (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->bMsgIndex)
666 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_TEO_PROLOGUE(msg)                   (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SECURE_PIN_VERIFICATION*)(msg))->bTeoPrologue)
667 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_DATA(msg)                           ((UCHAR*)(msg) + 25)
668 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_VERIFICATION_APDU(msg)                           ((UCHAR*)(msg) + 25)
669 
670 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION_STRUCT
671 {
672     UCHAR       bMessageType;
673     UCHAR       dwLength[4];
674     UCHAR       bSlot;
675     UCHAR       bSeq;
676     UCHAR       bBWI;
677     USHORT      wLevelParameter;
678     UCHAR       bPINOperation;
679 
680     UCHAR       bTimeOut;
681     UCHAR       bmFormatString;
682     UCHAR       bmPINBlockString;
683     UCHAR       bmPINLengthFormat;
684 
685     UCHAR       bInsertionOffsetOld;
686     UCHAR       bInsertionOffsetNew;
687     UCHAR       wPINMaxExtraDigit[2]; /* XXYY, XX: min size, YY: max size.  */
688     UCHAR       bConfirmPIN;
689     UCHAR       bEntryValidationCondition;
690     UCHAR       bNumberMessage;
691     UCHAR       wLangId[2];
692     UCHAR       bMsgIndex1;
693     UCHAR       bTeoPrologue[3];
694 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION;
695 typedef UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION1;
696 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION1_TEO_PROLOGUE(msg)   ((UCHAR*)(msg) + 25)
697 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION1_DATA(msg)           ((UCHAR*)(msg) + 28)
698 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION1_APDU(msg)           ((UCHAR*)(msg) + 28)
699 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION2_STRUCT
700 {
701     UCHAR       bMessageType;
702     UCHAR       dwLength[4];
703     UCHAR       bSlot;
704     UCHAR       bSeq;
705     UCHAR       bBWI;
706     USHORT      wLevelParameter;
707     UCHAR       bPINOperation;
708     UCHAR       bTimeOut;
709     UCHAR       bmFormatString;
710     UCHAR       bmPINBlockString;
711     UCHAR       bmPINLengthFormat;
712     UCHAR       bInsertionOffsetOld;
713     UCHAR       bInsertionOffsetNew;
714     UCHAR       wPINMaxExtraDigit[2]; /* XXYY, XX: min size, YY: max size.  */
715     UCHAR       bConfirmPIN;
716     UCHAR       bEntryValidationCondition;
717     UCHAR       bNumberMessage;
718     UCHAR       wLangId[2];
719     UCHAR       bMsgIndex1;
720     UCHAR       bMsgIndex2;
721     UCHAR       bTeoPrologue[3];
722 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION2;
723 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION2_TEO_PROLOGUE(msg)   ((UCHAR*)(msg) + 26)
724 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION2_DATA(msg)           ((UCHAR*)(msg) + 29)
725 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION2_APDU(msg)           ((UCHAR*)(msg) + 29)
726 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION3_STRUCT
727 {
728     UCHAR       bMessageType;
729     UCHAR       dwLength[4];
730     UCHAR       bSlot;
731     UCHAR       bSeq;
732     UCHAR       bBWI;
733     USHORT      wLevelParameter;
734     UCHAR       bPINOperation;
735     UCHAR       bTimeOut;
736     UCHAR       bmFormatString;
737     UCHAR       bmPINBlockString;
738     UCHAR       bmPINLengthFormat;
739     UCHAR       bInsertionOffsetOld;
740     UCHAR       bInsertionOffsetNew;
741     UCHAR       wPINMaxExtraDigit[2]; /* XXYY, XX: min size, YY: max size.  */
742     UCHAR       bConfirmPIN;
743     UCHAR       bEntryValidationCondition;
744     UCHAR       bNumberMessage;
745     UCHAR       wLangId[2];
746     UCHAR       bMsgIndex1;
747     UCHAR       bMsgIndex2;
748     UCHAR       bMsgIndex3;
749     UCHAR       bTeoPrologue[3];
750 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION3;
751 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION3_TEO_PROLOGUE(msg)   ((UCHAR*)(msg) + 27)
752 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION3_DATA(msg)           ((UCHAR*)(msg) + 30)
753 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_PIN_MODIFICATION3_APDU(msg)           ((UCHAR*)(msg) + 30)
754 
755 
756 /* Define CCID PC_to_RDR_Mechanical.  */
757 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_MECHANICAL_HEADER_STRUCT
758 {
759     UCHAR       bMessageType;
760     UCHAR       dwLength[4];
761     UCHAR       bSlot;
762     UCHAR       bSeq;
763     UCHAR       bFunction;
764     UCHAR       bRFU[2];
765 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_MECHANICAL_HEADER;
766 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_MECHANICAL_FUNCTION(msg)     (((UX_DEVICE_CLASS_CCID_PC_TO_RDR_MECHANICAL_HEADER*)(msg))->bFunction)
767 
768 /* Define CCID PC_to_RDR_Abort.  */
769 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_ABORT_HEADER;
770 
771 /* Define CCID PC_to_RDR_SetDataRateAndClockFrequency.  */
772 typedef UX_DEVICE_CLASS_CCID_MESSAGE_HEADER UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQUENCY_HEADER;
773 typedef struct UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQUENCY_STRUCT
774 {
775     UCHAR       bMessageType;
776     UCHAR       dwLength[4];
777     UCHAR       bSlot;
778     UCHAR       bSeq;
779     UCHAR       bRFU[3];
780     UCHAR       dwClockFrequency[4];
781     UCHAR       dwDataRate[4];
782 } UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQUENCY;
783 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_CLOCK_FREQUENCY_GET(msg)     _ux_utility_long_get(((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQUENCY*)(msg))->dwClockFrequency)
784 #define UX_DEVICE_CLASS_CCID_PC_TO_RDR_DATA_RATE_GET(msg)           _ux_utility_long_get(((UX_DEVICE_CLASS_CCID_PC_TO_RDR_SET_DATA_RATE_AND_CLOCK_FREQUENCY*)(msg))->dwDataRate)
785 
786 /* Define CCID RDR_to_PC_ header.  */
787 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER_STRUCT
788 {
789     UCHAR       bMessageType;
790     UCHAR       dwLength[4];
791     UCHAR       bSlot;
792     UCHAR       bSeq;
793     UCHAR       bStatus;
794     UCHAR       bError;
795     UCHAR       bRFU;
796 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER;
797 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_STATUS(msg)                  (((UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER*)(msg))->bStatus)
798 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_ERROR(msg)                   (((UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER*)(msg))->bError)
799 
800 /* Define CCID Slot Status Register.  */
801 typedef struct UX_DEVICE_CLASS_CCID_SLOT_STATUS_REGISTER_BITMAP_STRUCT
802 {
803     UCHAR bmICCStatus:2;
804     UCHAR bmRFU:4;
805     UCHAR bmCommandStatus:2;
806 } UX_DEVICE_CLASS_CCID_SLOT_STATUS_REGISTER_BITMAP;
807 
808 /* Define CCID RDR_to_PC_DataBlock.  */
809 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_BLOCK_HEADER_STRUCT
810 {
811     UCHAR       bMessageType;
812     UCHAR       dwLength[4];
813     UCHAR       bSlot;
814     UCHAR       bSeq;
815     UCHAR       bStatus;
816     UCHAR       bError;
817     UCHAR       bChainParameter;
818 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_BLOCK_HEADER;
819 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_CHAIN_PARAMETER(msg)         (((UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_BLOCK_HEADER*)(msg))->bChainParameter)
820 
821 /* Define CCID RDR_to_PC_SlotStatus.  */
822 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_SLOT_STATUS_HEADER_STRUCT
823 {
824     UCHAR       bMessageType;
825     UCHAR       dwLength[4];
826     UCHAR       bSlot;
827     UCHAR       bSeq;
828     UCHAR       bStatus;
829     UCHAR       bError;
830     UCHAR       bClockStatus;
831 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_SLOT_STATUS_HEADER;
832 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_CLOCK_STATUS(msg)            (((UX_DEVICE_CLASS_CCID_RDR_TO_PC_SLOT_STATUS_HEADER*)(msg))->bClockStatus)
833 
834 /* Define CCID RDR_to_PC_Parameters.  */
835 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_HEADER_STRUCT
836 {
837     UCHAR       bMessageType;
838     UCHAR       dwLength[4];
839     UCHAR       bSlot;
840     UCHAR       bSeq;
841     UCHAR       bStatus;
842     UCHAR       bError;
843     UCHAR       bProtocolNum;
844 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_HEADER;
845 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_PROTOCOL_NUM(msg)            (((UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_HEADER*)(msg))->bProtocolNum)
846 
847 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T0_STRUCT
848 {
849     UCHAR       bMessageType;
850     UCHAR       dwLength[4];
851     UCHAR       bSlot;
852     UCHAR       bSeq;
853     UCHAR       bStatus;
854     UCHAR       bError;
855     UCHAR       bProtocolNum;
856     UCHAR       bmFindexDindex;
857     UCHAR       bmTCCKST0;
858     UCHAR       bGuardTimeT0;
859     UCHAR       bWaitingIntegerT0;
860     UCHAR       bClockStop;
861 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T0;
862 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T0_LENGTH         5
863 
864 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T1_STRUCT
865 {
866     UCHAR       bMessageType;
867     UCHAR       dwLength[4];
868     UCHAR       bSlot;
869     UCHAR       bSeq;
870     UCHAR       bStatus;
871     UCHAR       bError;
872     UCHAR       bProtocolNum;
873     UCHAR       bmFindexDindex;
874     UCHAR       bmTCCKST1;
875     UCHAR       bGuardTimeT1;
876     UCHAR       bmWaitingIntegersT1;
877     UCHAR       bClockStop;
878     UCHAR       bIFSC;
879     UCHAR       bNadValue;
880 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T1;
881 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_PARAMETERS_T1_LENGTH         7
882 
883 /* Define CCID RDR_to_PC_Escape.  */
884 typedef UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER UX_DEVICE_CLASS_CCID_RDR_TO_PC_ESCAPE_HEADER;
885 
886 /* Define CCID RDR_to_PC_DataRateAndClockFrequency.  */
887 typedef UX_DEVICE_CLASS_CCID_RDR_TO_PC_HEADER UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQUENCY_HEADER;
888 typedef struct UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQUENCY_STRUCT
889 {
890     UCHAR       bMessageType;
891     UCHAR       dwLength[4];
892     UCHAR       bSlot;
893     UCHAR       bSeq;
894     UCHAR       bStatus;
895     UCHAR       bError;
896     UCHAR       bRFU;
897     UCHAR       dwClockFrequency[4];
898     UCHAR       dwDataRate[4];
899 } UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQUENCY;
900 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_CLOCK_FREQUENCY_SET(msg,v)   _ux_utility_long_put(((UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQUENCY*)(msg))->dwClockFrequency,(v))
901 #define UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_SET(msg,v)         _ux_utility_long_put(((UX_DEVICE_CLASS_CCID_RDR_TO_PC_DATA_RATE_AND_CLOCK_FREQUENCY*)(msg))->dwDataRate,(v))
902 
903 
904 /* Define CCID message command handles, if command handle is not defined device
905    reports command not supported to host.
906    In RTOS mode return normal status code (_SUCCESS/_ERROR/...).
907    In standalone mode return task state status code (_STATE_NEXT/_STATE_ERROR/...).  */
908 typedef UINT (*UX_DEVICE_CLASS_CCID_HANDLE)(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*);
909 typedef struct UX_DEVICE_CLASS_CCID_HANDLES_STRUCT
910 {
911     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_icc_power_on;
912     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_icc_power_off;
913     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_get_slot_status;
914     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_xfr_block;
915     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_get_parameters;
916     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_reset_parameters;
917     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_set_parameters;
918     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_escape;
919     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_icc_clock;
920     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_t0_apdu;
921     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_secure;
922     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_mechanical;
923     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_abort;
924     UX_DEVICE_CLASS_CCID_HANDLE ux_device_class_ccid_handles_set_data_rate_and_clock_frequency;
925 } UX_DEVICE_CLASS_CCID_HANDLES;
926 
927 typedef struct UX_DEVICE_CLASS_CCID_COMMAND_SETT_STRUCT
928 {
929     UCHAR ux_device_class_ccid_command_sett_command_type;
930     UCHAR ux_device_class_ccid_command_sett_response_type;
931     UCHAR ux_device_class_ccid_command_sett_flags;
932     CHAR  ux_device_class_ccid_command_sett_handle_index;
933 } UX_DEVICE_CLASS_CCID_COMMAND_SETT;
934 
935 
936 /* Define CCID slot structure.  */
937 typedef struct UX_DEVICE_CLASS_CCID_SLOT_STRUCT
938 {
939     CHAR                    ux_device_class_ccid_slot_runner;
940     UCHAR                   ux_device_class_ccid_slot_flags;
941 
942     UCHAR                   ux_device_class_ccid_slot_icc_status;
943     UCHAR                   ux_device_class_ccid_slot_clock_status;
944 
945     UCHAR                   ux_device_class_ccid_slot_hw_error;
946     UCHAR                   ux_device_class_ccid_slot_hw_error_seq;
947 
948     UCHAR                   ux_device_class_ccid_slot_aborting_seq;
949     UCHAR                   ux_device_class_ccid_slot_aborting;
950 } UX_DEVICE_CLASS_CCID_SLOT;
951 
952 /* Define CCID runner structure.  */
953 typedef struct UX_DEVICE_CLASS_CCID_RUNNER_STRUCT
954 {
955     struct UX_DEVICE_CLASS_CCID_STRUCT
956                             *ux_device_class_ccid_runner_ccid;
957     UCHAR                   *ux_device_class_ccid_runner_command;
958     UCHAR                   *ux_device_class_ccid_runner_response;
959 
960     CHAR                    ux_device_class_ccid_runner_slot;
961     CHAR                    ux_device_class_ccid_runner_id;
962     CHAR                    ux_device_class_ccid_runner_command_index;
963 #if !defined(UX_DEVICE_STANDALONE)
964     UCHAR                   reserved;
965 
966     UX_THREAD               ux_device_class_ccid_runner_thread;
967     UCHAR                   *ux_device_class_ccid_runner_thread_stack;
968 #else
969     UCHAR                   ux_device_class_ccid_runner_state;
970 
971     UX_DEVICE_CLASS_CCID_HANDLE
972                             ux_device_class_ccid_runner_handle;
973     UX_DEVICE_CLASS_CCID_MESSAGES
974                             ux_device_class_ccid_runner_messages;
975 #endif
976 } UX_DEVICE_CLASS_CCID_RUNNER;
977 
978 /* Define Device CCID Class Calling Parameter structure */
979 typedef struct UX_DEVICE_CLASS_CCID_PARAMETER_STRUCT
980 {
981     VOID                    (*ux_device_class_ccid_instance_activate)(VOID *);
982     VOID                    (*ux_device_class_ccid_instance_deactivate)(VOID *);
983     UX_DEVICE_CLASS_CCID_HANDLES
984                             *ux_device_class_ccid_handles;
985     ULONG                   *ux_device_class_ccid_clocks;
986     ULONG                   *ux_device_class_ccid_data_rates;
987     ULONG                   ux_device_class_ccid_max_transfer_length;
988     UCHAR                   ux_device_class_ccid_max_n_slots;
989     UCHAR                   ux_device_class_ccid_max_n_busy_slots;
990     UCHAR                   ux_device_class_ccid_n_clocks;
991     UCHAR                   ux_device_class_ccid_n_data_rates;
992 } UX_DEVICE_CLASS_CCID_PARAMETER;
993 
994 
995 /* Define CCID Class structure.  */
996 
997 typedef struct UX_DEVICE_CLASS_CCID_STRUCT
998 {
999     UX_SLAVE_INTERFACE      *ux_device_class_ccid_interface;
1000     UX_SLAVE_ENDPOINT       *ux_device_class_ccid_endpoint_out;
1001     UX_SLAVE_ENDPOINT       *ux_device_class_ccid_endpoint_in;
1002     UX_SLAVE_ENDPOINT       *ux_device_class_ccid_endpoint_notify;
1003 
1004     UX_DEVICE_CLASS_CCID_PARAMETER
1005                             ux_device_class_ccid_parameter;
1006 
1007     UX_DEVICE_CLASS_CCID_RUNNER
1008                             *ux_device_class_ccid_runners;
1009     UX_DEVICE_CLASS_CCID_SLOT
1010                             *ux_device_class_ccid_slots;
1011 
1012     UCHAR                   ux_device_class_ccid_header[UX_DEVICE_CLASS_CCID_MESSAGE_HEADER_LENGTH];
1013     SHORT                   ux_device_class_ccid_n_busy;
1014 
1015 #if !defined(UX_DEVICE_STANDALONE)
1016     UX_THREAD               ux_device_class_ccid_thread;
1017     UCHAR                   *ux_device_class_ccid_thread_stack;
1018 
1019     UX_THREAD               ux_device_class_ccid_notify_thread;
1020     UCHAR                   *ux_device_class_ccid_notify_thread_stack;
1021 
1022     UX_EVENT_FLAGS_GROUP    ux_device_class_ccid_events;
1023     UX_MUTEX                ux_device_class_ccid_mutex;
1024     UX_MUTEX                ux_device_class_ccid_response_mutex;
1025     UX_SEMAPHORE            ux_device_class_ccid_notify_semaphore;
1026 #else
1027     ULONG                   ux_device_class_ccid_flags;
1028 
1029     UCHAR                   ux_device_class_ccid_cmd_state;
1030     CHAR                    ux_device_class_ccid_cmd_index;
1031     UCHAR                   ux_device_class_ccid_rsp_state;
1032     UCHAR                   ux_device_class_ccid_notify_state;
1033 #endif
1034 } UX_DEVICE_CLASS_CCID;
1035 
1036 /* Device CCID flags.  */
1037 #define UX_DEVICE_CLASS_CCID_FLAG_LOCK          0x0001u
1038 #define UX_DEVICE_CLASS_CCID_FLAG_CMD_RSP       0x0010u
1039 
1040 #if defined(UX_DEVICE_STANDALONE)
1041 #define _ux_device_class_ccid_lock(ccid)    do {                                \
1042         UX_INTERRUPT_SAVE_AREA                                                  \
1043         UX_DISABLE                                                              \
1044         if (ccid->ux_device_class_ccid_flags & UX_DEVICE_CLASS_CCID_FLAG_LOCK)  \
1045         {                                                                       \
1046             UX_RESTORE                                                          \
1047             return(UX_BUSY);                                                    \
1048         }                                                                       \
1049         ccid->ux_device_class_ccid_flags |= UX_DEVICE_CLASS_CCID_FLAG_LOCK;     \
1050         UX_RESTORE                                                              \
1051     } while(0)
1052 #define _ux_device_class_ccid_unlock(ccid)  do {                                \
1053         ccid->ux_device_class_ccid_flags &= ~UX_DEVICE_CLASS_CCID_FLAG_LOCK;    \
1054     } while(0)
1055 #else
1056 #define _ux_device_class_ccid_lock(ccid)    _ux_device_mutex_on(&ccid -> ux_device_class_ccid_mutex)
1057 #define _ux_device_class_ccid_unlock(ccid)  _ux_device_mutex_off(&ccid -> ux_device_class_ccid_mutex)
1058 #endif
1059 
1060 /* Device CCID states.  */
1061 #define UX_DEVICE_CLASS_CCID_CMD_IDLE                               (UX_STATE_STEP + 0)
1062 #define UX_DEVICE_CLASS_CCID_CMD_START                              (UX_STATE_STEP + 1)
1063 #define UX_DEVICE_CLASS_CCID_CMD_WAIT                               (UX_STATE_STEP + 2)
1064 #define UX_DEVICE_CLASS_CCID_CMD_LOCK                               (UX_STATE_STEP + 3)
1065 #define UX_DEVICE_CLASS_CCID_CMD_PROCESS                            (UX_STATE_STEP + 4)
1066 #define UX_DEVICE_CLASS_CCID_CMD_RSP_START                          (UX_STATE_STEP + 5)
ccidCmdStateName(const UINT s)1067 static inline const char *ccidCmdStateName(const UINT s)
1068 {
1069     switch(s)
1070     {
1071     case UX_DEVICE_CLASS_CCID_CMD_IDLE:     return("cmdIDLE");
1072     case UX_DEVICE_CLASS_CCID_CMD_START:    return("cmdSTART");
1073     case UX_DEVICE_CLASS_CCID_CMD_WAIT:     return("cmdWAIT");
1074     case UX_DEVICE_CLASS_CCID_CMD_LOCK:     return("cmdLOCK");
1075     case UX_DEVICE_CLASS_CCID_CMD_PROCESS:  return("cmdPROCESS");
1076     case UX_DEVICE_CLASS_CCID_CMD_RSP_START:return("cmdRSP_START");
1077     default: return("cmd?");
1078     }
1079 }
1080 
1081 #define UX_DEVICE_CLASS_CCID_RUNNER_IDLE                            (UX_STATE_STEP + 0)
1082 #define UX_DEVICE_CLASS_CCID_RUNNER_START                           (UX_STATE_STEP + 1)
1083 #define UX_DEVICE_CLASS_CCID_RUNNER_HANDLE                          (UX_STATE_STEP + 2)
1084 #define UX_DEVICE_CLASS_CCID_RUNNER_RSP_START                       (UX_STATE_STEP + 3)
ccidRunnerStateName(const UINT s)1085 static inline const char *ccidRunnerStateName(const UINT s)
1086 {
1087     switch(s)
1088     {
1089     case UX_DEVICE_CLASS_CCID_RUNNER_IDLE:          return("runnerIDLE");
1090     case UX_DEVICE_CLASS_CCID_RUNNER_START:         return("runnerSTART");
1091     case UX_DEVICE_CLASS_CCID_RUNNER_HANDLE:        return("runnerHANDLE");
1092     case UX_DEVICE_CLASS_CCID_RUNNER_RSP_START:     return("runnerRSP_START");
1093     default: return("runner?");
1094     }
1095 }
1096 
1097 #define UX_DEVICE_CLASS_CCID_RSP_IDLE                               (UX_STATE_STEP + 0)
1098 #define UX_DEVICE_CLASS_CCID_RSP_START                              (UX_STATE_STEP + 1)
1099 #define UX_DEVICE_CLASS_CCID_RSP_WAIT                               (UX_STATE_STEP + 2)
1100 #define UX_DEVICE_CLASS_CCID_RSP_LOCK                               (UX_STATE_STEP + 3)
1101 #define UX_DEVICE_CLASS_CCID_RSP_UPDATE                             (UX_STATE_STEP + 4)
1102 #define UX_DEVICE_CLASS_CCID_RSP_DONE                               (UX_STATE_STEP + 5)
ccidRspStateName(const UINT s)1103 static inline const char *ccidRspStateName(const UINT s)
1104 {
1105     switch(s)
1106     {
1107     case UX_DEVICE_CLASS_CCID_RSP_IDLE:     return("rspIDLE");
1108     case UX_DEVICE_CLASS_CCID_RSP_START:    return("rspSTART");
1109     case UX_DEVICE_CLASS_CCID_RSP_WAIT:     return("rspWAIT");
1110     case UX_DEVICE_CLASS_CCID_RSP_LOCK:     return("rspLOCK");
1111     case UX_DEVICE_CLASS_CCID_RSP_UPDATE:   return("rspUPDATE");
1112     case UX_DEVICE_CLASS_CCID_RSP_DONE:     return("rspDONE");
1113     default: return("rsp?");
1114     }
1115 }
1116 
1117 #define UX_DEVICE_CLASS_CCID_NOTIFY_IDLE                            (UX_STATE_STEP + 0)
1118 #define UX_DEVICE_CLASS_CCID_NOTIFY_LOCK                            (UX_STATE_STEP + 1)
1119 #define UX_DEVICE_CLASS_CCID_NOTIFY_START                           (UX_STATE_STEP + 2)
1120 #define UX_DEVICE_CLASS_CCID_NOTIFY_WAIT                            (UX_STATE_STEP + 3)
ccidNotifyStateName(const UINT s)1121 static inline const char *ccidNotifyStateName(const UINT s)
1122 {
1123     switch(s)
1124     {
1125     case UX_DEVICE_CLASS_CCID_NOTIFY_IDLE:     return("notifyIDLE");
1126     case UX_DEVICE_CLASS_CCID_NOTIFY_LOCK:     return("notifyLOCK");
1127     case UX_DEVICE_CLASS_CCID_NOTIFY_START:    return("notifySTART");
1128     case UX_DEVICE_CLASS_CCID_NOTIFY_WAIT:     return("notifyWAIT");
1129     default: return("notify?");
1130     }
1131 }
1132 
1133 /* Define Device CCID command settings.  */
1134 extern const UX_DEVICE_CLASS_CCID_COMMAND_SETT _ux_device_class_ccid_command_sett[];
1135 
1136 /* Define Device CCID Class prototypes.  */
1137 UINT  _ux_device_class_ccid_initialize(UX_SLAVE_CLASS_COMMAND *command);
1138 UINT  _ux_device_class_ccid_uninitialize(UX_SLAVE_CLASS_COMMAND *command);
1139 UINT  _ux_device_class_ccid_activate(UX_SLAVE_CLASS_COMMAND *command);
1140 UINT  _ux_device_class_ccid_deactivate(UX_SLAVE_CLASS_COMMAND *command);
1141 UINT  _ux_device_class_ccid_control_request(UX_SLAVE_CLASS_COMMAND *command);
1142 
1143 VOID  _ux_device_class_ccid_thread_entry(ULONG ccid_instance);
1144 VOID  _ux_device_class_ccid_notify_thread_entry(ULONG ccid_instance);
1145 VOID  _ux_device_class_ccid_runner_thread_entry(ULONG runner_instance);
1146 
1147 UINT  _ux_device_class_ccid_tasks_run(VOID *instance);
1148 UINT  _ux_device_class_ccid_notify_task_run(UX_DEVICE_CLASS_CCID *ccid);
1149 UINT  _ux_device_class_ccid_runner_task_run(UX_DEVICE_CLASS_CCID *ccid);
1150 
1151 UINT  _ux_device_class_ccid_control_abort(UX_DEVICE_CLASS_CCID *ccid, ULONG slot, ULONG seq);
1152 
1153 UINT  _ux_device_class_ccid_response(UX_DEVICE_CLASS_CCID *ccid, UCHAR *buffer, ULONG length);
1154 
1155 UINT  _ux_device_class_ccid_entry(UX_SLAVE_CLASS_COMMAND *command);
1156 
1157 UINT  _ux_device_class_ccid_icc_insert(UX_DEVICE_CLASS_CCID *ccid, ULONG slot, ULONG seq_start);
1158 UINT  _ux_device_class_ccid_icc_remove(UX_DEVICE_CLASS_CCID *ccid, ULONG slot);
1159 UINT  _ux_device_class_ccid_auto_seq_start(UX_DEVICE_CLASS_CCID *ccid, ULONG slot);
1160 UINT  _ux_device_class_ccid_auto_seq_done(UX_DEVICE_CLASS_CCID *ccid, ULONG slot, ULONG icc_status);
1161 UINT  _ux_device_class_ccid_time_extension(UX_DEVICE_CLASS_CCID *ccid, ULONG slot, ULONG wt);
1162 UINT  _ux_device_class_ccid_hardware_error(UX_DEVICE_CLASS_CCID *ccid, ULONG slot, ULONG error);
1163 
1164 /* Define Device CCID Class API prototypes.  */
1165 
1166 #define ux_device_class_ccid_entry               _ux_device_class_ccid_entry
1167 
1168 #define ux_device_class_ccid_icc_insert          _ux_device_class_ccid_icc_insert
1169 #define ux_device_class_ccid_icc_remove          _ux_device_class_ccid_icc_remove
1170 #define ux_device_class_ccid_auto_seq_done       _ux_device_class_ccid_auto_seq_done
1171 #define ux_device_class_ccid_time_extension      _ux_device_class_ccid_time_extension
1172 #define ux_device_class_ccid_hardware_error      _ux_device_class_ccid_hardware_error
1173 
1174 
1175 /* Determine if a C++ compiler is being used.  If so, complete the standard
1176    C conditional started above.  */
1177 #ifdef __cplusplus
1178 }
1179 #endif
1180 
1181 #endif /* UX_DEVICE_CLASS_CCID_H */
1182