1 /* This test is designed to test the ux_device_stack_control_request_process.  */
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_cdc_acm.h"
13 #include "ux_host_class_cdc_acm.h"
14 
15 #include "ux_host_class_dpump.h"
16 #include "ux_device_class_dpump.h"
17 
18 #include "ux_host_class_hid.h"
19 #include "ux_device_class_hid.h"
20 
21 #include "ux_host_class_storage.h"
22 #include "ux_device_class_storage.h"
23 
24 #include "ux_test_dcd_sim_slave.h"
25 #include "ux_test_hcd_sim_host.h"
26 #include "ux_test_utility_sim.h"
27 
28 
29 /* Define USBX test constants.  */
30 
31 #define UX_TEST_STACK_SIZE      4096
32 #define UX_TEST_BUFFER_SIZE     2048
33 #define UX_TEST_RUN             1
34 #define UX_TEST_MEMORY_SIZE     (64*1024)
35 
36 /* HID mouse related descriptors */
37 
38 static UCHAR hid_mouse_report[] = {
39 
40     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
41     0x09, 0x02,                    // USAGE (Mouse)
42     0xa1, 0x01,                    // COLLECTION (Application)
43     0x09, 0x01,                    //   USAGE (Pointer)
44     0xa1, 0x00,                    //   COLLECTION (Physical)
45     0x05, 0x09,                    //     USAGE_PAGE (Button)
46     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
47     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
48     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
49     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
50     0x95, 0x03,                    //     REPORT_COUNT (3)
51     0x75, 0x01,                    //     REPORT_SIZE (1)
52     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
53     0x95, 0x01,                    //     REPORT_COUNT (1)
54     0x75, 0x05,                    //     REPORT_SIZE (5)
55     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
56     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
57     0x09, 0x30,                    //     USAGE (X)
58     0x09, 0x31,                    //     USAGE (Y)
59     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
60     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
61     0x75, 0x08,                    //     REPORT_SIZE (8)
62     0x95, 0x02,                    //     REPORT_COUNT (2)
63     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
64     0x09, 0x38,                    //     USAGE (Mouse Wheel)
65     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
66     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
67     0x75, 0x08,                    //     REPORT_SIZE (8)
68     0x95, 0x01,                    //     REPORT_COUNT (1)
69     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
70     0xc0,                          //   END_COLLECTION
71     0xc0                           // END_COLLECTION
72 };
73 #define HID_MOUSE_REPORT_LENGTH (sizeof(hid_mouse_report)/sizeof(hid_mouse_report[0]))
74 
75 #define     LSB(x) (x & 0x00ff)
76 #define     MSB(x) ((x & 0xff00) >> 8)
77 
78 /* Configuration descriptor 9 bytes */
79 #define CFG_DESC(wTotalLength, bNumInterfaces, bConfigurationValue)\
80     /* Configuration 1 descriptor 9 bytes */\
81     0x09, 0x02, LSB(wTotalLength), MSB(wTotalLength),\
82     (bNumInterfaces), (bConfigurationValue), 0x00,\
83     0x20, 0x00,
84 #define CFG_DESC_LEN 9
85 
86 /* DPUMP interface descriptors 9+7+7=23 bytes. */
87 #define DPUMP_IFC_DESC_ALL(ifc, bulk_in_epa, bulk_out_epa) \
88     /* Interface descriptor */\
89     0x09, 0x04, (ifc), 0x00, 0x02, 0x99, 0x99, 0x99, 0x00,\
90     /* Endpoint descriptor (Bulk Out) */\
91     0x07, 0x05, (bulk_out_epa), 0x02, 0x40, 0x00, 0x00,\
92     /* Endpoint descriptor (Bulk In) */\
93     0x07, 0x05, (bulk_in_epa), 0x02, 0x40, 0x00, 0x00,
94 #define DPUMP_IFC_DESC_ALL_LEN 23
95 
96 /* HID Mouse interface descriptors 9+9=18 bytes */
97 #define HID_MOUSE_IFC0_DESC_ALL(ifc)     \
98     /* Interface descriptor */\
99     0x09, 0x04, (ifc), 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,\
100     /* HID descriptor */\
101     0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
102     MSB(HID_MOUSE_REPORT_LENGTH),
103 #define HID_MOUSE_IFC0_DESC_ALL_LEN 18
104 
105 /* HID Mouse interface descriptors 9+9+7=25 bytes */
106 #define HID_MOUSE_IFC1_DESC_ALL(ifc, interrupt_epa)     \
107     /* Interface descriptor */\
108     0x09, 0x04, (ifc), 0x01, 0x01, 0x03, 0x00, 0x00, 0x00,\
109     /* HID descriptor */\
110     0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
111     MSB(HID_MOUSE_REPORT_LENGTH),\
112     /* Endpoint descriptor (Interrupt) */\
113     0x07, 0x05, (interrupt_epa), 0x03, 0x08, 0x00, 0x08,
114 #define HID_MOUSE_IFC1_DESC_ALL_LEN 25
115 
116 /* CDC-ACM interfaces descriptors 8 +9+5+4+5+5+7 +9+7+7=66 bytes */
117 #define CDC_ACM_IFCES_DESC_ALL(ifc, interrupt_epa, bulk_in_epa, bulk_out_epa) \
118     /* Interface association descriptor. 8 bytes.  */\
119     0x08, 0x0b, (ifc), 0x02, 0x02, 0x02, 0x00, 0x00,\
120     /* Communication Class Interface Descriptor Requirement. 9 bytes.   */\
121     0x09, 0x04, (ifc), 0x00, 0x01, 0x02, 0x02, 0x01, 0x00,\
122     /* Header Functional Descriptor 5 bytes */\
123     0x05, 0x24, 0x00, 0x10, 0x01,\
124     /* ACM Functional Descriptor 4 bytes */\
125     0x04, 0x24, 0x02, 0x0f,\
126     /* Union Functional Descriptor 5 bytes */\
127     0x05, 0x24, 0x06,\
128     (ifc),                        /* Master interface */\
129     (ifc+1),                      /* Slave interface  */\
130     /* Call Management Functional Descriptor 5 bytes */\
131     0x05, 0x24, 0x01, 0x03,\
132     (ifc+1),                      /* Data interface   */\
133     /* Interrupt endpoint descriptor 7 bytes */\
134     0x07, 0x05, (interrupt_epa), 0x03, 0x08, 0x00, 15,\
135     /* Data Class Interface Descriptor Requirement 9 bytes */\
136     0x09, 0x04, (ifc+1), 0x00, 0x02, 0x0A, 0x00, 0x00, 0x00,\
137     /* Endpoint descriptor 7 bytes */\
138     0x07, 0x05, (bulk_out_epa), 0x02, 0x40, 0x00, 0x00,\
139     /* Endpoint descriptor 7 bytes */\
140     0x07, 0x05, (bulk_in_epa), 0x02, 0x40, 0x00, 0x00,
141 #define CDC_ACM_IFCES_DESC_ALL_LEN 66
142 
143 /* Define the counters used in the test application...  */
144 
145 static ULONG                           thread_0_counter;
146 static ULONG                           thread_1_counter;
147 static ULONG                           error_counter;
148 
149 static UCHAR                           expect_errors = UX_FALSE;
150 
151 static UCHAR                           buffer[UX_TEST_BUFFER_SIZE];
152 
153 /* Define USBX test global variables.  */
154 
155 static UX_HOST_CLASS                   *class_driver;
156 static UX_HOST_CLASS_DPUMP             *dpump;
157 static UX_SLAVE_CLASS_DPUMP            *dpump_slave = UX_NULL;
158 
159 
160 static UCHAR device_framework_full_speed[] = {
161 
162     /* Device descriptor 18 bytes */
163     0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
164     0xec, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
165     0x00, 0x01,
166 
167     /* Configuration descriptor 9 bytes */
168     CFG_DESC(CFG_DESC_LEN + DPUMP_IFC_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN + CDC_ACM_IFCES_DESC_ALL_LEN, 2, 1)
169     /* DPUMP 9+9+7      =25 */
170     DPUMP_IFC_DESC_ALL(0, 0x81, 0x02)
171     /* HID   9+9 + 9+9+7=43 */
172     HID_MOUSE_IFC0_DESC_ALL(1)
173     HID_MOUSE_IFC1_DESC_ALL(1, 0x83)
174     /* CDC-ACM */
175     CDC_ACM_IFCES_DESC_ALL(2, 0x86, 0x85, 0x04)
176 };
177 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
178 
179 static UCHAR device_framework_high_speed[] = {
180 
181     /* Device descriptor */
182     0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
183     0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
184     0x03, 0x01,
185 
186     /* Device qualifier descriptor */
187     0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
188     0x01, 0x00,
189 
190     /* Configuration descriptor 9 bytes */
191     CFG_DESC(CFG_DESC_LEN + DPUMP_IFC_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN + CDC_ACM_IFCES_DESC_ALL_LEN, 2, 1)
192     /* DPUMP 9+9+7      =25 */
193     DPUMP_IFC_DESC_ALL(0, 0x81, 0x02)
194     /* HID   9+9 + 9+9+7=43 */
195     HID_MOUSE_IFC0_DESC_ALL(1)
196     HID_MOUSE_IFC1_DESC_ALL(1, 0x83)
197     /* CDC-ACM */
198     CDC_ACM_IFCES_DESC_ALL(2, 0x86, 0x85, 0x04)
199 };
200 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
201 
202 /* String Device Framework :
203     Byte 0 and 1 : Word containing the language ID : 0x0904 for US
204     Byte 2       : Byte containing the index of the descriptor
205     Byte 3       : Byte containing the length of the descriptor string
206 */
207 
208 static UCHAR string_framework[] = {
209 
210     /* Manufacturer string descriptor : Index 1 */
211     0x09, 0x04, 0x01, 0x0c,
212     0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
213     0x6f, 0x67, 0x69, 0x63,
214 
215     /* Product string descriptor : Index 2 */
216     0x09, 0x04, 0x02, 0x0c,
217     0x44, 0x61, 0x74, 0x61, 0x50, 0x75, 0x6d, 0x70,
218     0x44, 0x65, 0x6d, 0x6f,
219 
220     /* Serial Number string descriptor : Index 3 */
221     0x09, 0x04, 0x03, 0x04,
222     0x30, 0x30, 0x30, 0x31
223 };
224 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
225 
226     /* Multiple languages are supported on the device, to add
227        a language besides English, the unicode language code must
228        be appended to the language_id_framework array and the length
229        adjusted accordingly. */
230 static UCHAR language_id_framework[] = {
231 
232 /* English. */
233     0x09, 0x04
234 };
235 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
236 
237 /* Simulation actions. */
238 
239 static UX_TEST_SIM_ENTRY_ACTION dcd_endpoint_create_fail[] = {
240 /* function, request to match,
241    port action, port status,
242    request action, request EP, request data, request actual length, request status,
243    status, additional callback,
244    no_return */
245 {   UX_DCD_CREATE_ENDPOINT, NULL,
246         UX_FALSE, 0,
247         0         , 0, UX_NULL, 0, 0,
248         UX_ERROR , UX_NULL},
249 {   0   }
250 };
251 
252 
253 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
254 
255 static VOID                ux_test_instance_activate(VOID  *dpump_instance);
256 static VOID                ux_test_instance_deactivate(VOID *dpump_instance);
257 
258 UINT                       _ux_host_class_dpump_entry(UX_HOST_CLASS_COMMAND *command);
259 UINT                       ux_hcd_sim_initialize(UX_HCD *hcd);
260 UINT                       _ux_host_class_dpump_write(UX_HOST_CLASS_DPUMP *dpump, UCHAR * data_pointer,
261                                     ULONG requested_length, ULONG *actual_length);
262 UINT                       _ux_host_class_dpump_read (UX_HOST_CLASS_DPUMP *dpump, UCHAR *data_pointer,
263                                     ULONG requested_length, ULONG *actual_length);
264 
265 static TX_THREAD           ux_test_thread_simulation_0;
266 static TX_THREAD           ux_test_thread_simulation_1;
267 static void                ux_test_thread_simulation_0_entry(ULONG);
268 static void                ux_test_thread_simulation_1_entry(ULONG);
269 
270 
271 /* Define the ISR dispatch.  */
272 
273 extern VOID    (*test_isr_dispatch)(void);
274 
275 
276 /* Prototype for test control return.  */
277 
278 void  test_control_return(UINT status);
279 
280 
281 /* Define the ISR dispatch routine.  */
282 
test_isr(void)283 static void    test_isr(void)
284 {
285 
286     /* For further expansion of interrupt-level testing.  */
287 }
288 
289 
error_callback(UINT system_level,UINT system_context,UINT error_code)290 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
291 {
292     if (!expect_errors)
293     {
294         if (error_code != UX_DEVICE_HANDLE_UNKNOWN)
295         {
296             /* Failed test.  */
297             printf("Error on line %d, system_level: %d, system_context: %d, error code: %x\n", __LINE__, system_level, system_context, error_code);
298             test_control_return(1);
299         }
300     }
301 }
302 
test_ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND * command)303 static UINT test_ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND *command)
304 {
305     return UX_SUCCESS;
306     // return _ux_device_class_hid_entry(command);
307 }
308 
309 /* Define what the initial system looks like.  */
310 
311 #ifdef CTEST
test_application_define(void * first_unused_memory)312 void test_application_define(void *first_unused_memory)
313 #else
314 void    usbx_ux_device_stack_control_request_process_test_application_define(void *first_unused_memory)
315 #endif
316 {
317 
318 UINT status;
319 CHAR                            *stack_pointer;
320 CHAR                            *memory_pointer;
321 UX_SLAVE_CLASS_DPUMP_PARAMETER  parameter;
322 UX_SLAVE_CLASS_HID_PARAMETER    hid_parameter;
323 
324     /* Initialize the free memory pointer.  */
325     stack_pointer = (CHAR *) first_unused_memory;
326     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
327 
328     /* Initialize USBX Memory.  */
329     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
330 
331     /* Check for error.  */
332     if (status != UX_SUCCESS)
333     {
334 
335         printf("Running ux_device_stack_control_request_process Test................ ERROR #1\n");
336         test_control_return(1);
337     }
338 
339     /* Register the error callback. */
340     _ux_utility_error_callback_register(error_callback);
341 
342     /* The code below is required for installing the host portion of USBX.  */
343     status =  ux_host_stack_initialize(UX_NULL);
344 
345     /* Check for error.  */
346     if (status != UX_SUCCESS)
347     {
348 
349         printf("Running ux_device_stack_control_request_process Test................ ERROR #2\n");
350         test_control_return(1);
351     }
352 
353     /* Register all the host class drivers for this USBX implementation.  */
354     status =  ux_host_stack_class_register(_ux_system_host_class_dpump_name, ux_host_class_dpump_entry);
355 
356     /* Check for error.  */
357     if (status != UX_SUCCESS)
358     {
359 
360         printf("Running ux_device_stack_control_request_process Test................ ERROR #3\n");
361         test_control_return(1);
362     }
363 
364     /* The code below is required for installing the device portion of USBX */
365     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
366                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
367                                        string_framework, STRING_FRAMEWORK_LENGTH,
368                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, UX_NULL);
369 
370     /* Check for error.  */
371     if (status != UX_SUCCESS)
372     {
373 
374         printf("Running ux_device_stack_control_request_process Test................ ERROR #5\n");
375         test_control_return(1);
376     }
377 
378     /* Set the parameters for callback when insertion/extraction of a Data Pump device.  */
379     parameter.ux_slave_class_dpump_instance_activate   =  ux_test_instance_activate;
380     parameter.ux_slave_class_dpump_instance_deactivate =  ux_test_instance_deactivate;
381 
382     /* Initialize the device dpump class. The class is connected with interface 0 */
383     status =  ux_device_stack_class_register(_ux_system_slave_class_dpump_name, _ux_device_class_dpump_entry,
384                                               1, 0, &parameter);
385 
386     /* Initialize the hid class parameters.  */
387     hid_parameter.ux_device_class_hid_parameter_report_address = hid_mouse_report;
388     hid_parameter.ux_device_class_hid_parameter_report_length  = HID_MOUSE_REPORT_LENGTH;
389     hid_parameter.ux_device_class_hid_parameter_callback       = UX_NULL;
390     hid_parameter.ux_slave_class_hid_instance_activate         = UX_NULL;
391 
392     status |= ux_device_stack_class_register(_ux_system_slave_class_hid_name, test_ux_device_class_hid_entry,
393                                               1, 1, &parameter);
394 #if UX_MAX_SLAVE_CLASS_DRIVER > 1
395     /* Check for error.  */
396     if (status != UX_SUCCESS)
397     {
398 
399         printf("Running ux_device_stack_control_request_process Test................ ERROR #6\n");
400         test_control_return(1);
401     }
402 #endif
403     /* Initialize the simulated device controller.  */
404     status =  _ux_test_dcd_sim_slave_initialize();
405 
406     /* Check for error.  */
407     if (status != UX_SUCCESS)
408     {
409 
410         printf("Running ux_device_stack_control_request_process Test................ ERROR #7\n");
411         test_control_return(1);
412     }
413 
414     /* Register all the USB host controllers available in this system */
415     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
416 
417     /* Check for error.  */
418     if (status != UX_SUCCESS)
419     {
420 
421         printf("Running ux_device_stack_control_request_process Test................ ERROR #4\n");
422         test_control_return(1);
423     }
424 
425     /* Create the main host simulation thread.  */
426     status =  tx_thread_create(&ux_test_thread_simulation_0, "test host simulation", ux_test_thread_simulation_0_entry, 0,
427             stack_pointer, UX_TEST_STACK_SIZE,
428             20, 20, 1, TX_AUTO_START);
429 
430     /* Check for error.  */
431     if (status != TX_SUCCESS)
432     {
433 
434         printf("Running ux_device_stack_control_request_process Test................ ERROR #8\n");
435         test_control_return(1);
436     }
437 }
438 
439 
ux_test_thread_simulation_0_entry(ULONG arg)440 static void  ux_test_thread_simulation_0_entry(ULONG arg)
441 {
442 
443 UINT                     status;
444 
445 UX_SLAVE_DEVICE         *slave_device;
446 UX_SLAVE_ENDPOINT       *slave_endpoint;
447 UX_SLAVE_TRANSFER       *slave_transfer_request;
448 
449 UX_DEVICE               *device;
450 UX_ENDPOINT             *control_endpoint;
451 UX_TRANSFER             *transfer_request;
452 
453     /* Inform user.  */
454     printf("Running ux_device_stack_control_request_process Test................ ");
455 
456     ux_test_dcd_sim_slave_connect(UX_HIGH_SPEED_DEVICE);
457     ux_test_hcd_sim_host_connect(UX_HIGH_SPEED_DEVICE);
458 
459     /* Enumeration check. */
460     if (dpump_slave == UX_NULL)
461     {
462 
463         printf("ERROR #%d: Enum fail\n", __LINE__);
464         test_control_return(1);
465     }
466 
467     /* Device. */
468     status = ux_host_stack_device_get(0, &device);
469     if (status != UX_SUCCESS)
470     {
471 
472         printf("ERROR #%d: device_get fail\n", __LINE__);
473         test_control_return(1);
474     }
475     control_endpoint = &device->ux_device_control_endpoint;
476     transfer_request = &control_endpoint->ux_endpoint_transfer_request;
477 
478     /* Expect errors. */
479     expect_errors = UX_TRUE;
480 
481     transfer_request -> ux_transfer_request_data_pointer =      buffer;
482     transfer_request -> ux_transfer_request_requested_length =  0;
483     transfer_request -> ux_transfer_request_function =          0xFF;
484     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
485     transfer_request -> ux_transfer_request_value =             0;
486 
487     /* Issue class/vendor request, index 0 - class registered. */
488     transfer_request -> ux_transfer_request_index =             0;
489     status = ux_host_stack_transfer_request(transfer_request);
490     if (status != UX_TRANSFER_STALLED && status != UX_SUCCESS)
491     {
492 
493         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
494         error_counter ++;
495     }
496 
497     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
498     status = ux_host_stack_transfer_request(transfer_request);
499     if (status != UX_TRANSFER_STALLED && status != UX_SUCCESS)
500     {
501 
502         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
503         error_counter ++;
504     }
505 
506     /* Issue class/vendor request, index 2 - class not registered. */
507     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
508     transfer_request -> ux_transfer_request_index =             2;
509     status = ux_host_stack_transfer_request(transfer_request);
510     if (status != UX_TRANSFER_STALLED)
511     {
512 
513         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
514         error_counter ++;
515     }
516 
517     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
518     status = ux_host_stack_transfer_request(transfer_request);
519     if (status != UX_TRANSFER_STALLED)
520     {
521 
522         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
523         error_counter ++;
524     }
525 
526     /* Issue class/vendor request, index 20 - invalid interface. */
527     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
528     transfer_request -> ux_transfer_request_index =            20;
529     status = ux_host_stack_transfer_request(transfer_request);
530     if (status != UX_TRANSFER_STALLED)
531     {
532 
533         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
534         error_counter ++;
535     }
536 
537     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
538     status = ux_host_stack_transfer_request(transfer_request);
539     if (status != UX_TRANSFER_STALLED)
540     {
541 
542         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
543         error_counter ++;
544     }
545 
546     /* Slave device. */
547     slave_device = &_ux_system_slave->ux_system_slave_device;
548     /* Device control endpoint. */
549     slave_endpoint = &slave_device -> ux_slave_device_control_endpoint;
550     /* Endpoint transfer request. */
551     slave_transfer_request = &slave_endpoint -> ux_slave_endpoint_transfer_request;
552 
553     /* Error case: ux_slave_transfer_request_completion_code error. */
554     slave_transfer_request->ux_slave_transfer_request_completion_code = UX_ERROR;
555     status = _ux_device_stack_control_request_process(slave_transfer_request);
556     if (status == UX_SUCCESS)
557     {
558 
559         printf("ERROR #%d: expect error but got %x\n", __LINE__, status);
560         error_counter ++;
561     }
562 
563     expect_errors = UX_FALSE;
564 
565     /* Sleep for a tick to make sure everything is complete.  */
566     tx_thread_sleep(1);
567 
568     /* Check for errors from other threads.  */
569     if (error_counter)
570     {
571 
572         /* Test error.  */
573         printf("ERROR #14\n");
574         test_control_return(1);
575     }
576     else
577     {
578 
579         /* Successful test.  */
580         printf("SUCCESS!\n");
581         test_control_return(0);
582     }
583 }
584 
ux_test_instance_activate(VOID * dpump_instance)585 static VOID  ux_test_instance_activate(VOID *dpump_instance)
586 {
587 
588     /* Save the DPUMP instance.  */
589     dpump_slave = (UX_SLAVE_CLASS_DPUMP *) dpump_instance;
590 }
591 
ux_test_instance_deactivate(VOID * dpump_instance)592 static VOID  ux_test_instance_deactivate(VOID *dpump_instance)
593 {
594 
595     /* Reset the DPUMP instance.  */
596     dpump_slave = UX_NULL;
597 }
598 
599