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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device CDC_ECM Class                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_class_cdc_ecm.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_cdc_ecm_entry                      PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the entry point of the cdc_ecm class. It           */
45 /*    will be called by the device stack enumeration module when the      */
46 /*    host has sent a SET_CONFIGURATION command and the cdc_ecm interface */
47 /*    needs to be mounted.                                                */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    command                               Pointer to class command      */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_device_class_cdc_ecm_initialize       Initialize cdc_ecm class  */
60 /*    _ux_device_class_cdc_ecm_uninitialize     Uninitialize cdc_ecm class*/
61 /*    _ux_device_class_cdc_ecm_activate         Activate cdc_ecm class    */
62 /*    _ux_device_class_cdc_ecm_deactivate       Deactivate cdc_ecm class  */
63 /*    _ux_device_class_cdc_ecm_change           Alternate setting change  */
64 /*    _ux_device_class_cdc_ecm_control_request  Request control           */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    CDC_ECM Class                                                       */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_ux_device_class_cdc_ecm_entry(UX_SLAVE_CLASS_COMMAND * command)79 UINT  _ux_device_class_cdc_ecm_entry(UX_SLAVE_CLASS_COMMAND *command)
80 {
81 
82 UINT        status;
83 
84     /* The command request will tell us we need to do here, either a enumeration
85        query, an activation or a deactivation.  */
86     switch (command -> ux_slave_class_command_request)
87     {
88 
89     case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
90 
91         /* Call the init function of the CDC_ECM class.  */
92         status =  _ux_device_class_cdc_ecm_initialize(command);
93 
94         /* Return the completion status.  */
95         return(status);
96 
97     case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
98 
99         /* Call the init function of the CDC_ECM class.  */
100         status =  _ux_device_class_cdc_ecm_uninitialize(command);
101 
102         /* Return the completion status.  */
103         return(status);
104 
105     case UX_SLAVE_CLASS_COMMAND_QUERY:
106 
107         /* Check the CLASS definition in the interface descriptor. */
108         if (command -> ux_slave_class_command_class == UX_DEVICE_CLASS_CDC_ECM_CLASS_COMMUNICATION_CONTROL ||
109                 command -> ux_slave_class_command_class == UX_DEVICE_CLASS_CDC_ECM_CLASS_COMMUNICATION_DATA)
110             return(UX_SUCCESS);
111         else
112             return(UX_NO_CLASS_MATCH);
113 
114     case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
115 
116         /* The activate command is used when the host has sent a SET_CONFIGURATION command
117            and this interface has to be mounted. In CDC ECM, the alternate setting 0 has no endpoints.
118            Only the Alternate Setting 1 has the Bulk IN and OUT endpoints active.  */
119         status =  _ux_device_class_cdc_ecm_activate(command);
120 
121         /* Return the completion status.  */
122         return(status);
123 
124     case UX_SLAVE_CLASS_COMMAND_CHANGE:
125 
126         /* The change command is used when the host has sent a SET_INTERFACE command
127            to go from Alternate Setting 0 to 1 or revert to the default mode.  */
128         status =  _ux_device_class_cdc_ecm_change(command);
129 
130         /* Return the completion status.  */
131         return(status);
132 
133 
134     case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
135 
136         /* The deactivate command is used when the device has been extracted.
137            The device endpoints have to be dismounted and the cdc_ecm thread canceled.  */
138         status =  _ux_device_class_cdc_ecm_deactivate(command);
139 
140         /* Return the completion status.  */
141         return(status);
142 
143     case UX_SLAVE_CLASS_COMMAND_REQUEST:
144 
145         /* The request command is used when the host sends a command on the control endpoint.  */
146         status = _ux_device_class_cdc_ecm_control_request(command);
147 
148         /* Return the completion status.  */
149         return(status);
150 
151     default:
152 
153         /* Error trap. */
154         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
155 
156         /* If trace is enabled, insert this event into the trace buffer.  */
157         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
158 
159         /* Return an error.  */
160         return(UX_FUNCTION_NOT_SUPPORTED);
161     }
162 }
163 
164