1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 /**************************************************************************/
12 /**************************************************************************/
13 /**                                                                       */
14 /** USBX Component                                                        */
15 /**                                                                       */
16 /**   Device CDC Class                                                    */
17 /**                                                                       */
18 /**************************************************************************/
19 /**************************************************************************/
20 
21 #define UX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "ux_api.h"
27 #include "ux_device_class_cdc_acm.h"
28 #include "ux_device_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_cdc_acm_entry                      PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function is the entry point of the cdc_acm class. It           */
44 /*    will be called by the device stack enumeration module when the      */
45 /*    host has sent a SET_CONFIGURATION command and the cdc_acm interface */
46 /*    needs to be mounted.                                                */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    command                               Pointer to class command      */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _ux_device_class_cdc_acm_initialize       Initialize cdc_acm class  */
59 /*    _ux_device_class_cdc_acm_uninitialize     Uninitialize cdc_acm class*/
60 /*    _ux_device_class_cdc_acm_activate         Activate cdc_acm class    */
61 /*    _ux_device_class_cdc_acm_deactivate       Deactivate cdc_acm class  */
62 /*    _ux_device_class_cdc_acm_control_request  Request control           */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    CDC Class                                                           */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
73 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_ux_device_class_cdc_acm_entry(UX_SLAVE_CLASS_COMMAND * command)77 UINT  _ux_device_class_cdc_acm_entry(UX_SLAVE_CLASS_COMMAND *command)
78 {
79 
80 UINT        status;
81 
82 
83     /* The command request will tell us we need to do here, either a enumeration
84        query, an activation or a deactivation.  */
85     switch (command -> ux_slave_class_command_request)
86     {
87 
88     case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
89 
90         /* Call the init function of the CDC ACM class.  */
91         status =  _ux_device_class_cdc_acm_initialize(command);
92 
93         /* Return the completion status.  */
94         return(status);
95 
96     case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
97 
98         /* Call the init function of the CDC ACM class.  */
99         status =  _ux_device_class_cdc_acm_uninitialize(command);
100 
101         /* Return the completion status.  */
102         return(status);
103 
104     case UX_SLAVE_CLASS_COMMAND_QUERY:
105 
106         /* Check the CLASS definition in the interface descriptor. */
107         if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_CDC_ACM_CLASS)
108             return(UX_SUCCESS);
109         else
110             return(UX_NO_CLASS_MATCH);
111 
112     case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
113 
114         /* The activate command is used when the host has sent a SET_CONFIGURATION command
115            and this interface has to be mounted. Both Bulk endpoints have to be mounted
116            and the cdc_acm thread needs to be activated.  */
117         status =  _ux_device_class_cdc_acm_activate(command);
118 
119         /* Return the completion status.  */
120         return(status);
121 
122     case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
123 
124         /* The deactivate command is used when the device has been extracted.
125            The device endpoints have to be dismounted and the cdc_acm thread canceled.  */
126         status =  _ux_device_class_cdc_acm_deactivate(command);
127 
128         /* Return the completion status.  */
129         return(status);
130 
131     case UX_SLAVE_CLASS_COMMAND_REQUEST:
132 
133         /* The request command is used when the host sends a command on the control endpoint.  */
134         status = _ux_device_class_cdc_acm_control_request(command);
135 
136         /* Return the completion status.  */
137         return(status);
138 
139     default:
140 
141         /* If trace is enabled, insert this event into the trace buffer.  */
142         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
143 
144         /* Return an error.  */
145         return(UX_FUNCTION_NOT_SUPPORTED);
146     }
147 }
148 
149