1 /* This tests the case where the setting the data interface with endpoints fails.  */
2 
3 #include "usbx_ux_test_cdc_ecm.h"
4 
5 static DEVICE_INIT_DATA device_init_data = {
6     .framework = default_device_framework,
7     .framework_length = sizeof(default_device_framework),
8     .dont_register_hcd = 1,
9 };
10 
11 /* Define what the initial system looks like.  */
12 #ifdef CTEST
test_application_define(void * first_unused_memory)13 void test_application_define(void *first_unused_memory)
14 #else
15 void usbx_cdc_ecm_data_interface_setting_select_fails_test_application_define(void *first_unused_memory)
16 #endif
17 {
18 
19     /* Inform user.  */
20     printf("Running Data Interface Setting Select Fails Test.................... ");
21 
22     stepinfo("\n");
23 
24     ux_test_cdc_ecm_initialize_use_framework(first_unused_memory, &device_init_data);
25 }
26 
post_init_host()27 static void post_init_host()
28 {
29 
30 int i;
31 
32 #if 0
33     /* Create a transfer_request for the SET_INTERFACE request. No data for this request */
34     transfer_request -> ux_transfer_request_requested_length =  0;
35     transfer_request -> ux_transfer_request_function =          UX_SET_INTERFACE;
36     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_INTERFACE;
37     transfer_request -> ux_transfer_request_index =             (USHORT) interface -> ux_interface_descriptor.bInterfaceNumber;
38     transfer_request -> ux_transfer_request_value =             (USHORT) interface -> ux_interface_descriptor.bAlternateSetting;
39 #endif
40 
41     UX_TEST_SETUP alternate_setting_set_setup;
42     alternate_setting_set_setup.ux_test_setup_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_INTERFACE;
43     alternate_setting_set_setup.ux_test_setup_request = UX_SET_INTERFACE;
44     alternate_setting_set_setup.ux_test_setup_value = 1; /* Alternate Setting */
45     alternate_setting_set_setup.ux_test_setup_index = 1; /* Interface (data is 1) */
46 
47     /* We need to intercept the configuration descriptor. */
48     UX_TEST_ACTION alternate_setting_fail_action = {0};
49     alternate_setting_fail_action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
50     alternate_setting_fail_action.function = UX_HCD_TRANSFER_REQUEST;
51     alternate_setting_fail_action.req_action = UX_TEST_SETUP_MATCH_REQUEST;
52     alternate_setting_fail_action.req_setup = &alternate_setting_set_setup;
53     alternate_setting_fail_action.status = UX_ERROR;
54     alternate_setting_fail_action.no_return = 0;
55 
56     /* We expect this to fail multiple times since enumeration tries multiple times. */
57     for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
58     {
59         ux_test_add_action_to_main_list(alternate_setting_fail_action);
60     }
61     ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));
62 
63     /* Enumerate. */
64     UX_TEST_CHECK_SUCCESS(ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize, 0, 0));
65 
66     /* The HCD init function put()s the HCD semaphore, so we can do this here. */
67     ux_test_wait_for_enum_thread_completion();
68 
69     /* Enumeration should've failed.  */
70     UX_TEST_ASSERT(ux_test_check_actions_empty());
71     UX_TEST_ASSERT(cdc_ecm_host_from_system_change_function == UX_NULL);
72 }
73 
post_init_device()74 static void post_init_device()
75 {
76 }