1 #include "usbx_test_common_hid.h"
2 #include "ux_host_class_hid_keyboard.h"
3 
4 #include "ux_test_utility_sim.h"
5 
6 #define DUMMY_USBX_MEMORY_SIZE (64*1024)
7 static UCHAR dummy_usbx_memory[DUMMY_USBX_MEMORY_SIZE];
8 
9 static UCHAR hid_report_descriptor[] = {
10 
11     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
12     0x09, 0x06,                    // USAGE (Keyboard)
13     0xa1, 0x01,                    // COLLECTION (Application)
14     0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
15     0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
16     0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
17     0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
18     0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
19     0x75, 0x01,                    //   REPORT_SIZE (1)
20     0x95, 0x08,                    //   REPORT_COUNT (8)
21     0x81, 0x02,                    //   INPUT (Data,Var,Abs)
22     0x95, 0x01,                    //   REPORT_COUNT (1)
23     0x75, 0x08,                    //   REPORT_SIZE (8)
24     0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
25     0x95, 0x05,                    //   REPORT_COUNT (5)
26     0x75, 0x01,                    //   REPORT_SIZE (1)
27     0x05, 0x08,                    //   USAGE_PAGE (LEDs)
28     0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
29     0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
30     0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
31     0x95, 0x01,                    //   REPORT_COUNT (1)
32     0x75, 0x03,                    //   REPORT_SIZE (3)
33     0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
34     0x95, 0x06,                    //   REPORT_COUNT (6)
35     0x75, 0x08,                    //   REPORT_SIZE (8)
36     0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
37     0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
38     0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
39     0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
40     0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
41     0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
42     0xc0                           // END_COLLECTION
43 };
44 #define HID_REPORT_LENGTH sizeof(hid_report_descriptor)/sizeof(hid_report_descriptor[0])
45 
46 
47 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED 52
48 static UCHAR device_framework_full_speed[DEVICE_FRAMEWORK_LENGTH_FULL_SPEED] = {
49 
50     /* Device descriptor */
51         0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
52         0x81, 0x0A, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
53         0x00, 0x01,
54 
55     /* Configuration descriptor */
56         0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
57         0x32,
58 
59     /* Interface descriptor */
60         0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
61         0x00,
62 
63     /* HID descriptor */
64         0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_REPORT_LENGTH),
65         MSB(HID_REPORT_LENGTH),
66 
67     /* Endpoint descriptor (Interrupt) */
68         0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
69 
70     };
71 
72 
73 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED 62
74 static UCHAR device_framework_high_speed[DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED] = {
75 
76     /* Device descriptor */
77         0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
78         0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
79         0x03, 0x01,
80 
81     /* Device qualifier descriptor */
82         0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
83         0x01, 0x00,
84 
85     /* Configuration descriptor */
86         0x09, 0x02, 0x22, 0x00, 0x01, 0x01, 0x00, 0xc0,
87         0x32,
88 
89     /* Interface descriptor */
90         0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00,
91         0x00,
92 
93     /* HID descriptor */
94         0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_REPORT_LENGTH),
95         MSB(HID_REPORT_LENGTH),
96 
97     /* Endpoint descriptor (Interrupt) */
98         0x07, 0x05, 0x82, 0x03, 0x08, 0x00, 0x08
99 
100     };
101 
102 
103     /* String Device Framework :
104      Byte 0 and 1 : Word containing the language ID : 0x0904 for US
105      Byte 2       : Byte containing the index of the descriptor
106      Byte 3       : Byte containing the length of the descriptor string
107     */
108 
109 #define STRING_FRAMEWORK_LENGTH 40
110 static UCHAR string_framework[] = {
111 
112     /* Manufacturer string descriptor : Index 1 */
113         0x09, 0x04, 0x01, 0x0c,
114         0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
115         0x6f, 0x67, 0x69, 0x63,
116 
117     /* Product string descriptor : Index 2 */
118         0x09, 0x04, 0x02, 0x0c,
119         0x55, 0x53, 0x42, 0x20, 0x4b, 0x65, 0x79, 0x62,
120         0x6f, 0x61, 0x72, 0x64,
121 
122     /* Serial Number string descriptor : Index 3 */
123         0x09, 0x04, 0x03, 0x04,
124         0x30, 0x30, 0x30, 0x31
125     };
126 
127 
128     /* Multiple languages are supported on the device, to add
129        a language besides english, the unicode language code must
130        be appended to the language_id_framework array and the length
131        adjusted accordingly. */
132 #define LANGUAGE_ID_FRAMEWORK_LENGTH 2
133 static UCHAR language_id_framework[] = {
134 
135     /* English. */
136         0x09, 0x04
137     };
138 
139 
140 UINT  _ux_hcd_sim_host_entry(UX_HCD *hcd, UINT function, VOID *parameter);
141 
142 
ux_system_host_change_function(ULONG a,UX_HOST_CLASS * b,VOID * c)143 static UINT ux_system_host_change_function(ULONG a, UX_HOST_CLASS *b, VOID *c)
144 {
145     return 0;
146 }
147 
error_callback(UINT system_level,UINT system_context,UINT error_code)148 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
149 {
150 }
151 
152 /* Define what the initial system looks like.  */
153 
154 #ifdef CTEST
test_application_define(void * first_unused_memory)155 void test_application_define(void *first_unused_memory)
156 #else
157 void    usbx_ux_host_class_hid_report_get_test2_application_define(void *first_unused_memory)
158 #endif
159 {
160 
161 UINT                            status;
162 CHAR *                          stack_pointer;
163 CHAR *                          memory_pointer;
164 
165 
166     /* Inform user.  */
167     printf("Running ux_host_class_hid_report_get Test 2......................... ");
168 
169     /* Initialize the free memory pointer */
170     stack_pointer = (CHAR *) usbx_memory;
171     memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
172 
173     /* Initialize USBX. Memory */
174     status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
175 
176     /* Check for error.  */
177     if (status != UX_SUCCESS)
178     {
179 
180         printf("Error on line %d, error code: %d\n", __LINE__, status);
181         test_control_return(1);
182     }
183 
184     /* Register the error callback. */
185     _ux_utility_error_callback_register(error_callback);
186 
187     /* The code below is required for installing the host portion of USBX */
188     status =  ux_host_stack_initialize(ux_system_host_change_function);
189     if (status != UX_SUCCESS)
190     {
191 
192         printf("Error on line %d, error code: %d\n", __LINE__, status);
193         test_control_return(1);
194     }
195 
196     status =  ux_host_stack_class_register(_ux_system_host_class_hid_name, ux_host_class_hid_entry);
197     if (status != UX_SUCCESS)
198     {
199 
200         printf("Error on line %d, error code: %d\n", __LINE__, status);
201         test_control_return(1);
202     }
203 
204     /* Register the HID client(s).  */
205     status =  ux_host_class_hid_client_register(_ux_system_host_class_hid_client_keyboard_name, ux_host_class_hid_keyboard_entry);
206     if (status != UX_SUCCESS)
207     {
208 
209         printf("Error on line %d, error code: %d\n", __LINE__, status);
210         test_control_return(1);
211     }
212 
213     /* The code below is required for installing the device portion of USBX. No call back for
214        device status change in this example. */
215     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
216                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
217                                        string_framework, STRING_FRAMEWORK_LENGTH,
218                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
219     if(status!=UX_SUCCESS)
220     {
221 
222         printf("Error on line %d, error code: %d\n", __LINE__, status);
223         test_control_return(1);
224     }
225 
226     /* Initialize the hid class parameters.  */
227     hid_parameter.ux_device_class_hid_parameter_report_address = hid_report_descriptor;
228     hid_parameter.ux_device_class_hid_parameter_report_length  = HID_REPORT_LENGTH;
229     hid_parameter.ux_device_class_hid_parameter_callback       = demo_thread_hid_callback;
230 
231     /* Initilize the device hid class. The class is connected with interface 2 */
232     status =  ux_device_stack_class_register(_ux_system_slave_class_hid_name, ux_device_class_hid_entry,
233                                                 1,2, (VOID *)&hid_parameter);
234     if(status!=UX_SUCCESS)
235     {
236 
237         printf("Error on line %d, error code: %d\n", __LINE__, status);
238         test_control_return(1);
239     }
240 
241     /* Initialize the simulated device controller.  */
242     status =  _ux_dcd_sim_slave_initialize();
243 
244     /* Check for error.  */
245     if (status != UX_SUCCESS)
246     {
247 
248         printf("Error on line %d, error code: %d\n", __LINE__, status);
249         test_control_return(1);
250     }
251 
252     /* Register all the USB host controllers available in this system */
253     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
254 
255     /* Check for error.  */
256     if (status != UX_SUCCESS)
257     {
258 
259         printf("Error on line %d, error code: %d\n", __LINE__, status);
260         test_control_return(1);
261     }
262 
263     /* Create the main host simulation thread.  */
264     status =  tx_thread_create(&tx_demo_thread_host_simulation, "tx demo host simulation", tx_demo_thread_host_simulation_entry, 0,
265             stack_pointer, UX_DEMO_STACK_SIZE,
266             20, 20, 1, TX_AUTO_START);
267 
268     /* Check for error.  */
269     if (status != TX_SUCCESS)
270     {
271 
272         printf("Error on line %d, error code: %d\n", __LINE__, status);
273         test_control_return(1);
274     }
275 }
276 
ux_hcd_sim_host_entry_filter(UX_HCD * hcd,UINT function,VOID * parameter)277 static UINT ux_hcd_sim_host_entry_filter(UX_HCD *hcd, UINT function, VOID *parameter)
278 {
279 
280 UINT            status;
281 UX_TRANSFER    *transfer_request;
282 
283 
284     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
285 
286     /* Let get port status requests don't return UX_SUCCESS. */
287     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
288     {
289 
290         printf("Error on line %d, error code: %d\n", __LINE__, status);
291         test_control_return(1);
292     }
293 
294     if (function == UX_HCD_TRANSFER_REQUEST)
295     {
296 
297         transfer_request = parameter;
298 
299         if (transfer_request -> ux_transfer_request_requested_length == 8 &&
300             transfer_request -> ux_transfer_request_function == 1 &&
301             transfer_request -> ux_transfer_request_type == 0xa1 &&
302             transfer_request -> ux_transfer_request_value == 0x100 &&
303             transfer_request -> ux_transfer_request_index == 2)
304         {
305 
306             transfer_request -> ux_transfer_request_actual_length = 0;
307         }
308     }
309 
310     return status;
311 }
312 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test2(UX_HCD * hcd,UINT function,VOID * parameter)313 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test2(UX_HCD *hcd, UINT function, VOID *parameter)
314 {
315 
316 UINT            status;
317 UX_TRANSFER    *transfer_request;
318 
319 
320     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
321 
322     /* Let get port status requests don't return UX_SUCCESS. */
323     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
324     {
325 
326         printf("Error on line %d, error code: %d\n", __LINE__, status);
327         test_control_return(1);
328     }
329 
330     if (function == UX_HCD_TRANSFER_REQUEST)
331     {
332 
333         transfer_request = parameter;
334 
335         if (transfer_request -> ux_transfer_request_requested_length == 8 &&
336             transfer_request -> ux_transfer_request_function == 1 &&
337             transfer_request -> ux_transfer_request_type == 0xa1 &&
338             transfer_request -> ux_transfer_request_value == 0x100 &&
339             transfer_request -> ux_transfer_request_index == 2)
340         {
341 
342             status = UX_ERROR;
343         }
344     }
345 
346     return status;
347 }
348 
tx_demo_thread_host_simulation_entry(ULONG arg)349 static void  tx_demo_thread_host_simulation_entry(ULONG arg)
350 {
351 
352 UINT                                status;
353 UX_HOST_CLASS_HID_KEYBOARD          *keyboard;
354 UX_HCD                              *hcd;
355 ALIGN_TYPE                          tmp;
356 UX_HOST_CLASS_HID_CLIENT_REPORT     client_report;
357 UX_HOST_CLASS_HID_REPORT            hid_report;
358 ULONG                               client_report_buffer[32/4];
359 
360     /**************************************************/
361     /**************************************************/
362     /** Why direct: this is a user API and not called by USBX. **/
363     /**************************************************/
364     /**************************************************/
365 
366     /* Find the HID class */
367     status = demo_class_hid_get();
368     if (status != UX_SUCCESS)
369     {
370 
371         printf("Error on line %d, error code: %d\n", __LINE__, status);
372         test_control_return(1);
373     }
374 
375     /* Get the HID client */
376     hid_client = hid -> ux_host_class_hid_client;
377 
378     /* Check if the instance of the keyboard is live */
379     while (hid_client -> ux_host_class_hid_client_local_instance == UX_NULL)
380         tx_thread_sleep(10);
381 
382     /* Get the keyboard instance */
383     keyboard =  (UX_HOST_CLASS_HID_KEYBOARD *)hid_client -> ux_host_class_hid_client_local_instance;
384 
385     /**************************************************/
386     /** Test case: (status == UX_SUCCESS) fails in
387     if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == hid_report -> ux_host_class_hid_report_byte_length)) **/
388     /**************************************************/
389 
390     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
391 
392     client_report.ux_host_class_hid_client_report = &hid_report;
393     client_report.ux_host_class_hid_client_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
394     client_report.ux_host_class_hid_client_report_length = 32;
395 
396     /* Swap the hcd entry function. */
397     hcd = UX_DEVICE_HCD_GET(hid -> ux_host_class_hid_device);
398     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
399     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test2;
400 
401     status = _ux_host_class_hid_report_get(hid, &client_report);
402     if (status != UX_HOST_CLASS_HID_REPORT_ERROR)
403     {
404 
405         printf("Error on line %d, error code: %d\n", __LINE__, status);
406         test_control_return(1);
407     }
408 
409     /** Restore state for next test. **/
410 
411     /* Restore entry function. */
412     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
413 
414     /* ux_host_stack_transfer_request() doesn't release the device protection semaphore when it fails, so do it manually. */
415     _ux_utility_semaphore_put(&hid -> ux_host_class_hid_device -> ux_device_protection_semaphore);
416 
417     /**************************************************/
418     /** Test case: (transfer_request -> ux_transfer_request_actual_length == hid_report -> ux_host_class_hid_report_byte_length) fails in
419     if ((status == UX_SUCCESS) && (transfer_request -> ux_transfer_request_actual_length == hid_report -> ux_host_class_hid_report_byte_length)) **/
420     /**************************************************/
421 
422     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
423 
424     client_report.ux_host_class_hid_client_report = &hid_report;
425     client_report.ux_host_class_hid_client_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
426     client_report.ux_host_class_hid_client_report_length = 32;
427 
428     /* Swap the hcd entry function. */
429     hcd = UX_DEVICE_HCD_GET(hid -> ux_host_class_hid_device);
430     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
431     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter;
432 
433     status = _ux_host_class_hid_report_get(hid, &client_report);
434     if (status != UX_HOST_CLASS_HID_REPORT_ERROR)
435     {
436 
437         printf("Error on line %d, error code: %d\n", __LINE__, status);
438         test_control_return(1);
439     }
440 
441     /* Restore entry function. */
442     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
443 
444     /* ux_host_stack_transfer_request() doesn't release the device protection semaphore when it fails, so do it manually. */
445     _ux_utility_semaphore_put(&hid -> ux_host_class_hid_device -> ux_device_protection_semaphore);
446 
447     /**************************************************/
448     /** Test case: status =  _ux_utility_semaphore_get(&hid -> ux_host_class_hid_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); fails **/
449     /**************************************************/
450 
451     hid_report.ux_host_class_hid_report_byte_length = 1;
452     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
453     client_report.ux_host_class_hid_client_report = &hid_report;
454 
455     /* Make sure it fails. */
456     hid -> ux_host_class_hid_device -> ux_device_protection_semaphore.tx_semaphore_id++;
457 
458     status = _ux_host_class_hid_report_get(hid, &client_report);
459     if(status != TX_SEMAPHORE_ERROR)
460     {
461 
462         printf("Error on line %d, error code: %d\n", __LINE__, status);
463         test_control_return(1);
464     }
465 
466     /* Restore state. */
467     hid -> ux_host_class_hid_device -> ux_device_protection_semaphore.tx_semaphore_id--;
468 
469     /* The function did a get() on the hid semaphore and never put() it, so we must do it!!! FOR THE GOOD OF HUMANITY... BY THE POWER INVESTED IN ME, YOU SHALL BE PUT()'d! */
470     status = ux_utility_semaphore_put(&hid -> ux_host_class_hid_semaphore);
471     if (status != UX_SUCCESS)
472     {
473 
474         printf("Error on line %d, error code: %d\n", __LINE__, status);
475         test_control_return(1);
476     }
477 
478     /**************************************************/
479     /** Test case: _ux_utility_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER); fails **/
480     /**************************************************/
481 
482     /* Make sure it fails. */
483     hid -> ux_host_class_hid_semaphore.tx_semaphore_id++;
484 
485     status = _ux_host_class_hid_report_get(hid, UX_NULL);
486     if(status != TX_SEMAPHORE_ERROR)
487     {
488 
489         printf("Error on line %d, error code: %d\n", __LINE__, status);
490         test_control_return(1);
491     }
492 
493     /* Restore state. */
494     hid -> ux_host_class_hid_semaphore.tx_semaphore_id--;
495 
496     /**************************************************/
497     /** Test case: making ux_utility_memory_allocate() fails **/
498     /**************************************************/
499 
500     hid_report.ux_host_class_hid_report_byte_length = 1;
501     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
502     client_report.ux_host_class_hid_client_report = &hid_report;
503 
504     ux_test_utility_sim_mem_alloc_fail_all_start();
505 
506     status = _ux_host_class_hid_report_get(hid, &client_report);
507     if (status != UX_MEMORY_INSUFFICIENT)
508     {
509 
510         printf("Error on line %d, error code: %d\n", __LINE__, status);
511         test_control_return(1);
512     }
513 
514     /* Restore state for next test. */
515     ux_test_utility_sim_mem_alloc_fail_all_stop();
516 
517     /**************************************************/
518     /** Test case: _ux_host_stack_class_instance_verify() fails. **/
519     /**************************************************/
520 
521     /* Make sure verify() doesn't find any classes. */
522     // tmp = _ux_system_host -> ux_system_host_max_class;
523     // _ux_system_host -> ux_system_host_max_class = 0;
524     tmp = _ux_system_host->ux_system_host_class_array->ux_host_class_status;
525     _ux_system_host->ux_system_host_class_array->ux_host_class_status = UX_UNUSED;
526 
527     if (ux_host_class_hid_report_get(hid, &client_report) != UX_HOST_CLASS_INSTANCE_UNKNOWN)
528     {
529 
530         printf("Error on line %d\n", __LINE__);
531         test_control_return(1);
532     }
533 
534     /* Restore state for next test. */
535     // _ux_system_host -> ux_system_host_max_class = (UINT)tmp;
536     _ux_system_host->ux_system_host_class_array->ux_host_class_status = (UINT)tmp;
537 
538     /**************************************************/
539     /** Test case: if (hid_report -> ux_host_class_hid_report_type != UX_HOST_CLASS_HID_REPORT_TYPE_INPUT). **/
540     /**************************************************/
541 
542     /* Set to a non-input report. */
543     hid_report.ux_host_class_hid_report_type = ~UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
544 
545     client_report.ux_host_class_hid_client_report = &hid_report;
546 
547     if (_ux_host_class_hid_report_get(hid, &client_report) != UX_HOST_CLASS_HID_REPORT_ERROR)
548     {
549 
550         printf("Error on line %d\n", __LINE__);
551         test_control_return(1);
552     }
553 
554     /**************************************************/
555     /** Test case: if (hid_report -> ux_host_class_hid_report_type != UX_HOST_CLASS_HID_REPORT_TYPE_FEATURE). **/
556     /**************************************************/
557 
558     /* Set to a feature report. */
559     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_FEATURE;
560 
561     client_report.ux_host_class_hid_client_report = &hid_report;
562     client_report.ux_host_class_hid_client_report_buffer = client_report_buffer;
563     tmp = client_report.ux_host_class_hid_client_report_flags;
564     client_report.ux_host_class_hid_client_report_flags |= UX_HOST_CLASS_HID_REPORT_RAW;
565 
566     status = _ux_host_class_hid_report_get(hid, &client_report);
567     if (status != UX_SUCCESS)
568     {
569 
570         printf("Error on line %d, %x\n", __LINE__, status);
571         test_control_return(1);
572     }
573 
574     /* Restore.  */
575     client_report.ux_host_class_hid_client_report_flags = tmp;
576 
577     /**************************************************/
578     /** Test case: request a zero-length report. **/
579     /**************************************************/
580 
581     /* Set to a zero-length input report. */
582     hid_report.ux_host_class_hid_report_type = UX_HOST_CLASS_HID_REPORT_TYPE_INPUT;
583     hid_report.ux_host_class_hid_report_byte_length = 0;
584 
585     client_report.ux_host_class_hid_client_report = &hid_report;
586 
587     if (_ux_host_class_hid_report_get(hid, &client_report) != UX_HOST_CLASS_HID_REPORT_ERROR)
588     {
589 
590         printf("Error on line %d\n", __LINE__);
591         test_control_return(1);
592     }
593 
594     /**************************************************/
595     /** Test case: not enough memory to store report. **/
596     /**************************************************/
597 
598     /* Set to the report in the main report descriptor. */
599     client_report.ux_host_class_hid_client_report_flags = UX_HOST_CLASS_HID_REPORT_RAW;
600     client_report.ux_host_class_hid_client_report = hid -> ux_host_class_hid_parser.ux_host_class_hid_parser_input_report;
601     client_report.ux_host_class_hid_client_report_length = 0;
602 
603     if (_ux_host_class_hid_report_get(hid, &client_report) != UX_BUFFER_OVERFLOW)
604     {
605 
606         printf("Error on line %d\n", __LINE__);
607         test_control_return(1);
608     }
609 
610     /* Now disconnect the device.  */
611     _ux_device_stack_disconnect();
612 
613     /* And deinitialize the class.  */
614     status =  ux_device_stack_class_unregister(_ux_system_slave_class_hid_name, ux_device_class_hid_entry);
615 
616     /* Deinitialize the device side of usbx.  */
617     _ux_device_stack_uninitialize();
618 
619     /* And finally the usbx system resources.  */
620     _ux_system_uninitialize();
621 
622     /* Successful test.  */
623     printf("SUCCESS!\n");
624     test_control_return(0);
625 }
626 
demo_thread_hid_callback(UX_SLAVE_CLASS_HID * class,UX_SLAVE_CLASS_HID_EVENT * event)627 static UINT    demo_thread_hid_callback(UX_SLAVE_CLASS_HID *class, UX_SLAVE_CLASS_HID_EVENT *event)
628 {
629     return(UX_SUCCESS);
630 }
631