1 /* This test is designed to test the ux_utility_descriptor_pack.  */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8 
9 #include "ux_host_stack.h"
10 #include "ux_device_stack.h"
11 
12 #include "ux_device_class_ccid.h"
13 
14 #include "ux_test.h"
15 
16 /* Define USBX test constants.  */
17 
18 #define UX_TEST_STACK_SIZE      4096
19 #define UX_TEST_BUFFER_SIZE     2048
20 #define UX_TEST_MEMORY_SIZE     (64*1024)
21 
22 
23 /* Define the counters used in the test application...  */
24 
25 static ULONG                           error_counter = 0;
26 
27 /* Define USBX test global variables.  */
28 
29 
30 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
31 
32 static TX_THREAD           ux_test_thread_simulation_0;
33 static void                ux_test_thread_simulation_0_entry(ULONG);
34 
35 
36 /* Prototype for test control return.  */
37 
38 void  test_control_return(UINT status);
39 
40 #if 0
41 static UINT  ux_test_ccid_icc_power_on(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
42 static UINT  ux_test_ccid_icc_power_off(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
43 static UINT  ux_test_ccid_get_slot_status(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
44 static UINT  ux_test_ccid_xfr_block(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
45 static UINT  ux_test_ccid_get_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
46 static UINT  ux_test_ccid_reset_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
47 static UINT  ux_test_ccid_set_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
48 static UINT  ux_test_ccid_escape(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
49 static UINT  ux_test_ccid_icc_clock(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
50 static UINT  ux_test_ccid_t0_apdu(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
51 static UINT  ux_test_ccid_secure(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
52 static UINT  ux_test_ccid_mechanical(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
53 static UINT  ux_test_ccid_abort(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
54 static UINT  ux_test_ccid_set_data_rate_and_clock_frequency(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg);
55 
56 static UX_DEVICE_CLASS_CCID_HANDLES device_ccid_handles =
57 {
58     ux_test_ccid_icc_power_on,
59     ux_test_ccid_icc_power_off,
60     ux_test_ccid_get_slot_status,
61     ux_test_ccid_xfr_block,
62     ux_test_ccid_get_parameters,
63     ux_test_ccid_reset_parameters,
64     ux_test_ccid_set_parameters,
65     ux_test_ccid_escape,
66     ux_test_ccid_icc_clock,
67     ux_test_ccid_t0_apdu,
68     ux_test_ccid_secure,
69     ux_test_ccid_mechanical,
70     ux_test_ccid_abort,
71     ux_test_ccid_set_data_rate_and_clock_frequency,
72 };
73 
74 static UINT ux_test_ccid_icc_power_on(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
75 {
76     return UX_SUCCESS;
77 }
78 
79 static UINT  ux_test_ccid_icc_power_off(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
80 {
81     return UX_SUCCESS;
82 }
83 
84 static UINT  ux_test_ccid_get_slot_status(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
85 {
86     return UX_SUCCESS;
87 }
88 
89 static UINT  ux_test_ccid_xfr_block(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
90 {
91     return UX_SUCCESS;
92 }
93 
94 static UINT  ux_test_ccid_get_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
95 {
96     return UX_SUCCESS;
97 }
98 
99 static UINT  ux_test_ccid_reset_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
100 {
101     return UX_SUCCESS;
102 }
103 
104 static UINT  ux_test_ccid_set_parameters(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
105 {
106     return UX_SUCCESS;
107 }
108 
109 static UINT  ux_test_ccid_escape(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
110 {
111     return UX_SUCCESS;
112 }
113 
114 static UINT  ux_test_ccid_icc_clock(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
115 {
116     return UX_SUCCESS;
117 }
118 
119 static UINT  ux_test_ccid_t0_apdu(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
120 {
121     return UX_SUCCESS;
122 }
123 
124 static UINT  ux_test_ccid_secure(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
125 {
126     return UX_SUCCESS;
127 }
128 
129 static UINT  ux_test_ccid_mechanical(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
130 {
131     return UX_SUCCESS;
132 }
133 
134 static UINT  ux_test_ccid_abort(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
135 {
136     return UX_SUCCESS;
137 }
138 
139 static UINT  ux_test_ccid_set_data_rate_and_clock_frequency(ULONG slot, UX_DEVICE_CLASS_CCID_MESSAGES*io_msg)
140 {
141     return UX_SUCCESS;
142 }
143 
144 #endif
145 
146 /* Define what the initial system looks like.  */
147 
148 #ifdef CTEST
test_application_define(void * first_unused_memory)149 void test_application_define(void *first_unused_memory)
150 #else
151 void usbx_uxe_device_ccid_test_application_define(void *first_unused_memory)
152 #endif
153 {
154 
155 UINT status;
156 CHAR                            *stack_pointer;
157 CHAR                            *memory_pointer;
158 
159     /* Inform user.  */
160     printf("Running uxe_device_printer APIs Test.................................. ");
161 #if !defined(UX_DEVICE_CLASS_CCID_ENABLE_ERROR_CHECKING)
162 #warning Tests skipped due to compile option!
163     printf("SKIP SUCCESS!\n");
164     test_control_return(0);
165     return;
166 #endif
167 
168     /* Initialize the free memory pointer.  */
169     stack_pointer = (CHAR *) first_unused_memory;
170     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
171 
172     /* Initialize USBX Memory.  */
173     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
174 
175     /* Check for error.  */
176     if (status != UX_SUCCESS)
177     {
178 
179         printf("ERROR #%d\n", __LINE__);
180         test_control_return(1);
181     }
182 
183     /* Create the simulation thread.  */
184     status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
185             stack_pointer, UX_TEST_STACK_SIZE,
186             20, 20, 1, TX_AUTO_START);
187 
188     /* Check for error.  */
189     if (status != TX_SUCCESS)
190     {
191 
192         printf("ERROR #%d\n", __LINE__);
193         test_control_return(1);
194     }
195 }
196 
197 
ux_test_thread_simulation_0_entry(ULONG arg)198 static void  ux_test_thread_simulation_0_entry(ULONG arg)
199 {
200 UINT                                    status;
201 UX_DEVICE_CLASS_CCID                    dummy_ccid_inst;
202 UX_DEVICE_CLASS_CCID                    *dummy_ccid = &dummy_ccid_inst;
203 UCHAR                                   dummy_buffer[32];
204 ULONG                                   dummy_actual_length;
205 
206 UX_DEVICE_CLASS_CCID_PARAMETER          device_ccid_parameter;
207 
208 
209     status = ux_device_class_ccid_icc_insert(UX_NULL, 0, 0);
210     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
211 
212     status = ux_device_class_ccid_icc_remove(UX_NULL, 0);
213     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
214 
215     status = ux_device_class_ccid_auto_seq_done(UX_NULL, 0, 0);
216     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
217 
218     status = ux_device_class_ccid_time_extension(UX_NULL, 0, 0);
219     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
220 
221     status = ux_device_class_ccid_time_extension(UX_NULL, UX_DEVICE_CLASS_CCID_MAX_N_SLOTS, 0);
222     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
223 
224     status = _uxe_device_class_ccid_hardware_error(UX_NULL, 0,  1);
225     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
226 
227     /* Sleep for a tick to make sure everything is complete.  */
228     tx_thread_sleep(1);
229 
230     /* Check for errors from other threads.  */
231     if (error_counter)
232     {
233 
234         /* Test error.  */
235         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
236         test_control_return(1);
237     }
238     else
239     {
240 
241         /* Successful test.  */
242         printf("SUCCESS!\n");
243         test_control_return(0);
244     }
245 }
246