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 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device Data Pump 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_dpump.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_dpump_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 device dpump class. It      */
44 /*    will be called by the device stack enumeration module when the      */
45 /*    host has sent a SET_CONFIGURATION command and the dpump 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_dpump_initialize      Initialize dpump class       */
59 /*    _ux_device_class_dpump_activate        Activate dpump class         */
60 /*    _ux_device_class_dpump_deactivate      Deactivate dpump class       */
61 /*    _ux_device_class_dpump_change          Alternate setting change     */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Device Data Pump 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 /*                                                                        */
75 /**************************************************************************/
_ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND * command)76 UINT  _ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND *command)
77 {
78 
79 UINT        status;
80 
81 
82     /* The command request will tell us we need to do here, either a enumeration
83        query, an activation or a deactivation.  */
84     switch (command -> ux_slave_class_command_request)
85     {
86 
87     case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
88 
89         /* Call the init function of the DPUMP class.  */
90         status =  _ux_device_class_dpump_initialize(command);
91 
92         /* Return the completion status.  */
93         return(status);
94 
95     case UX_SLAVE_CLASS_COMMAND_QUERY:
96 
97         /* Check the CLASS definition in the interface descriptor. */
98         if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_DPUMP_CLASS)
99             return(UX_SUCCESS);
100         else
101             return(UX_NO_CLASS_MATCH);
102 
103     case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
104 
105         /* The activate command is used when the host has sent a SET_CONFIGURATION command
106            and this interface has to be mounted. Both Bulk endpoints have to be mounted
107            and the dpump thread needs to be activated.  */
108         status =  _ux_device_class_dpump_activate(command);
109 
110         /* Return the completion status.  */
111         return(status);
112 
113     case UX_SLAVE_CLASS_COMMAND_CHANGE:
114 
115         /* The change command is used when the host has sent a SET_INTERFACE command
116            to go from Alternate Setting 0 to 1 or revert to the default mode.  */
117         status =  _ux_device_class_dpump_change(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 dpump thread canceled.  */
126         status =  _ux_device_class_dpump_deactivate(command);
127 
128         /* Return the completion status.  */
129         return(status);
130 
131     case UX_SLAVE_CLASS_COMMAND_REQUEST:
132 
133         /* Return the completion status.  */
134         return(UX_SUCCESS);
135 
136     default:
137 
138         /* Error trap. */
139         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
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