1 /* This tests the case where there no functional descriptor. There should be a
2 functional descriptor, so this is an error. */
3
4 #include "usbx_ux_test_cdc_ecm.h"
5
6 static unsigned char no_function_descriptor_framework[] = {
7
8 /* Device Descriptor */
9 0x12, /* bLength */
10 0x01, /* bDescriptorType */
11 0x10, 0x01, /* bcdUSB */
12 0xef, /* bDeviceClass - Depends on bDeviceSubClass */
13 0x02, /* bDeviceSubClass - Depends on bDeviceProtocol */
14 0x01, /* bDeviceProtocol - There's an IAD */
15 0x40, /* bMaxPacketSize0 */
16 0x70, 0x07, /* idVendor */
17 0x42, 0x10, /* idProduct */
18 0x00, 0x01, /* bcdDevice */
19 0x01, /* iManufacturer */
20 0x02, /* iProduct */
21 0x03, /* iSerialNumber */
22 0x01, /* bNumConfigurations */
23
24 /* Configuration Descriptor */
25 0x09, /* bLength */
26 0x02, /* bDescriptorType */
27 0x4b, 0x00, /* wTotalLength */
28 0x02, /* bNumInterfaces */
29 0x01, /* bConfigurationValue */
30 0x00, /* iConfiguration */
31 0xc0, /* bmAttributes - Self-powered */
32 0x00, /* bMaxPower */
33
34 /* Interface Association Descriptor */
35 0x08, /* bLength */
36 0x0b, /* bDescriptorType */
37 0x00, /* bFirstInterface */
38 0x02, /* bInterfaceCount */
39 0x02, /* bFunctionClass - CDC - Communication */
40 0x06, /* bFunctionSubClass - ECM */
41 0x00, /* bFunctionProtocol - No class specific protocol required */
42 0x00, /* iFunction */
43
44 /* Interface Descriptor */
45 0x09, /* bLength */
46 0x04, /* bDescriptorType */
47 0x00, /* bInterfaceNumber */
48 0x00, /* bAlternateSetting */
49 0x01, /* bNumEndpoints */
50 0x02, /* bInterfaceClass - CDC - Communication */
51 0x06, /* bInterfaceSubClass - ECM */
52 0x00, /* bInterfaceProtocol - No class specific protocol required */
53 0x00, /* iInterface */
54
55 /* CDC Header Functional Descriptor */
56 0x05, /* bLength */
57 0x24, /* bDescriptorType */
58 0x00, /* bDescriptorSubType */
59 0x10, 0x01, /* bcdCDC */
60
61 /* CDC Union Functional Descriptor */
62 0x05, /* bLength */
63 0x24, /* bDescriptorType */
64 0x06, /* bDescriptorSubType */
65 0x00, /* bmMasterInterface */
66 0x01, /* bmSlaveInterface0 */
67
68 /* Endpoint Descriptor */
69 0x07, /* bLength */
70 0x05, /* bDescriptorType */
71 0x83, /* bEndpointAddress */
72 0x03, /* bmAttributes - Interrupt */
73 0x08, 0x00, /* wMaxPacketSize */
74 0x08, /* bInterval */
75
76 /* Interface Descriptor */
77 0x09, /* bLength */
78 0x04, /* bDescriptorType */
79 0x01, /* bInterfaceNumber */
80 0x00, /* bAlternateSetting */
81 0x00, /* bNumEndpoints */
82 0x0a, /* bInterfaceClass - CDC - Data */
83 0x00, /* bInterfaceSubClass - Should be 0x00 */
84 0x00, /* bInterfaceProtocol - No class specific protocol required */
85 0x00, /* iInterface */
86
87 /* Interface Descriptor */
88 0x09, /* bLength */
89 0x04, /* bDescriptorType */
90 0x01, /* bInterfaceNumber */
91 0x01, /* bAlternateSetting */
92 0x02, /* bNumEndpoints */
93 0x0a, /* bInterfaceClass - CDC - Data */
94 0x00, /* bInterfaceSubClass - Should be 0x00 */
95 0x00, /* bInterfaceProtocol - No class specific protocol required */
96 0x00, /* iInterface */
97
98 /* Endpoint Descriptor */
99 0x07, /* bLength */
100 0x05, /* bDescriptorType */
101 0x02, /* bEndpointAddress */
102 0x02, /* bmAttributes - Bulk */
103 0x40, 0x00, /* wMaxPacketSize */
104 0x00, /* bInterval */
105
106 /* Endpoint Descriptor */
107 0x07, /* bLength */
108 0x05, /* bDescriptorType */
109 0x81, /* bEndpointAddress */
110 0x02, /* bmAttributes - Bulk */
111 0x40, 0x00, /* wMaxPacketSize */
112 0x00, /* bInterval */
113
114 };
115
116 static DEVICE_INIT_DATA device_init_data = {
117 .framework = no_function_descriptor_framework,
118 .framework_length = sizeof(no_function_descriptor_framework),
119 .dont_register_hcd = 1,
120 };
121
122 /* Define what the initial system looks like. */
123 #ifdef CTEST
test_application_define(void * first_unused_memory)124 void test_application_define(void *first_unused_memory)
125 #else
126 void usbx_cdc_ecm_no_functional_descriptor_test_application_define(void *first_unused_memory)
127 #endif
128 {
129
130 /* Inform user. */
131 printf("Running CDC-ECM No Functional Descriptor Test....................... ");
132
133 stepinfo("\n");
134
135 ux_test_cdc_ecm_initialize_use_framework(first_unused_memory, &device_init_data);
136 }
137
post_init_host()138 static void post_init_host()
139 {
140
141 int i;
142
143 /* We expect this to fail multiple times since enumeration tries multiple times. */
144 for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
145 {
146
147 ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED));
148 }
149 ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));
150
151 /* Enumerate. */
152 UX_TEST_CHECK_SUCCESS(ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize, 0, 0));
153
154 /* The HCD init function put()s the HCD semaphore, so we can do this here. */
155 ux_test_wait_for_enum_thread_completion();
156
157 /* Enumeration should've failed. */
158 UX_TEST_ASSERT(ux_test_check_actions_empty());
159 UX_TEST_ASSERT(cdc_ecm_host_from_system_change_function == UX_NULL);
160 }
161
post_init_device()162 static void post_init_device()
163 {
164 }