1 /* This tests the case where the hub reports an invalid device protocol. Specific
2    test case is in ux_host_class_hub_descriptor_get.c. */
3 
4 #include "usbx_ux_test_hub.h"
5 
6 static unsigned char framework_invalid_device_protocol[] = {
7 
8     /* Device Descriptor */
9     0x12, /* bLength */
10     0x01, /* bDescriptorType */
11     0x00, 0x02, /* bcdUSB */
12     0x09, /* bDeviceClass - Hub */
13     0x00, /* bDeviceSubClass */
14     0x03, /* bDeviceProtocol - invalid device protocl */
15     0x40, /* bMaxPacketSize0 */
16     0x24, 0x04, /* idVendor */
17     0x12, 0x24, /* idProduct */
18     0xb2, 0x0b, /* bcdDevice */
19     0x00, /* iManufacturer */
20     0x00, /* iProduct */
21     0x00, /* iSerialNumber */
22     0x01, /* bNumConfigurations */
23 
24     /* Configuration Descriptor */
25     0x09, /* bLength */
26     0x02, /* bDescriptorType */
27     0x19, 0x00, /* wTotalLength */
28     0x01, /* bNumInterfaces */
29     0x01, /* bConfigurationValue */
30     0x00, /* iConfiguration */
31     0xe0, /* bmAttributes - Self-powered */
32     0x01, /* bMaxPower */
33 
34     /* Interface Descriptor */
35     0x09, /* bLength */
36     0x04, /* bDescriptorType */
37     0x00, /* bInterfaceNumber */
38     0x00, /* bAlternateSetting */
39     0x01, /* bNumEndpoints */
40     0x09, /* bInterfaceClass - Hub */
41     0x00, /* bInterfaceSubClass */
42     0x00, /* bInterfaceProtocol */
43     0x00, /* iInterface */
44 
45     /* Endpoint Descriptor */
46     0x07, /* bLength */
47     0x05, /* bDescriptorType */
48     0x81, /* bEndpointAddress */
49     0x03, /* bmAttributes - Interrupt */
50     0x02, 0x00, /* wMaxPacketSize */
51     0x0c, /* bInterval */
52 
53 };
54 
55 static DEVICE_INIT_DATA device_init_data = {
56     .dont_enumerate = 1,
57     .framework = framework_invalid_device_protocol,
58     .framework_length = sizeof(framework_invalid_device_protocol),
59 };
60 
61 #ifdef CTEST
test_application_define(void * first_unused_memory)62 void test_application_define(void *first_unused_memory)
63 #else
64 void usbx_hub_invalid_device_protocol_test_application_define(void *first_unused_memory)
65 #endif
66 {
67 
68     /* Inform user.  */
69     printf("Running Hub Invalid Device Protocol Test............................ ");
70 
71     stepinfo("\n");
72 
73     initialize_hub_with_device_init_data(first_unused_memory, &device_init_data);
74 }
75 
post_init_host()76 static void post_init_host()
77 {
78 #if UX_MAX_DEVICES > 1
79 int i;
80 
81     /* We expect error to happen multiple times. */
82     for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
83     {
84         ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_DESCRIPTOR_CORRUPTED));
85     }
86     ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));
87 
88     /* Enumerate. */
89     UX_TEST_CHECK_SUCCESS(ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize, 0, 0));
90     ux_test_wait_for_enum_thread_completion();
91 
92     /* Ensure all expected actions occurred. */
93     UX_TEST_ASSERT(ux_test_check_actions_empty());
94     UX_TEST_ASSERT(g_hub_host_from_system_change_function == UX_NULL);
95 #endif
96 }
97 
post_init_device()98 static void post_init_device()
99 {
100 }