diff options
| author | Yuxin Zhou <[email protected]> | 2021-02-02 00:52:59 +0000 |
|---|---|---|
| committer | Yuxin Zhou <[email protected]> | 2021-02-02 00:52:59 +0000 |
| commit | 5d2acef877e3a9215ef495bf350fbceb06349bb5 (patch) | |
| tree | f68e6c13b1503f87be8f346bb97a715d8dc3a723 | |
| parent | 9823f3857d7eb54c8416d9eab316aab0257130f9 (diff) | |
Release 6.1.4v6.1.4_rel
61 files changed, 1174 insertions, 257 deletions
diff --git a/common/core/CMakeLists.txt b/common/core/CMakeLists.txt index 85f1b85..8b1796f 100644 --- a/common/core/CMakeLists.txt +++ b/common/core/CMakeLists.txt @@ -104,14 +104,18 @@ target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_configuration_instance_create.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_configuration_instance_delete.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_configuration_interface_get.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_configuration_interface_scan.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_configuration_set.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_delay_ms.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_address_set.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_configuration_activate.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_configuration_deactivate.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_configuration_get.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_configuration_reset.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_configuration_select.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_descriptor_read.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_get.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_string_get.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_remove.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_device_resources_free.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_stack_endpoint_instance_create.c diff --git a/common/core/inc/ux_api.h b/common/core/inc/ux_api.h index 872f6cc..7932d79 100644..100755 --- a/common/core/inc/ux_api.h +++ b/common/core/inc/ux_api.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* ux_api.h PORTABLE C */ -/* 6.1.3 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -71,6 +71,16 @@ /* 12-31-2020 Chaoqiong Xiao Modified comment(s), */ /* added BOS support, */ /* resulting in version 6.1.3 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* added configuration activate*/ +/* and deactivate support, */ +/* added host printer get */ +/* device ID support, */ +/* added host device string */ +/* descriptor get support, */ +/* added events for device */ +/* connection/disconnection, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ @@ -205,7 +215,7 @@ typedef signed char SCHAR; #define AZURE_RTOS_USBX #define USBX_MAJOR_VERSION 6 #define USBX_MINOR_VERSION 1 -#define USBX_PATCH_VERSION 3 +#define USBX_PATCH_VERSION 4 /* Macros for concatenating tokens, where UX_CONCATn concatenates n tokens. */ @@ -395,6 +405,9 @@ VOID _ux_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, UL #define UX_TRACE_HOST_STACK_HCD_UNREGISTER (UX_TRACE_HOST_STACK_EVENTS_BASE + 35) /* I1 = hcd name , I2 = parameter 1 , I3 = parameter 2 */ #define UX_TRACE_HOST_STACK_CLASS_REGISTER (UX_TRACE_HOST_STACK_EVENTS_BASE + 36) /* I1 = class name , I2 = entry function */ #define UX_TRACE_HOST_STACK_CLASS_UNREGISTER (UX_TRACE_HOST_STACK_EVENTS_BASE + 37) /* I1 = class entry */ +#define UX_TRACE_HOST_STACK_DEVICE_STRING_GET (UX_TRACE_HOST_STACK_EVENTS_BASE + 38) /* I1 = device , I2 = buffer , I3 = length , I4 = (langID<<16) | index */ +#define UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_ACTIVATE (UX_TRACE_HOST_STACK_EVENTS_BASE + 39) /* I1 = device , I2 = configuration */ +#define UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_DEACTIVATE (UX_TRACE_HOST_STACK_EVENTS_BASE + 40) /* I1 = device , I2 = configuration */ /* Define the USBX host class events. */ @@ -490,6 +503,7 @@ VOID _ux_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, UL #define UX_TRACE_HOST_CLASS_PRINTER_WRITE (UX_TRACE_HOST_CLASS_EVENTS_BASE + 104) /* I1 = class instance , I2 = data pointer , I3 = requested length */ #define UX_TRACE_HOST_CLASS_PRINTER_SOFT_RESET (UX_TRACE_HOST_CLASS_EVENTS_BASE + 105) /* I1 = class instance */ #define UX_TRACE_HOST_CLASS_PRINTER_STATUS_GET (UX_TRACE_HOST_CLASS_EVENTS_BASE + 106) /* I1 = class instance , I2 = printer status */ +#define UX_TRACE_HOST_CLASS_PRINTER_DEVICE_ID_GET (UX_TRACE_HOST_CLASS_EVENTS_BASE + 107) /* I1 = class instance , I2 = printer , I3 = data pointer , I4 = buffer length */ #define UX_TRACE_HOST_CLASS_PROLIFIC_ACTIVATE (UX_TRACE_HOST_CLASS_EVENTS_BASE + 110) /* I1 = class instance */ #define UX_TRACE_HOST_CLASS_PROLIFIC_DEACTIVATE (UX_TRACE_HOST_CLASS_EVENTS_BASE + 111) /* I1 = class instance */ @@ -1019,12 +1033,20 @@ VOID _ux_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, UL #define UX_TRANSFER_PHASE_STATUS_IN 4 #define UX_TRANSFER_PHASE_STATUS_OUT 5 -#define UX_DEVICE_INSERTION 1 -#define UX_DEVICE_REMOVAL 2 -#define UX_HID_CLIENT_INSERTION 3 -#define UX_HID_CLIENT_REMOVAL 4 -#define UX_STORAGE_MEDIA_INSERTION 5 -#define UX_STORAGE_MEDIA_REMOVAL 6 + +/* Host change callback events : _callback(event, *class, *instance) */ + +#define UX_DEVICE_INSERTION 0x01u +#define UX_DEVICE_REMOVAL 0x02u +#define UX_HID_CLIENT_INSERTION 0x03u +#define UX_HID_CLIENT_REMOVAL 0x04u +#define UX_STORAGE_MEDIA_INSERTION 0x05u +#define UX_STORAGE_MEDIA_REMOVAL 0x06u + +/* Host change callback events : _callback(event, NULL, *device_instance) */ + +#define UX_DEVICE_CONNECTION 0x81u +#define UX_DEVICE_DISCONNECTION 0x82u /* Define USBX transfer request status constants. */ @@ -1135,6 +1157,7 @@ VOID _ux_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, UL #define UX_MEMORY_CORRUPTED 0x19 #define UX_MEMORY_ARRAY_FULL 0x1a #define UX_FATAL_ERROR 0x1b +#define UX_ALREADY_ACTIVATED 0x1c #define UX_TRANSFER_STALLED 0x21 #define UX_TRANSFER_NO_ANSWER 0x22 @@ -1588,7 +1611,8 @@ typedef struct UX_DEVICE_STRUCT ULONG ux_device_address; ULONG ux_device_speed; ULONG ux_device_power_source; - UINT ux_device_current_configuration; + struct UX_CONFIGURATION_STRUCT + *ux_device_current_configuration; UX_SEMAPHORE ux_device_protection_semaphore; struct UX_HOST_CLASS_STRUCT *ux_device_class; @@ -2232,9 +2256,12 @@ typedef struct UX_HOST_CLASS_DPUMP_STRUCT #define ux_host_stack_class_register _ux_host_stack_class_register #define ux_host_stack_class_unregister _ux_host_stack_class_unregister #define ux_host_stack_configuration_interface_get _ux_host_stack_configuration_interface_get +#define ux_host_stack_device_configuration_activate _ux_host_stack_device_configuration_activate +#define ux_host_stack_device_configuration_deactivate _ux_host_stack_device_configuration_deactivate #define ux_host_stack_device_configuration_get _ux_host_stack_device_configuration_get #define ux_host_stack_device_configuration_select _ux_host_stack_device_configuration_select #define ux_host_stack_device_get _ux_host_stack_device_get +#define ux_host_stack_device_string_get _ux_host_stack_device_string_get #define ux_host_stack_endpoint_transfer_abort _ux_host_stack_endpoint_transfer_abort #define ux_host_stack_hcd_register _ux_host_stack_hcd_register #define ux_host_stack_hcd_unregister _ux_host_stack_hcd_unregister @@ -2303,9 +2330,12 @@ UINT ux_host_stack_class_register(UCHAR *class_name, UINT (*class_entry_funct UINT ux_host_stack_class_unregister(UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *)); UINT ux_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration, UINT interface_index, UINT alternate_setting_index, UX_INTERFACE **interface); +UINT ux_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration); +UINT ux_host_stack_device_configuration_deactivate(UX_DEVICE *device); UINT ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index, UX_CONFIGURATION **configuration); UINT ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration); UINT ux_host_stack_device_get(ULONG device_index, UX_DEVICE **device); +UINT ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index); UINT ux_host_stack_endpoint_transfer_abort(UX_ENDPOINT *endpoint); UINT ux_host_stack_hcd_register(UCHAR *hcd_name, UINT (*hcd_initialize_function)(struct UX_HCD_STRUCT *), ULONG hcd_param1, ULONG hcd_param2); UINT ux_host_stack_hcd_unregister(UCHAR *hcd_name, ULONG hcd_param1, ULONG hcd_param2); diff --git a/common/core/inc/ux_host_stack.h b/common/core/inc/ux_host_stack.h index e17f9f1..a8bc131 100644 --- a/common/core/inc/ux_host_stack.h +++ b/common/core/inc/ux_host_stack.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* ux_host_stack.h PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -46,6 +46,13 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* added configuration activate*/ +/* and deactivate support, */ +/* added host device string */ +/* descriptor get support, */ +/* updated internal function, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ @@ -83,15 +90,19 @@ VOID _ux_host_stack_configuration_instance_delete(UX_CONFIGURATION *configura UINT _ux_host_stack_configuration_interface_get(UX_CONFIGURATION *configuration, UINT interface_index, UINT alternate_setting_index, UX_INTERFACE **interface); +UINT _ux_host_stack_configuration_interface_scan(UX_CONFIGURATION *configuration); UINT _ux_host_stack_configuration_set(UX_CONFIGURATION *configuration); VOID _ux_host_stack_delay_ms(ULONG time); UINT _ux_host_stack_device_address_set(UX_DEVICE *device); +UINT _ux_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration); +UINT _ux_host_stack_device_configuration_deactivate(UX_DEVICE *device); UINT _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index, UX_CONFIGURATION **configuration); UINT _ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration); UINT _ux_host_stack_device_configuration_reset(UX_DEVICE *device); UINT _ux_host_stack_device_descriptor_read(UX_DEVICE *device); UINT _ux_host_stack_device_get(ULONG device_index, UX_DEVICE **device); +UINT _ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index); UINT _ux_host_stack_device_remove(UX_HCD *hcd, UX_DEVICE *parent, UINT port_index); UINT _ux_host_stack_device_resources_free(UX_DEVICE *device); UINT _ux_host_stack_endpoint_instance_create(UX_ENDPOINT *endpoint); @@ -116,7 +127,8 @@ VOID _ux_host_stack_new_configuration_create(UX_DEVICE *device, UX_CONFIGURAT UX_DEVICE *_ux_host_stack_new_device_get(VOID); UINT _ux_host_stack_new_device_create(UX_HCD *hcd, UX_DEVICE *device_owner, UINT port_index, UINT device_speed, - UINT port_max_power); + UINT port_max_power, + UX_DEVICE **created_device); UINT _ux_host_stack_new_endpoint_create(UX_INTERFACE *interface, UCHAR * interface_endpoint); UINT _ux_host_stack_new_interface_create(UX_CONFIGURATION *configuration, UCHAR * descriptor, ULONG length); VOID _ux_host_stack_rh_change_process(VOID); diff --git a/common/core/inc/ux_user_sample.h b/common/core/inc/ux_user_sample.h index 7f046fb..ea139cf 100644 --- a/common/core/inc/ux_user_sample.h +++ b/common/core/inc/ux_user_sample.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* ux_user.h PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* */ /* AUTHOR */ /* */ @@ -47,6 +47,10 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Xiuwen Cai Modified comment(s), added */ +/* compile option for using */ +/* packet pool from NetX, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ @@ -260,6 +264,17 @@ /* #define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT 10 */ /* Defined, this value represents the number of milliseconds to wait for packet + pool availability checking loop. + The default is 100 milliseconds. +*/ + +/* #define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT 10 */ + +/* Defined, this enables CDC ECM class to use the packet pool from NetX instance. */ + +/* #define UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX */ + +/* Defined, this value represents the number of milliseconds to wait for packet allocation until invoking the application's error callback and retrying. */ diff --git a/common/core/src/ux_host_stack_class_interface_scan.c b/common/core/src/ux_host_stack_class_interface_scan.c index 62b39e8..85a6348 100644 --- a/common/core/src/ux_host_stack_class_interface_scan.c +++ b/common/core/src/ux_host_stack_class_interface_scan.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_class_interface_scan PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -83,20 +83,18 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used internal function call */ +/* to scan interfaces, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_class_interface_scan(UX_DEVICE *device) { UX_CONFIGURATION *configuration; -UX_INTERFACE *interface; -UINT nb_class_owners; -UX_HOST_CLASS *class; -UX_HOST_CLASS_COMMAND class_command; UINT status; - /* Initialize class owners to 0. */ - nb_class_owners = 0; /* Get the 1st and only configuration. If the device has multiple configurations, we simply use the first one as default. */ @@ -104,94 +102,9 @@ UINT status; if (configuration == UX_NULL) return(UX_ERROR); - /* Get the first interface container for this configuration. */ - interface = configuration -> ux_configuration_first_interface; + /* Scan interfaces for this configuration. */ + status = _ux_host_stack_configuration_interface_scan(configuration); - /* We now scan all the alternate settings 0 for each of the interfaces. */ - while (interface != UX_NULL) - { - - /* Is there a default interface? */ - if(interface -> ux_interface_descriptor.bAlternateSetting == 0) - { - - /* We have a default interface for this configuration. Call each class - with the class\subclass\protocol. We include the IAD for the cdc classes. */ - class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY; - class_command.ux_host_class_command_container = (VOID *)interface; - class_command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_CSP; - class_command.ux_host_class_command_class = interface -> ux_interface_descriptor.bInterfaceClass; - class_command.ux_host_class_command_subclass = interface -> ux_interface_descriptor.bInterfaceSubClass; - class_command.ux_host_class_command_protocol = interface -> ux_interface_descriptor.bInterfaceProtocol; - class_command.ux_host_class_command_iad_class = interface -> ux_interface_iad_class ; - class_command.ux_host_class_command_iad_subclass = interface -> ux_interface_iad_subclass; - class_command.ux_host_class_command_iad_protocol = interface -> ux_interface_iad_protocol; - - class = _ux_host_stack_class_call(&class_command); - - /* On return, either we have found a class or the interface is still an orphan. */ - if (class != UX_NULL) - { - - /* There is a class. */ - nb_class_owners++; - interface -> ux_interface_class = class; - } - } - - /* point to the next interface until end of the list. */ - interface = interface -> ux_interface_next_interface; - } - - /* Assume no classes. */ - status = UX_NO_CLASS_MATCH; - - /* Check the number of class owner found. */ - if (nb_class_owners != 0) - { - - /* If we have found one or more classes for any of the interfaces, - we can safely do a SET_CONFIGURATION of the device. */ - status = _ux_host_stack_device_configuration_select(configuration); - - /* Check the completion status. */ - if (status == UX_SUCCESS) - { - - /* The device is in the CONFIGURED state, we have to call each of the classes - again with an ACTIVATE signal. */ - interface = configuration -> ux_configuration_first_interface; - - while (interface != UX_NULL) - { - - /* Is there a default interface? */ - if (interface -> ux_interface_descriptor.bAlternateSetting == 0) - { - - /* We have found the default interface. If this interface is owned, - activate its class. */ - class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE; - class_command.ux_host_class_command_container = (VOID *) interface; - - if (interface -> ux_interface_class != UX_NULL) - { - - /* Save the class in the command container */ - class_command.ux_host_class_command_class_ptr = interface -> ux_interface_class; - - /* Send the ACTIVATE command to the class */ - status = interface -> ux_interface_class -> ux_host_class_entry_function(&class_command); - - } - } - - /* Point to the next interface until end of the list. */ - interface = interface -> ux_interface_next_interface; - } - } - } - /* Return operation result. */ return(status); } diff --git a/common/core/src/ux_host_stack_configuration_interface_scan.c b/common/core/src/ux_host_stack_configuration_interface_scan.c new file mode 100644 index 0000000..6f83f3e --- /dev/null +++ b/common/core/src/ux_host_stack_configuration_interface_scan.c @@ -0,0 +1,179 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Host Stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" +#include "ux_host_stack.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_stack_configuration_interface_scan PORTABLE C */ +/* 6.1.4 */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function will scan all default interfaces for a specific */ +/* configuration and call the registered class with the */ +/* Class/SubClass/Protocol of the interface. */ +/* */ +/* INPUT */ +/* */ +/* configuration Configuration pointer */ +/* */ +/* OUTPUT */ +/* */ +/* Result of operation */ +/* */ +/* CALLS */ +/* */ +/* _ux_host_stack_class_call Call class command */ +/* _ux_host_stack_device_configuration_select */ +/* Select configuration */ +/* _ux_host_stack_class_call Call class from host stack */ +/* (ux_host_class_entry_function) Class entry function */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */ +/* */ +/**************************************************************************/ +UINT _ux_host_stack_configuration_interface_scan(UX_CONFIGURATION *configuration) +{ + +UX_INTERFACE *interface; +UINT nb_class_owners; +UX_HOST_CLASS *class; +UX_HOST_CLASS_COMMAND class_command; +UINT status; + + + /* Initialize class owners to 0. */ + nb_class_owners = 0; + + /* Get the first interface container for this configuration. */ + interface = configuration -> ux_configuration_first_interface; + + /* We now scan all the alternate settings 0 for each of the interfaces. */ + while (interface != UX_NULL) + { + + /* Is there a default interface? */ + if(interface -> ux_interface_descriptor.bAlternateSetting == 0) + { + + /* We have a default interface for this configuration. Call each class + with the class\subclass\protocol. We include the IAD for the cdc classes. */ + class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_QUERY; + class_command.ux_host_class_command_container = (VOID *)interface; + class_command.ux_host_class_command_usage = UX_HOST_CLASS_COMMAND_USAGE_CSP; + class_command.ux_host_class_command_class = interface -> ux_interface_descriptor.bInterfaceClass; + class_command.ux_host_class_command_subclass = interface -> ux_interface_descriptor.bInterfaceSubClass; + class_command.ux_host_class_command_protocol = interface -> ux_interface_descriptor.bInterfaceProtocol; + class_command.ux_host_class_command_iad_class = interface -> ux_interface_iad_class ; + class_command.ux_host_class_command_iad_subclass = interface -> ux_interface_iad_subclass; + class_command.ux_host_class_command_iad_protocol = interface -> ux_interface_iad_protocol; + + class = _ux_host_stack_class_call(&class_command); + + /* On return, either we have found a class or the interface is still an orphan. */ + if (class != UX_NULL) + { + + /* There is a class. */ + nb_class_owners++; + interface -> ux_interface_class = class; + } + } + + /* point to the next interface until end of the list. */ + interface = interface -> ux_interface_next_interface; + } + + /* Assume no classes. */ + status = UX_NO_CLASS_MATCH; + + /* Check the number of class owner found. */ + if (nb_class_owners != 0) + { + + /* If we have found one or more classes for any of the interfaces, + we can safely do a SET_CONFIGURATION of the device. */ + status = _ux_host_stack_device_configuration_select(configuration); + + /* Check the completion status. */ + if (status == UX_SUCCESS) + { + + /* The device is in the CONFIGURED state, we have to call each of the classes + again with an ACTIVATE signal. */ + interface = configuration -> ux_configuration_first_interface; + + while (interface != UX_NULL) + { + + /* Is there a default interface? */ + if (interface -> ux_interface_descriptor.bAlternateSetting == 0) + { + + /* We have found the default interface. If this interface is owned, + activate its class. */ + class_command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE; + class_command.ux_host_class_command_container = (VOID *) interface; + + if (interface -> ux_interface_class != UX_NULL) + { + + /* Save the class in the command container */ + class_command.ux_host_class_command_class_ptr = interface -> ux_interface_class; + + /* Send the ACTIVATE command to the class */ + status = interface -> ux_interface_class -> ux_host_class_entry_function(&class_command); + + } + } + + /* Point to the next interface until end of the list. */ + interface = interface -> ux_interface_next_interface; + } + } + } + + /* Return operation result. */ + return(status); +} + diff --git a/common/core/src/ux_host_stack_configuration_set.c b/common/core/src/ux_host_stack_configuration_set.c index 26312d0..4ffba3e 100644 --- a/common/core/src/ux_host_stack_configuration_set.c +++ b/common/core/src/ux_host_stack_configuration_set.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_configuration_set PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,6 +70,10 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used pointer for current */ +/* selected configuration, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_configuration_set(UX_CONFIGURATION *configuration) @@ -150,7 +154,7 @@ UX_HCD *hcd; device -> ux_device_state = UX_DEVICE_CONFIGURED; /* Store the new configuration value in the device container. */ - device -> ux_device_current_configuration = configuration -> ux_configuration_descriptor.bConfigurationValue; + device -> ux_device_current_configuration = configuration; } /* Return status to caller. */ diff --git a/common/core/src/ux_host_stack_device_configuration_activate.c b/common/core/src/ux_host_stack_device_configuration_activate.c new file mode 100644 index 0000000..47f659a --- /dev/null +++ b/common/core/src/ux_host_stack_device_configuration_activate.c @@ -0,0 +1,137 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Host Stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" +#include "ux_host_stack.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_stack_device_configuration_activate PORTABLE C */ +/* 6.1.4 */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function selects a specific configuration for a device. */ +/* When this configuration is set to the device, by default all the */ +/* device interface and their associated alternate setting 0 is */ +/* activated on the device. */ +/* */ +/* INPUT */ +/* */ +/* configuration Pointer to configuration */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_semaphore_get Get semaphore */ +/* _ux_utility_semaphore_put Put semaphore */ +/* _ux_host_stack_configuration_interface_scan Scan and activate */ +/* interfaces */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */ +/* */ +/**************************************************************************/ +UINT _ux_host_stack_device_configuration_activate(UX_CONFIGURATION *configuration) +{ + +UX_DEVICE *device; +UINT status; + + + /* Check for validity of the configuration handle. */ + if (configuration -> ux_configuration_handle != (ULONG) (ALIGN_TYPE) configuration) + { + + /* Error trap. */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_CONFIGURATION_HANDLE_UNKNOWN); + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0) + + return(UX_CONFIGURATION_HANDLE_UNKNOWN); + } + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_ACTIVATE, device, configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) + + /* Get the device container for this configuration. */ + device = configuration -> ux_configuration_device; + + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + { + + /* Error trap. */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_SEMAPHORE_ERROR); + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_SEMAPHORE_ERROR, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0) + + return(UX_SEMAPHORE_ERROR); + } + + /* Check for the state of the device . If the device is already configured, + we need to cancel the existing configuration before enabling this one. */ + if (device -> ux_device_state == UX_DEVICE_CONFIGURED) + { + + /* If this configuration is already activated, we are good, + otherwise report error. */ + status = (device -> ux_device_current_configuration == configuration) ? + UX_SUCCESS : UX_ALREADY_ACTIVATED; + _ux_utility_semaphore_put(&device -> ux_device_protection_semaphore); + return(status); + } + + /* Scan and activate the interfaces. */ + status = _ux_host_stack_configuration_interface_scan(configuration); + + /* Return completion status. */ + return(status); +} diff --git a/common/core/src/ux_host_stack_device_configuration_deactivate.c b/common/core/src/ux_host_stack_device_configuration_deactivate.c new file mode 100644 index 0000000..384b556 --- /dev/null +++ b/common/core/src/ux_host_stack_device_configuration_deactivate.c @@ -0,0 +1,160 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Host Stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" +#include "ux_host_stack.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_stack_device_configuration_deactivate PORTABLE C */ +/* 6.1.4 */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function deactivate current configuration for a device. */ +/* When this configuration is deactivated, all the device interfaces */ +/* are deactivated on the device. */ +/* */ +/* INPUT */ +/* */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_semaphore_get Get semaphore */ +/* _ux_utility_semaphore_put Put semaphore */ +/* (ux_host_class_entry_function) Class entry function */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */ +/* */ +/**************************************************************************/ +UINT _ux_host_stack_device_configuration_deactivate(UX_DEVICE *device) +{ + +UX_HOST_CLASS_COMMAND command; +UX_CONFIGURATION *configuration; +UX_INTERFACE *interface; +UINT status; + + + /* Do a sanity check on the device handle. */ + if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device) + { + + /* Error trap. */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN); + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0) + + return(UX_DEVICE_HANDLE_UNKNOWN); + } + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_DEACTIVATE, device, configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0) + + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + { + + /* Error trap. */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_SEMAPHORE_ERROR); + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_SEMAPHORE_ERROR, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0) + + return(UX_SEMAPHORE_ERROR); + } + + /* Get the configuration. */ + configuration = device -> ux_device_current_configuration; + + /* Check for the state of the device, if not configured, we are done. */ + if (device -> ux_device_state != UX_DEVICE_CONFIGURED) + { + _ux_utility_semaphore_put(&device -> ux_device_protection_semaphore); + return(UX_SUCCESS); + } + + /* Deactivate classes by command. */ + command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE; + + /* Search for the active configuration. */ + configuration = device -> ux_device_current_configuration; + + /* If device configured configuration must be activated. */ + + /* We have the correct configuration, search the interface(s). */ + interface = configuration -> ux_configuration_first_interface; + + /* Loop to perform the search. */ + while (interface != UX_NULL) + { + + /* Check if an instance of the interface is present. */ + if (interface -> ux_interface_class_instance != UX_NULL) + { + + /* We need to stop the class instance for the device. */ + command.ux_host_class_command_instance = interface -> ux_interface_class_instance; + + /* Call the class. */ + interface -> ux_interface_class -> ux_host_class_entry_function(&command); + } + + /* Move to next interface. */ + interface = interface -> ux_interface_next_interface; + } + + /* The device can now be un-configured. */ + status = _ux_host_stack_device_configuration_reset(device); + + /* Return completion status. */ + return(status); +} diff --git a/common/core/src/ux_host_stack_device_configuration_reset.c b/common/core/src/ux_host_stack_device_configuration_reset.c index b340d75..20aa20d 100644 --- a/common/core/src/ux_host_stack_device_configuration_reset.c +++ b/common/core/src/ux_host_stack_device_configuration_reset.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_device_configuration_reset PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -68,6 +68,10 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used pointer for current */ +/* selected configuration, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_device_configuration_reset(UX_DEVICE *device) @@ -92,20 +96,15 @@ UINT status; { /* The device is configured. Get the first configuration pointer. */ - current_configuration = device -> ux_device_first_configuration; - - /* Traverse the configuration list until we find the right one. */ - while (current_configuration -> ux_configuration_descriptor.bConfigurationValue != - device -> ux_device_current_configuration) - { - - current_configuration = current_configuration -> ux_configuration_next_configuration; - } + current_configuration = device -> ux_device_current_configuration; /* Deselect this instance */ _ux_host_stack_configuration_instance_delete(current_configuration); } + /* No configuration is selected now. */ + device -> ux_device_current_configuration = UX_NULL; + /* Set state of device to ATTACHED. */ device -> ux_device_state = UX_DEVICE_ATTACHED; diff --git a/common/core/src/ux_host_stack_device_configuration_select.c b/common/core/src/ux_host_stack_device_configuration_select.c index dd8224a..80597dc 100644 --- a/common/core/src/ux_host_stack_device_configuration_select.c +++ b/common/core/src/ux_host_stack_device_configuration_select.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_device_configuration_select PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -78,6 +78,10 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used pointer for current */ +/* selected configuration, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_device_configuration_select(UX_CONFIGURATION *configuration) @@ -112,15 +116,7 @@ UINT status; { /* The device is configured. Get the first configuration pointer. */ - current_configuration = device -> ux_device_first_configuration; - - /* Traverse the configuration list until we find the right one. */ - while (current_configuration -> ux_configuration_descriptor.bConfigurationValue != - device -> ux_device_current_configuration) - { - - current_configuration = current_configuration -> ux_configuration_next_configuration; - } + current_configuration = device -> ux_device_current_configuration; /* Deselect this instance */ _ux_host_stack_configuration_instance_delete(current_configuration); diff --git a/common/core/src/ux_host_stack_device_remove.c b/common/core/src/ux_host_stack_device_remove.c index 020c900..1a46658 100644 --- a/common/core/src/ux_host_stack_device_remove.c +++ b/common/core/src/ux_host_stack_device_remove.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_device_remove PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -71,6 +71,12 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used pointer for current */ +/* selected configuration, */ +/* added notification for */ +/* device disconnection, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_device_remove(UX_HCD *hcd, UX_DEVICE *parent, UINT port_index) @@ -160,46 +166,42 @@ UX_HOST_CLASS_COMMAND command; { /* Search for the active configuration. */ - configuration = device -> ux_device_first_configuration; + configuration = device -> ux_device_current_configuration; - /* Parse the interface(s) for this device in search of the classes - who own this device. */ - while (configuration != UX_NULL) + /* If configuration is activated. */ + if (configuration != UX_NULL) { - /* Is this the correct configuration? */ - if (configuration -> ux_configuration_descriptor.bConfigurationValue == - device -> ux_device_current_configuration) - { + /* We have the correct configuration, search the interface(s). */ + interface = configuration -> ux_configuration_first_interface; - /* We have the correct configuration, search the interface(s). */ - interface = configuration -> ux_configuration_first_interface; + /* Loop to perform the search. */ + while (interface != UX_NULL) + { - /* Loop to perform the search. */ - while (interface != UX_NULL) + /* Check if an instance of the interface is present. */ + if (interface -> ux_interface_class_instance != UX_NULL) { - /* Check if an instance of the interface is present. */ - if (interface -> ux_interface_class_instance != UX_NULL) - { - - /* We need to stop the class instance for the device. */ - command.ux_host_class_command_instance = interface -> ux_interface_class_instance; + /* We need to stop the class instance for the device. */ + command.ux_host_class_command_instance = interface -> ux_interface_class_instance; - /* Call the class. */ - interface -> ux_interface_class -> ux_host_class_entry_function(&command); - } - - /* Move to next interface. */ - interface = interface -> ux_interface_next_interface; + /* Call the class. */ + interface -> ux_interface_class -> ux_host_class_entry_function(&command); } - } - /* Move to next configuration in the list. */ - configuration = configuration -> ux_configuration_next_configuration; + /* Move to next interface. */ + interface = interface -> ux_interface_next_interface; + } } } + /* Notify application for disconnection of existing physical device. */ + if (_ux_system_host -> ux_system_host_change_function) + { + _ux_system_host -> ux_system_host_change_function(UX_DEVICE_DISCONNECTION, UX_NULL, (VOID*)device); + } + /* Now all the resources for this device must be free. */ _ux_host_stack_device_resources_free(device); diff --git a/common/core/src/ux_host_stack_device_string_get.c b/common/core/src/ux_host_stack_device_string_get.c new file mode 100644 index 0000000..90274ab --- /dev/null +++ b/common/core/src/ux_host_stack_device_string_get.c @@ -0,0 +1,126 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Host Stack */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" +#include "ux_host_class_printer.h" +#include "ux_host_stack.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_stack_device_string_get PORTABLE C */ +/* 6.1.4 */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function obtains the device string descriptor. */ +/* */ +/* INPUT */ +/* */ +/* device Pointer to device instance */ +/* descriptor_buffer Pointer to a buffer to fill */ +/* LANGID or STRING descriptor */ +/* length Length of buffer */ +/* language_id 0 to obtain LANGID descriptor */ +/* valid language ID to obtain */ +/* string descriptor */ +/* string_index Index of the string */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_host_stack_transfer_request Process transfer request */ +/* _ux_utility_semaphore_get Get Semaphore */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */ +/* */ +/**************************************************************************/ +UINT _ux_host_stack_device_string_get(UX_DEVICE *device, UCHAR *descriptor_buffer, ULONG length, ULONG language_id, ULONG string_index) +{ +UX_ENDPOINT *control_endpoint; +UX_TRANSFER *transfer_request; +UINT status; + + + /* Do a sanity check on the device handle. */ + if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device) + { + + /* Error trap. */ + _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN); + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0) + + return(UX_DEVICE_HANDLE_UNKNOWN); + } + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_STRING_GET, device, descriptor_buffer, length, (language_id << 16) | string_index, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) + + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + return(UX_SEMAPHORE_ERROR); + + /* We need to get the default control endpoint transfer request pointer. */ + control_endpoint = &device -> ux_device_control_endpoint; + transfer_request = &control_endpoint -> ux_endpoint_transfer_request; + + /* Create a transfer request for the GET_DEVICE_ID request. */ + transfer_request -> ux_transfer_request_data_pointer = descriptor_buffer; + transfer_request -> ux_transfer_request_requested_length = length; + transfer_request -> ux_transfer_request_function = UX_GET_DESCRIPTOR; + transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; + transfer_request -> ux_transfer_request_value = (UX_STRING_DESCRIPTOR_ITEM << 8) | string_index; + transfer_request -> ux_transfer_request_index = (language_id); + + /* Send request to HCD layer. */ + status = _ux_host_stack_transfer_request(transfer_request); + + /* Return completion status. */ + return(status); +} diff --git a/common/core/src/ux_host_stack_hcd_thread_entry.c b/common/core/src/ux_host_stack_hcd_thread_entry.c index bc0042e..bc0042e 100644..100755 --- a/common/core/src/ux_host_stack_hcd_thread_entry.c +++ b/common/core/src/ux_host_stack_hcd_thread_entry.c diff --git a/common/core/src/ux_host_stack_hcd_unregister.c b/common/core/src/ux_host_stack_hcd_unregister.c index 277cf1a..277cf1a 100644..100755 --- a/common/core/src/ux_host_stack_hcd_unregister.c +++ b/common/core/src/ux_host_stack_hcd_unregister.c diff --git a/common/core/src/ux_host_stack_hnp_polling_thread_entry.c b/common/core/src/ux_host_stack_hnp_polling_thread_entry.c index d185cdf..e57bca6 100644 --- a/common/core/src/ux_host_stack_hnp_polling_thread_entry.c +++ b/common/core/src/ux_host_stack_hnp_polling_thread_entry.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_hnp_polling_thread_entry PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -76,6 +76,10 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* used pointer for current */ +/* selected configuration, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ VOID _ux_host_stack_hnp_polling_thread_entry(ULONG argument) @@ -153,73 +157,58 @@ UINT status; /* We have a device on a OTG port. But is it a OTG HNP capable device ? We need to parse the configuration until we find the one current. */ - configuration = device -> ux_device_first_configuration; + configuration = device -> ux_device_current_configuration; - /* Are we at the of the configuration list ? */ - while (configuration != UX_NULL) + /* Check for OTG HNP support. */ + if (configuration -> ux_configuration_otg_capabilities & UX_OTG_HNP_SUPPORT) { - - /* Is this the current configuration ? */ - if (configuration -> ux_configuration_descriptor.bConfigurationValue == - device -> ux_device_current_configuration) - { - - /* Check for OTG HNP support. */ - if (configuration -> ux_configuration_otg_capabilities & UX_OTG_HNP_SUPPORT) - { - - /* Allocate memory for the OTG status. */ - otg_status = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 16); - - /* Check for status. */ - if (otg_status == UX_NULL) - return; - - /* Retrieve the control endpoint and the transfer request associated with it. */ - control_endpoint = &device -> ux_device_control_endpoint; - transfer_request = &control_endpoint -> ux_endpoint_transfer_request; + + /* Allocate memory for the OTG status. */ + otg_status = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 16); - /* Protect the control endpoint semaphore here. It will be unprotected in the - transfer request function. */ - status = _ux_utility_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + /* Check for status. */ + if (otg_status == UX_NULL) + return; + + /* Retrieve the control endpoint and the transfer request associated with it. */ + control_endpoint = &device -> ux_device_control_endpoint; + transfer_request = &control_endpoint -> ux_endpoint_transfer_request; - /* Perform a GET_STATUS on this device to see if it wants to become the host. */ - /* Create a transfer_request for the SET_CONFIGURATION request. No data for this request. */ - transfer_request -> ux_transfer_request_data_pointer = otg_status; - transfer_request -> ux_transfer_request_requested_length = 1; - transfer_request -> ux_transfer_request_function = UX_GET_STATUS; - transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; - transfer_request -> ux_transfer_request_value = 0; - transfer_request -> ux_transfer_request_index = UX_OTG_STATUS_SELECTOR; - - /* Send request to HCD layer. */ - status = _ux_host_stack_transfer_request(transfer_request); - - /* Check completion status. */ - if(status == UX_SUCCESS && transfer_request -> ux_transfer_request_actual_length == 1) - { - - /* We have an answer from the device. Check the HNP flag. */ - if (*otg_status & UX_OTG_HOST_REQUEST_FLAG) - { + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); - /* The device has requested a Host swap. Initiate the command and perform the - stopping of the host. */ - _ux_host_stack_role_swap(device); - } - - } - - /* Free all used resources. */ - _ux_utility_memory_free(otg_status); + /* Perform a GET_STATUS on this device to see if it wants to become the host. */ + /* Create a transfer_request for the SET_CONFIGURATION request. No data for this request. */ + transfer_request -> ux_transfer_request_data_pointer = otg_status; + transfer_request -> ux_transfer_request_requested_length = 1; + transfer_request -> ux_transfer_request_function = UX_GET_STATUS; + transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE; + transfer_request -> ux_transfer_request_value = 0; + transfer_request -> ux_transfer_request_index = UX_OTG_STATUS_SELECTOR; + + /* Send request to HCD layer. */ + status = _ux_host_stack_transfer_request(transfer_request); + + /* Check completion status. */ + if(status == UX_SUCCESS && transfer_request -> ux_transfer_request_actual_length == 1) + { + + /* We have an answer from the device. Check the HNP flag. */ + if (*otg_status & UX_OTG_HOST_REQUEST_FLAG) + { + /* The device has requested a Host swap. Initiate the command and perform the + stopping of the host. */ + _ux_host_stack_role_swap(device); } + } + + /* Free all used resources. */ + _ux_utility_memory_free(otg_status); - /* Move to next configuration in the list. */ - configuration = configuration -> ux_configuration_next_configuration; - - } + } } } diff --git a/common/core/src/ux_host_stack_new_device_create.c b/common/core/src/ux_host_stack_new_device_create.c index af6a109..e9ee549 100644 --- a/common/core/src/ux_host_stack_new_device_create.c +++ b/common/core/src/ux_host_stack_new_device_create.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_new_device_create PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -59,6 +59,8 @@ /* without creating an */ /* OVER_CURRENT condition on */ /* the bus */ +/* created_device Destination to fill created */ +/* device instance */ /* */ /* OUTPUT */ /* */ @@ -96,11 +98,16 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* added a new parameter to */ +/* return created device, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_new_device_create(UX_HCD *hcd, UX_DEVICE *device_owner, UINT port_index, UINT device_speed, - UINT port_max_power) + UINT port_max_power, + UX_DEVICE **created_device) { UX_DEVICE *device; @@ -138,6 +145,9 @@ UX_ENDPOINT *control_endpoint; return(UX_TOO_MANY_DEVICES); } + /* Store the device instance. */ + *created_device = device; + /* Increment the number of devices on this bus. */ hcd -> ux_hcd_nb_devices++; diff --git a/common/core/src/ux_host_stack_rh_change_process.c b/common/core/src/ux_host_stack_rh_change_process.c index ccce8e8..ccce8e8 100644..100755 --- a/common/core/src/ux_host_stack_rh_change_process.c +++ b/common/core/src/ux_host_stack_rh_change_process.c diff --git a/common/core/src/ux_host_stack_rh_device_insertion.c b/common/core/src/ux_host_stack_rh_device_insertion.c index a30ed4a..6e33f47 100644 --- a/common/core/src/ux_host_stack_rh_device_insertion.c +++ b/common/core/src/ux_host_stack_rh_device_insertion.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_stack_rh_device_insertion PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -73,11 +73,20 @@ /* checked HCD status before */ /* retrying enumeration, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* handled more fail cases, */ +/* updated internal call, */ +/* added notification for */ +/* device connection, */ +/* added disconnection check */ +/* in enumeration retries, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_stack_rh_device_insertion(UX_HCD *hcd, UINT port_index) { +UX_DEVICE *device; UINT index_loop; UINT device_speed; ULONG port_status; @@ -125,12 +134,20 @@ UINT status; return(UX_DEVICE_ENUMERATION_FAILURE); } + /* Check if device is still connected. */ + if ((port_status & UX_PS_CCS) == 0) + { + + /* Device disconnected during enumeration retries. */ + return(UX_DEVICE_ENUMERATION_FAILURE); + } + /* Set the device speed. */ device_speed = port_status >> UX_PS_DS; /* Ask the USB stack to enumerate this device. A root hub is considered self powered. */ - status = _ux_host_stack_new_device_create(hcd, UX_NULL, port_index, device_speed, UX_MAX_SELF_POWER); + status = _ux_host_stack_new_device_create(hcd, UX_NULL, port_index, device_speed, UX_MAX_SELF_POWER, &device); /* Check return status. */ if (status == UX_SUCCESS) @@ -143,6 +160,12 @@ UINT status; function again */ hcd -> ux_hcd_rh_device_connection |= (ULONG)(1 << port_index); + /* If the device instance is ready, notify application for connection. */ + if (_ux_system_host -> ux_system_host_change_function) + { + _ux_system_host -> ux_system_host_change_function(UX_DEVICE_CONNECTION, UX_NULL, (VOID*)device); + } + /* Return success to the caller. */ return(UX_SUCCESS); } @@ -153,10 +176,18 @@ UINT status; if (hcd -> ux_hcd_status != UX_HCD_STATUS_OPERATIONAL) return(UX_CONTROLLER_DEAD); + /* No retry if there are too many devices. */ + if (status == UX_TOO_MANY_DEVICES) + break; + + /* No retry if there is no class found. */ + if (status == UX_NO_CLASS_MATCH) + break; + /* Simulate remove to free allocated resources if retry. */ if (index_loop < UX_RH_ENUMERATION_RETRY - 1) - _ux_host_stack_device_remove(hcd, UX_NULL, port_index); - } + _ux_host_stack_device_remove(hcd, UX_NULL, port_index); + } } /* We get here if something did not go well. Either the port did not respond @@ -165,10 +196,19 @@ UINT status; _ux_utility_delay_ms(UX_RH_ENUMERATION_RETRY_DELAY); } - /* If we get here, the device did not enumerate completely. The device is still attached to the root - hub and therefore there is a physical connection with a unenumerated device. */ + /* If we get here, the device did not enumerate completely. + The device is still attached to the root hub and therefore + there could be a physical connection with a unconfigured device. */ hcd -> ux_hcd_rh_device_connection |= (ULONG)(1 << port_index); + /* Notify application for a physical connection failed to be enumed. + Device instance NULL indicates too many devices. + Device state unconfigured indicates enumeration fail. */ + if (_ux_system_host -> ux_system_host_change_function) + { + _ux_system_host -> ux_system_host_change_function(UX_DEVICE_CONNECTION, UX_NULL, (VOID*)device); + } + /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE); diff --git a/common/core/src/ux_utility_delay_ms.c b/common/core/src/ux_utility_delay_ms.c index e996b04..e996b04 100644..100755 --- a/common/core/src/ux_utility_delay_ms.c +++ b/common/core/src/ux_utility_delay_ms.c diff --git a/common/usbx_device_classes/src/ux_device_class_hid_control_request.c b/common/usbx_device_classes/src/ux_device_class_hid_control_request.c index f5c9d10..f5c9d10 100644..100755 --- a/common/usbx_device_classes/src/ux_device_class_hid_control_request.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_control_request.c diff --git a/common/usbx_host_classes/CMakeLists.txt b/common/usbx_host_classes/CMakeLists.txt index 35edc22..4088019 100644 --- a/common/usbx_host_classes/CMakeLists.txt +++ b/common/usbx_host_classes/CMakeLists.txt @@ -167,6 +167,7 @@ target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_activate.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_configure.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_deactivate.c + ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_device_id_get.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_endpoints_get.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_entry.c ${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_printer_name_get.c diff --git a/common/usbx_host_classes/inc/ux_host_class_cdc_ecm.h b/common/usbx_host_classes/inc/ux_host_class_cdc_ecm.h index ae5e1c8..f139d03 100644 --- a/common/usbx_host_classes/inc/ux_host_class_cdc_ecm.h +++ b/common/usbx_host_classes/inc/ux_host_class_cdc_ecm.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* ux_host_class_cdc_ecm.h PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -46,6 +46,10 @@ /* TX symbols instead of using */ /* them directly, */ /* resulting in version 6.1 */ +/* 02-02-2021 Xiuwen Cai Modified comment(s), added */ +/* compile option for using */ +/* packet pool from NetX, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ @@ -210,6 +214,12 @@ #define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT 1000 #endif +/* Define packet pool waiting time in milliseconds. */ + +#ifndef UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT +#define UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT 100 +#endif + /* Define CDC_ECM Class instance structure. */ typedef struct UX_HOST_CLASS_CDC_ECM_STRUCT @@ -246,8 +256,13 @@ typedef struct UX_HOST_CLASS_CDC_ECM_STRUCT ULONG ux_host_class_cdc_ecm_link_state; NX_PACKET *ux_host_class_cdc_ecm_xmit_queue_head; NX_PACKET *ux_host_class_cdc_ecm_xmit_queue_tail; +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX NX_PACKET_POOL ux_host_class_cdc_ecm_packet_pool; UCHAR *ux_host_class_cdc_ecm_pool_memory; +#else + NX_PACKET_POOL *ux_host_class_cdc_ecm_packet_pool; +#endif + UCHAR ux_host_class_cdc_ecm_node_id[UX_HOST_CLASS_CDC_ECM_NODE_ID_LENGTH]; VOID (*ux_host_class_cdc_ecm_device_status_change_callback)(struct UX_HOST_CLASS_CDC_ECM_STRUCT *cdc_ecm, ULONG device_state); diff --git a/common/usbx_host_classes/inc/ux_host_class_printer.h b/common/usbx_host_classes/inc/ux_host_class_printer.h index 8caa2eb..933c5ba 100644 --- a/common/usbx_host_classes/inc/ux_host_class_printer.h +++ b/common/usbx_host_classes/inc/ux_host_class_printer.h @@ -103,6 +103,7 @@ UINT _ux_host_class_printer_deactivate(UX_HOST_CLASS_COMMAND *command); UINT _ux_host_class_printer_endpoints_get(UX_HOST_CLASS_PRINTER *printer); UINT _ux_host_class_printer_entry(UX_HOST_CLASS_COMMAND *command); UINT _ux_host_class_printer_name_get(UX_HOST_CLASS_PRINTER *printer); +UINT _ux_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER *printer, UCHAR *descriptor_buffer, ULONG length); UINT _ux_host_class_printer_read (UX_HOST_CLASS_PRINTER *printer, UCHAR *data_pointer, ULONG requested_length, ULONG *actual_length); UINT _ux_host_class_printer_soft_reset(UX_HOST_CLASS_PRINTER *printer); @@ -114,6 +115,7 @@ UINT _ux_host_class_printer_write(UX_HOST_CLASS_PRINTER *printer, UCHAR * dat #define ux_host_class_printer_activate _ux_host_class_printer_activate #define ux_host_class_printer_name_get _ux_host_class_printer_name_get +#define ux_host_class_printer_device_id_get _ux_host_class_printer_device_id_get #define ux_host_class_printer_read _ux_host_class_printer_read #define ux_host_class_printer_soft_reset _ux_host_class_printer_soft_reset #define ux_host_class_printer_status_get _ux_host_class_printer_status_get diff --git a/common/usbx_host_classes/inc/ux_host_class_storage.h b/common/usbx_host_classes/inc/ux_host_class_storage.h index 977d66c..977d66c 100644..100755 --- a/common/usbx_host_classes/inc/ux_host_class_storage.h +++ b/common/usbx_host_classes/inc/ux_host_class_storage.h diff --git a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_activate.c b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_activate.c index 91b7f5b..cdc9b39 100644 --- a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_activate.c +++ b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_activate.c @@ -36,7 +36,7 @@ UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE_ASSERT /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_ecm_activate PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -85,6 +85,10 @@ UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE_ASSERT /* TX symbols instead of using */ /* them directly, */ /* resulting in version 6.1 */ +/* 02-02-2021 Xiuwen Cai Modified comment(s), added */ +/* compile option for using */ +/* packet pool from NetX, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_class_cdc_ecm_activate(UX_HOST_CLASS_COMMAND *command) @@ -193,7 +197,7 @@ UX_INTERFACE *cur_interface; if (cdc_ecm -> ux_host_class_cdc_ecm_thread_stack == UX_NULL) status = UX_MEMORY_INSUFFICIENT; } - +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX if (status == UX_SUCCESS) { @@ -205,7 +209,7 @@ UX_INTERFACE *cur_interface; if (cdc_ecm -> ux_host_class_cdc_ecm_pool_memory == UX_NULL) status = UX_MEMORY_INSUFFICIENT; } - +#endif if (status == UX_SUCCESS) { @@ -225,13 +229,13 @@ UX_INTERFACE *cur_interface; status = _ux_utility_semaphore_create(&cdc_ecm -> ux_host_class_cdc_ecm_interrupt_notification_semaphore, "host CDC-ECM interrupt notification semaphore", 0); if (status == UX_SUCCESS) { - +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX /* Create a packet pool. */ status = nx_packet_pool_create(&cdc_ecm -> ux_host_class_cdc_ecm_packet_pool, "host CDC-ECM packet pool", UX_HOST_CLASS_CDC_ECM_NX_PAYLOAD_SIZE, cdc_ecm -> ux_host_class_cdc_ecm_pool_memory, UX_HOST_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE); if (status == UX_SUCCESS) { - +#endif /* Create the cdc_ecm class thread. We do not start it yet. */ status = _ux_utility_thread_create(&cdc_ecm -> ux_host_class_cdc_ecm_thread, "ux_host_cdc_ecm_thread", _ux_host_class_cdc_ecm_thread, @@ -334,7 +338,7 @@ UX_INTERFACE *cur_interface; /* Delete CDC-ECM thread. */ _ux_utility_thread_delete(&cdc_ecm -> ux_host_class_cdc_ecm_thread); } - +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX /* Delete packet pool. */ nx_packet_pool_delete(&cdc_ecm -> ux_host_class_cdc_ecm_packet_pool); } @@ -344,7 +348,7 @@ UX_INTERFACE *cur_interface; /* Packet pool creation failed. Notify application. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, status); } - +#endif /* Delete interrupt notification semaphore. */ _ux_utility_semaphore_delete(&cdc_ecm -> ux_host_class_cdc_ecm_interrupt_notification_semaphore); } @@ -363,10 +367,10 @@ UX_INTERFACE *cur_interface; if (cdc_ecm -> ux_host_class_cdc_ecm_interrupt_endpoint != UX_NULL && cdc_ecm -> ux_host_class_cdc_ecm_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer != UX_NULL) _ux_utility_memory_free(cdc_ecm -> ux_host_class_cdc_ecm_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_data_pointer); - +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX if (cdc_ecm -> ux_host_class_cdc_ecm_pool_memory != UX_NULL) _ux_utility_memory_free(cdc_ecm -> ux_host_class_cdc_ecm_pool_memory); - +#endif if (cdc_ecm -> ux_host_class_cdc_ecm_thread_stack != UX_NULL) _ux_utility_memory_free(cdc_ecm -> ux_host_class_cdc_ecm_thread_stack); diff --git a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_deactivate.c b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_deactivate.c index a2d1aae..6fc0e85 100644 --- a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_deactivate.c +++ b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_deactivate.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_ecm_deactivate PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -77,6 +77,10 @@ /* TX symbols instead of using */ /* them directly, */ /* resulting in version 6.1 */ +/* 02-02-2021 Xiuwen Cai Modified comment(s), added */ +/* compile option for using */ +/* packet pool from NetX, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_class_cdc_ecm_deactivate(UX_HOST_CLASS_COMMAND *command) @@ -179,13 +183,13 @@ UX_TRANSFER *transfer_request; /* Destroy the notification semaphore. */ _ux_utility_semaphore_delete(&cdc_ecm -> ux_host_class_cdc_ecm_interrupt_notification_semaphore); - +#ifndef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX /* Delete the packet pool. */ nx_packet_pool_delete(&cdc_ecm -> ux_host_class_cdc_ecm_packet_pool); /* Free this pool of packets. */ _ux_utility_memory_free(cdc_ecm -> ux_host_class_cdc_ecm_pool_memory); - +#endif /* Before we free the device resources, we need to inform the application that the device is removed. */ if (_ux_system_host -> ux_system_host_change_function != UX_NULL) diff --git a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_thread.c b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_thread.c index af76f64..6911d59 100644 --- a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_thread.c +++ b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_thread.c @@ -34,7 +34,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_ecm_thread PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -82,6 +82,10 @@ /* TX symbols instead of using */ /* them directly, */ /* resulting in version 6.1 */ +/* 02-02-2021 Xiuwen Cai Modified comment(s), added */ +/* compile option for using */ +/* packet pool from NetX, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ VOID _ux_host_class_cdc_ecm_thread(ULONG parameter) @@ -92,6 +96,9 @@ UX_TRANSFER *transfer_request; NX_PACKET *packet; ULONG ip_given_length; UINT status; +#ifdef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX +USB_NETWORK_DEVICE_TYPE *usb_network_device_ptr; +#endif /* Cast the parameter passed in the thread into the cdc_ecm pointer. */ UX_THREAD_EXTENSION_PTR_GET(cdc_ecm, UX_HOST_CLASS_CDC_ECM, parameter) @@ -117,11 +124,41 @@ UINT status; while ((cdc_ecm -> ux_host_class_cdc_ecm_link_state == UX_HOST_CLASS_CDC_ECM_LINK_STATE_UP) && (cdc_ecm -> ux_host_class_cdc_ecm_device -> ux_device_state == UX_DEVICE_CONFIGURED)) { +#ifdef UX_HOST_CLASS_CDC_ECM_USE_PACKET_POOL_FROM_NETX + + /* Check if we have packet pool available. */ + if (cdc_ecm -> ux_host_class_cdc_ecm_packet_pool == UX_NULL) + { + + /* Get the network device handle. */ + usb_network_device_ptr = (USB_NETWORK_DEVICE_TYPE *)(cdc_ecm -> ux_host_class_cdc_ecm_network_handle); + + /* Check if IP instance is available. */ + if (usb_network_device_ptr -> ux_network_device_ip_instance != UX_NULL) + { + + /* Get the packet pool from IP instance. */ + cdc_ecm -> ux_host_class_cdc_ecm_packet_pool = usb_network_device_ptr -> ux_network_device_ip_instance -> nx_ip_default_packet_pool; + } + else + { + + /* IP instance is not available, wait for application to attach the interface. */ + _ux_utility_delay_ms(UX_HOST_CLASS_CDC_ECM_PACKET_POOL_INSTANCE_WAIT); + } + continue; + } + + /* We can accept reception. Get a NX Packet. */ + status = nx_packet_allocate(cdc_ecm -> ux_host_class_cdc_ecm_packet_pool, &packet, + NX_RECEIVE_PACKET, UX_MS_TO_TICK(UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT)); +#else /* We can accept reception. Get a NX Packet. */ status = nx_packet_allocate(&cdc_ecm -> ux_host_class_cdc_ecm_packet_pool, &packet, NX_RECEIVE_PACKET, UX_MS_TO_TICK(UX_HOST_CLASS_CDC_ECM_PACKET_POOL_WAIT)); +#endif if (status == NX_SUCCESS) { diff --git a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_transmission_callback.c b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_transmission_callback.c index 82095e6..d088f00 100644 --- a/common/usbx_host_classes/src/ux_host_class_cdc_ecm_transmission_callback.c +++ b/common/usbx_host_classes/src/ux_host_class_cdc_ecm_transmission_callback.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_cdc_ecm_transmission_callback PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,6 +70,9 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), fixed */ +/* ZLP issue for transmission, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ VOID _ux_host_class_cdc_ecm_transmission_callback(UX_TRANSFER *transfer_request) @@ -111,7 +114,22 @@ UCHAR *packet_header; /* Check the state of the transfer. */ if (transfer_request -> ux_transfer_request_completion_code == UX_SUCCESS) { - + + /* Check if the transfer length is not zero and it is multiple of MPS. */ + if ((transfer_request -> ux_transfer_request_requested_length != 0) && + (transfer_request -> ux_transfer_request_requested_length % (transfer_request -> ux_transfer_request_endpoint -> ux_endpoint_descriptor.wMaxPacketSize & UX_MAX_PACKET_SIZE_MASK)) == 0) + { + + /* Set transfer request length to zero. */ + transfer_request -> ux_transfer_request_requested_length = 0; + + /* Send the transfer. */ + _ux_host_stack_transfer_request(transfer_request); + + /* Finished processing. */ + return; + } + /* Get the next packet associated with the first packet. */ next_packet = current_packet -> nx_packet_queue_next; diff --git a/common/usbx_host_classes/src/ux_host_class_hub_port_change_connection_process.c b/common/usbx_host_classes/src/ux_host_class_hub_port_change_connection_process.c index fb4f7bf..db704f8 100644 --- a/common/usbx_host_classes/src/ux_host_class_hub_port_change_connection_process.c +++ b/common/usbx_host_classes/src/ux_host_class_hub_port_change_connection_process.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_hub_port_change_connection_process PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -77,11 +77,20 @@ /* optimized based on compile */ /* definitions, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* handled more fail cases, */ +/* updated internal call, */ +/* added notification for */ +/* device connection, */ +/* added disconnection check */ +/* in enumeration retries, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ VOID _ux_host_class_hub_port_change_connection_process(UX_HOST_CLASS_HUB *hub, UINT port, UINT port_status) { +UX_DEVICE *device = UX_NULL; UINT device_speed; UINT device_enumeration_retry; USHORT port_power; @@ -137,6 +146,10 @@ USHORT local_port_change; if (status != UX_SUCCESS) return; + /* Check if device is still connected. */ + if ((local_port_status & UX_HOST_CLASS_HUB_PORT_STATUS_CONNECTION) == 0) + return; + /* Device connected. Get the device speed. */ if (local_port_status & UX_HOST_CLASS_HUB_PORT_STATUS_LOW_SPEED) device_speed = UX_LOW_SPEED_DEVICE; @@ -166,28 +179,56 @@ USHORT local_port_change; /* Perform the device creation. */ status = _ux_host_stack_new_device_create(UX_DEVICE_HCD_GET(hub -> ux_host_class_hub_device), hub -> ux_host_class_hub_device, - port, device_speed, port_power); + port, device_speed, port_power, + &device); /* Check return status. */ if (status == UX_SUCCESS) { /* Successful device creation. */ + + /* If the device instance is ready, notify application for unconfigured device. */ + if (_ux_system_host -> ux_system_host_change_function) + { + _ux_system_host -> ux_system_host_change_function(UX_DEVICE_CONNECTION, UX_NULL, (VOID*)device); + } + /* Just return. */ return; } - else if (device_enumeration_retry < UX_HOST_CLASS_HUB_ENUMERATION_RETRY - 1) + else { - /* Simulate remove to free allocated resources before retry. */ - _ux_host_stack_device_remove(hcd, hub -> ux_host_class_hub_device, port); + /* No retry if there are too many devices. */ + if (status == UX_TOO_MANY_DEVICES) + break; + + /* No retry if there is no class found. */ + if (status == UX_NO_CLASS_MATCH) + break; - /* Wait for a while. */ - _ux_utility_delay_ms(UX_HOST_CLASS_HUB_ENUMERATION_RETRY_DELAY); + if (device_enumeration_retry < UX_HOST_CLASS_HUB_ENUMERATION_RETRY - 1) + { + + /* Simulate remove to free allocated resources before retry. */ + _ux_host_stack_device_remove(hcd, hub -> ux_host_class_hub_device, port); + + /* Wait for a while. */ + _ux_utility_delay_ms(UX_HOST_CLASS_HUB_ENUMERATION_RETRY_DELAY); + } } } - /* If we get here, the device did not enumerate completely. */ + /* If we get here, the device did not enumerate completely. + The device is still attached to the hub and therefore there is a + physical connection with a unenumerated device. */ + + /* If the device instance is ready, notify application for unconfigured device. */ + if (_ux_system_host -> ux_system_host_change_function) + { + _ux_system_host -> ux_system_host_change_function(UX_DEVICE_CONNECTION, UX_NULL, (VOID*)device); + } /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE); diff --git a/common/usbx_host_classes/src/ux_host_class_printer_device_id_get.c b/common/usbx_host_classes/src/ux_host_class_printer_device_id_get.c new file mode 100644 index 0000000..5601fad --- /dev/null +++ b/common/usbx_host_classes/src/ux_host_class_printer_device_id_get.c @@ -0,0 +1,132 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** USBX Component */ +/** */ +/** Printer Class */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/* Include necessary system files. */ + +#define UX_SOURCE_CODE + +#include "ux_api.h" +#include "ux_host_class_printer.h" +#include "ux_host_stack.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_class_printer_device_id_get PORTABLE C */ +/* 6.1.4 */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function obtains the printer IEEE 1284 device ID string */ +/* (including length in the first two bytes in big endian format). */ +/* */ +/* INPUT */ +/* */ +/* printer Pointer to printer class */ +/* descriptor_buffer Pointer to a buffer to fill */ +/* IEEE 1284 device ID string */ +/* (including length in the */ +/* first two bytes in BE format) */ +/* length Length of buffer in bytes */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_host_stack_transfer_request Process transfer request */ +/* _ux_utility_memory_allocate Allocate memory block */ +/* _ux_utility_memory_compare Compare memory block */ +/* _ux_utility_memory_copy Copy memory block */ +/* _ux_utility_memory_free Free memory block */ +/* _ux_utility_short_get_big_endian Get 16-bit value */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 02-02-2021 Chaoqiong Xiao Initial Version 6.1.4 */ +/* */ +/**************************************************************************/ +UINT _ux_host_class_printer_device_id_get(UX_HOST_CLASS_PRINTER *printer, UCHAR *descriptor_buffer, ULONG length) +{ +UX_INTERFACE *interface; +UX_ENDPOINT *control_endpoint; +UX_TRANSFER *transfer_request; +UINT status; + + + /* If trace is enabled, insert this event into the trace buffer. */ + UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PRINTER_DEVICE_ID_GET, printer, descriptor_buffer, length, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) + + /* Protect thread reentry to this instance. */ + status = _ux_utility_semaphore_get(&printer -> ux_host_class_printer_semaphore, UX_WAIT_FOREVER); + if (status != UX_SUCCESS) + return(status); + + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&printer -> ux_host_class_printer_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + { + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + return(status); + } + + /* We need to get the default control endpoint transfer request pointer. */ + control_endpoint = &printer -> ux_host_class_printer_device -> ux_device_control_endpoint; + transfer_request = &control_endpoint -> ux_endpoint_transfer_request; + + /* Need interface for wIndex. */ + interface = printer -> ux_host_class_printer_interface; + + /* Create a transfer request for the GET_DEVICE_ID request. */ + transfer_request -> ux_transfer_request_data_pointer = descriptor_buffer; + transfer_request -> ux_transfer_request_requested_length = length; + transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_PRINTER_GET_DEVICE_ID; + transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; + transfer_request -> ux_transfer_request_value = 0; /* Do not support multiple configuration for now. */ + transfer_request -> ux_transfer_request_index = (interface -> ux_interface_descriptor.bInterfaceNumber << 8) | + (interface -> ux_interface_descriptor.bAlternateSetting ); + + /* Send request to HCD layer. */ + status = _ux_host_stack_transfer_request(transfer_request); + + /* Unprotect thread reentry to this instance. */ + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + + /* Return completion status. */ + return(status); +} diff --git a/common/usbx_host_classes/src/ux_host_class_printer_name_get.c b/common/usbx_host_classes/src/ux_host_class_printer_name_get.c index 073ffc7..7e500e0 100644 --- a/common/usbx_host_classes/src/ux_host_class_printer_name_get.c +++ b/common/usbx_host_classes/src/ux_host_class_printer_name_get.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_printer_name_get PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -64,7 +64,7 @@ /* */ /* CALLED BY */ /* */ -/* Application */ +/* Printer Class */ /* */ /* RELEASE HISTORY */ /* */ @@ -75,6 +75,10 @@ /* verified memset and memcpy */ /* cases, */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* supported interface other */ +/* than number zero, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_class_printer_name_get(UX_HOST_CLASS_PRINTER *printer) @@ -83,6 +87,7 @@ UINT _ux_host_class_printer_name_get(UX_HOST_CLASS_PRINTER *printer) UCHAR * descriptor_buffer; UCHAR * printer_name_buffer; UCHAR * printer_name; +UX_INTERFACE *interface; UX_ENDPOINT *control_endpoint; UX_TRANSFER *transfer_request; UINT status; @@ -101,13 +106,17 @@ UINT printer_name_length; if(descriptor_buffer == UX_NULL) return(UX_MEMORY_INSUFFICIENT); + /* Need interface for wIndex. */ + interface = printer -> ux_host_class_printer_interface; + /* Create a transfer request for the GET_DEVICE_ID request. */ transfer_request -> ux_transfer_request_data_pointer = descriptor_buffer; transfer_request -> ux_transfer_request_requested_length = UX_HOST_CLASS_PRINTER_DESCRIPTOR_LENGTH; transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_PRINTER_GET_DEVICE_ID; transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; - transfer_request -> ux_transfer_request_value = 0; - transfer_request -> ux_transfer_request_index = 0; + transfer_request -> ux_transfer_request_value = 0; /* Do not support multiple configuration for now. */ + transfer_request -> ux_transfer_request_index = (interface -> ux_interface_descriptor.bInterfaceNumber << 8) | + (interface -> ux_interface_descriptor.bAlternateSetting ); /* Send request to HCD layer. */ status = _ux_host_stack_transfer_request(transfer_request); diff --git a/common/usbx_host_classes/src/ux_host_class_printer_soft_reset.c b/common/usbx_host_classes/src/ux_host_class_printer_soft_reset.c index 3058896..7b81a1d 100644 --- a/common/usbx_host_classes/src/ux_host_class_printer_soft_reset.c +++ b/common/usbx_host_classes/src/ux_host_class_printer_soft_reset.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_printer_soft_reset PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -70,12 +70,17 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* supported interface other */ +/* than number zero, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_class_printer_soft_reset(UX_HOST_CLASS_PRINTER *printer) { +UX_INTERFACE *interface; UX_ENDPOINT *control_endpoint; UX_TRANSFER *transfer_request; UINT status; @@ -103,23 +108,37 @@ UINT status; /* Return error. */ return(status); + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&printer -> ux_host_class_printer_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + { + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + return(status); + } + /* We need to get the default control endpoint transfer request pointer. */ control_endpoint = &printer -> ux_host_class_printer_device -> ux_device_control_endpoint; transfer_request = &control_endpoint -> ux_endpoint_transfer_request; + /* Need interface for wIndex. */ + interface = printer -> ux_host_class_printer_interface; + /* Create a transfer_request for the SOFT_RESET request. */ transfer_request -> ux_transfer_request_data_pointer = UX_NULL; transfer_request -> ux_transfer_request_requested_length = 0; transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_PRINTER_SOFT_RESET; transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; transfer_request -> ux_transfer_request_value = 0; - transfer_request -> ux_transfer_request_index = 0; + transfer_request -> ux_transfer_request_index = interface -> ux_interface_descriptor.bInterfaceNumber; /* Send request to HCD layer. */ status = _ux_host_stack_transfer_request(transfer_request); /* Unprotect thread reentry to this instance. */ - status = _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); /* Return completion status. */ return(status); diff --git a/common/usbx_host_classes/src/ux_host_class_printer_status_get.c b/common/usbx_host_classes/src/ux_host_class_printer_status_get.c index 164490c..052a7fe 100644 --- a/common/usbx_host_classes/src/ux_host_class_printer_status_get.c +++ b/common/usbx_host_classes/src/ux_host_class_printer_status_get.c @@ -35,7 +35,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_printer_status_get PORTABLE C */ -/* 6.1 */ +/* 6.1.4 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -75,11 +75,16 @@ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* 02-02-2021 Chaoqiong Xiao Modified comment(s), */ +/* supported interface other */ +/* than number zero, */ +/* resulting in version 6.1.4 */ /* */ /**************************************************************************/ UINT _ux_host_class_printer_status_get(UX_HOST_CLASS_PRINTER *printer, ULONG *printer_status) { +UX_INTERFACE *interface; UX_ENDPOINT *control_endpoint; UX_TRANSFER *transfer_request; UINT status; @@ -102,6 +107,17 @@ UCHAR * printer_status_buffer; /* Return error. */ return(status); + /* Protect the control endpoint semaphore here. It will be unprotected in the + transfer request function. */ + status = _ux_utility_semaphore_get(&printer -> ux_host_class_printer_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER); + + /* Check for status. */ + if (status != UX_SUCCESS) + { + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + return(status); + } + /* We need to get the default control endpoint transfer_request pointer. */ control_endpoint = &printer -> ux_host_class_printer_device -> ux_device_control_endpoint; transfer_request = &control_endpoint -> ux_endpoint_transfer_request; @@ -116,13 +132,16 @@ UCHAR * printer_status_buffer; return(UX_MEMORY_INSUFFICIENT); } + /* Need interface for wIndex. */ + interface = printer -> ux_host_class_printer_interface; + /* Create a transfer_request for the GET_STATUS request. */ transfer_request -> ux_transfer_request_data_pointer = printer_status_buffer; transfer_request -> ux_transfer_request_requested_length = UX_HOST_CLASS_PRINTER_STATUS_LENGTH; transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_PRINTER_GET_STATUS; transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; transfer_request -> ux_transfer_request_value = 0; - transfer_request -> ux_transfer_request_index = 0; + transfer_request -> ux_transfer_request_index = interface -> ux_interface_descriptor.bInterfaceNumber; /* Send request to HCD layer. */ status = _ux_host_stack_transfer_request(transfer_request); @@ -156,7 +175,7 @@ UCHAR * printer_status_buffer; _ux_utility_memory_free(printer_status_buffer); /* Unprotect thread reentry to this instance. */ - status = _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); + _ux_utility_semaphore_put(&printer -> ux_host_class_printer_semaphore); /* Return completion status. */ return(status); diff --git a/common/usbx_host_classes/src/ux_host_class_storage_entry.c b/common/usbx_host_classes/src/ux_host_class_storage_entry.c index d8e1c09..d8e1c09 100644..100755 --- a/common/usbx_host_classes/src/ux_host_class_storage_entry.c +++ b/common/usbx_host_classes/src/ux_host_class_storage_entry.c diff --git a/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c b/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c index c3e17fa..c3e17fa 100644..100755 --- a/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c +++ b/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c diff --git a/common/usbx_host_classes/src/ux_host_class_video_frame_interval_get.c b/common/usbx_host_classes/src/ux_host_class_video_frame_interval_get.c index 2bb2b3c..2bb2b3c 100644..100755 --- a/common/usbx_host_classes/src/ux_host_class_video_frame_interval_get.c +++ b/common/usbx_host_classes/src/ux_host_class_video_frame_interval_get.c diff --git a/common/usbx_host_controllers/inc/ux_hcd_ehci.h b/common/usbx_host_controllers/inc/ux_hcd_ehci.h index 2154558..2154558 100644..100755 --- a/common/usbx_host_controllers/inc/ux_hcd_ehci.h +++ b/common/usbx_host_controllers/inc/ux_hcd_ehci.h diff --git a/common/usbx_host_controllers/inc/ux_hcd_ohci.h b/common/usbx_host_controllers/inc/ux_hcd_ohci.h index 47de75e..47de75e 100644..100755 --- a/common/usbx_host_controllers/inc/ux_hcd_ohci.h +++ b/common/usbx_host_controllers/inc/ux_hcd_ohci.h diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_asynchronous_endpoint_create.c b/common/usbx_host_controllers/src/ux_hcd_ehci_asynchronous_endpoint_create.c index 0d03bbd..0d03bbd 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_asynchronous_endpoint_create.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_asynchronous_endpoint_create.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_done_queue_process.c b/common/usbx_host_controllers/src/ux_hcd_ehci_done_queue_process.c index d04571e..d04571e 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_done_queue_process.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_done_queue_process.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_hsisochronous_tds_process.c b/common/usbx_host_controllers/src/ux_hcd_ehci_hsisochronous_tds_process.c index 9f7593c..9f7593c 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_hsisochronous_tds_process.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_hsisochronous_tds_process.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_create.c b/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_create.c index e57dd13..e57dd13 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_create.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_create.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_destroy.c b/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_destroy.c index 9b99668..9b99668 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_destroy.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_interrupt_endpoint_destroy.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_create.c b/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_create.c index 2c594c2..2c594c2 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_create.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_create.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_destroy.c b/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_destroy.c index bc5c15f..bc5c15f 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_destroy.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_isochronous_endpoint_destroy.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_least_traffic_list_get.c b/common/usbx_host_controllers/src/ux_hcd_ehci_least_traffic_list_get.c index 8611ef2..8611ef2 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_least_traffic_list_get.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_least_traffic_list_get.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_periodic_tree_create.c b/common/usbx_host_controllers/src/ux_hcd_ehci_periodic_tree_create.c index df4a1b1..df4a1b1 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_periodic_tree_create.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_periodic_tree_create.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_poll_rate_entry_get.c b/common/usbx_host_controllers/src/ux_hcd_ehci_poll_rate_entry_get.c index 5e3c229..5e3c229 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_poll_rate_entry_get.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_poll_rate_entry_get.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_request_control_transfer.c b/common/usbx_host_controllers/src/ux_hcd_ehci_request_control_transfer.c index 5eedf16..5eedf16 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_request_control_transfer.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_request_control_transfer.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ehci_transfer_abort.c b/common/usbx_host_controllers/src/ux_hcd_ehci_transfer_abort.c index aa12ab0..aa12ab0 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ehci_transfer_abort.c +++ b/common/usbx_host_controllers/src/ux_hcd_ehci_transfer_abort.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_error_clear.c b/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_error_clear.c index e3bfbaf..e3bfbaf 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_error_clear.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_error_clear.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_reset.c b/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_reset.c index bb32a5a..bb32a5a 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_reset.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_endpoint_reset.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_periodic_endpoint_destroy.c b/common/usbx_host_controllers/src/ux_hcd_ohci_periodic_endpoint_destroy.c index bd4777d..bd4777d 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_periodic_endpoint_destroy.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_periodic_endpoint_destroy.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_port_resume.c b/common/usbx_host_controllers/src/ux_hcd_ohci_port_resume.c index e66ead6..e66ead6 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_port_resume.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_port_resume.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_port_suspend.c b/common/usbx_host_controllers/src/ux_hcd_ohci_port_suspend.c index 4cb5639..4cb5639 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_port_suspend.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_port_suspend.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_power_down_port.c b/common/usbx_host_controllers/src/ux_hcd_ohci_power_down_port.c index 4b33668..4b33668 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_power_down_port.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_power_down_port.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_power_on_port.c b/common/usbx_host_controllers/src/ux_hcd_ohci_power_on_port.c index 9eb639c..9eb639c 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_power_on_port.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_power_on_port.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_power_root_hubs.c b/common/usbx_host_controllers/src/ux_hcd_ohci_power_root_hubs.c index fbefb34..fbefb34 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_power_root_hubs.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_power_root_hubs.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_request_control_transfer.c b/common/usbx_host_controllers/src/ux_hcd_ohci_request_control_transfer.c index d6adb19..d6adb19 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_request_control_transfer.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_request_control_transfer.c diff --git a/common/usbx_host_controllers/src/ux_hcd_ohci_transfer_abort.c b/common/usbx_host_controllers/src/ux_hcd_ohci_transfer_abort.c index 63fb74f..63fb74f 100644..100755 --- a/common/usbx_host_controllers/src/ux_hcd_ohci_transfer_abort.c +++ b/common/usbx_host_controllers/src/ux_hcd_ohci_transfer_abort.c |
