1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** USBX Component                                                        */
17 /**                                                                       */
18 /**   CDC ECM Class                                                       */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /* Include necessary system files.  */
25 
26 #define UX_SOURCE_CODE
27 
28 #include "ux_api.h"
29 #include "ux_host_class_cdc_ecm.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_cdc_ecm_entry                        PORTABLE C      */
38 /*                                                           6.1.11       */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function is the entry point of the cdc_ecm class. It will be   */
46 /*    called by the USBX stack enumeration module when there is a new     */
47 /*    cdc_ecm ethernet device on the bus or when the it is removed.       */
48 /*                                                                        */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    command                                    CDC ECM class command    */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _ux_host_class_cdc_ecm_activate            Activate cdc_ecm class   */
61 /*    _ux_host_class_cdc_ecm_deactivate          Deactivate cdc_ecm class */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    CDC ECM Class                                                       */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            fixed standalone compile,   */
76 /*                                            resulting in version 6.1.11 */
77 /*                                                                        */
78 /**************************************************************************/
_ux_host_class_cdc_ecm_entry(UX_HOST_CLASS_COMMAND * command)79 UINT  _ux_host_class_cdc_ecm_entry(UX_HOST_CLASS_COMMAND *command)
80 {
81 #if defined(UX_HOST_STANDALONE)
82     UX_PARAMETER_NOT_USED(command);
83     return(UX_FUNCTION_NOT_SUPPORTED);
84 #else
85 
86 UINT    status;
87 
88 
89     /* The command request will tell us we need to do here, either a enumeration
90        query, an activation or a deactivation.  */
91     switch (command -> ux_host_class_command_request)
92     {
93 
94     case UX_HOST_CLASS_COMMAND_QUERY:
95 
96         /* The query command is used to let the stack enumeration process know if we want to own
97            this device or not.  */
98         if(command -> ux_host_class_command_usage == UX_HOST_CLASS_COMMAND_USAGE_CSP)
99         {
100 
101             /* We are in CSP mode. Check if CDC-ECM Control or Data.  */
102             if (((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_DATA_CLASS) && (command -> ux_host_class_command_subclass == 0)) ||
103                              ((command -> ux_host_class_command_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) &&
104                              (command -> ux_host_class_command_subclass == UX_HOST_CLASS_CDC_ECM_CONTROL_SUBCLASS)))
105             {
106                 /* Check for IAD presence.  */
107                 if ((command -> ux_host_class_command_iad_class == 0) && (command -> ux_host_class_command_iad_subclass == 0))
108 
109                     /* No IAD, we accept this class.  */
110                     return(UX_SUCCESS);
111 
112                 else
113                 {
114 
115                     if ((command -> ux_host_class_command_iad_class == UX_HOST_CLASS_CDC_CONTROL_CLASS) &&
116                             (command -> ux_host_class_command_iad_subclass == UX_HOST_CLASS_CDC_ECM_CONTROL_SUBCLASS))
117 
118                         /* There is an IAD and this is for CDC-ACM.  */
119                         return(UX_SUCCESS);
120 
121                     else
122 
123                         /* The IAD does not match with CDC-ACM.  */
124                         return(UX_NO_CLASS_MATCH);
125                 }
126             }
127 
128                 /* Not CDC-ECM control or data class.  */
129                 return(UX_NO_CLASS_MATCH);
130 
131         }
132 
133         else
134 
135             /* No match.  */
136             return(UX_NO_CLASS_MATCH);
137 
138     case UX_HOST_CLASS_COMMAND_ACTIVATE:
139 
140         /* The activate command is used when the device inserted has found a parent and
141            is ready to complete the enumeration.  */
142         status =  _ux_host_class_cdc_ecm_activate(command);
143         return(status);
144 
145     case UX_HOST_CLASS_COMMAND_DEACTIVATE:
146 
147         /* The deactivate command is used when the device has been extracted either
148            directly or when its parents has been extracted.  */
149         status =  _ux_host_class_cdc_ecm_deactivate(command);
150         return(status);
151 
152     default:
153 
154         /* Error trap. */
155         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
156 
157         /* If trace is enabled, insert this event into the trace buffer.  */
158         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
159 
160         return(UX_FUNCTION_NOT_SUPPORTED);
161     }
162 #endif
163 }
164 
165