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 Storage 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_storage.h"
29 #include "ux_device_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_class_storage_entry PORTABLE C */
37 /* 6.3.0 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is the entry point of the device storage class. It */
45 /* will be called by the device stack enumeration module when the */
46 /* host has sent a SET_CONFIGURATION command and the storage 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_storage_initialize Initialize storage class */
60 /* _ux_device_class_storage_uninitialize Uninitialize storage class */
61 /* _ux_device_class_storage_activate Activate storage class */
62 /* _ux_device_class_storage_deactivate Deactivate storage class */
63 /* _ux_device_class_storage_control_request */
64 /* Request control */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Device Storage 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 /* 10-31-2023 Chaoqiong Xiao Modified comment(s), */
78 /* added error checks support, */
79 /* resulting in version 6.3.0 */
80 /* */
81 /**************************************************************************/
_ux_device_class_storage_entry(UX_SLAVE_CLASS_COMMAND * command)82 UINT _ux_device_class_storage_entry(UX_SLAVE_CLASS_COMMAND *command)
83 {
84
85 UINT status;
86
87
88 /* The command request will tell us we need to do here, either a enumeration
89 query, an activation or a deactivation. */
90 switch (command -> ux_slave_class_command_request)
91 {
92
93 case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
94
95 /* Call the init function of the Storage class. */
96 #if defined(UX_DEVICE_CLASS_STORAGE_ENABLE_ERROR_CHECKING)
97 status = _uxe_device_class_storage_initialize(command);
98 #else
99 status = _ux_device_class_storage_initialize(command);
100 #endif
101
102 /* Return the completion status. */
103 return(status);
104
105 case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
106
107 /* Call the init function of the Storage class. */
108 status = _ux_device_class_storage_uninitialize(command);
109
110 /* Return the completion status. */
111 return(status);
112
113
114 case UX_SLAVE_CLASS_COMMAND_QUERY:
115
116 /* Check the CLASS definition in the interface descriptor. */
117 if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_STORAGE_CLASS)
118 return(UX_SUCCESS);
119 else
120 return(UX_NO_CLASS_MATCH);
121
122 case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
123
124 /* The activate command is used when the host has sent a SET_CONFIGURATION command
125 and this interface has to be mounted. Both Bulk endpoints have to be mounted
126 and the storage thread needs to be activated. */
127 status = _ux_device_class_storage_activate(command);
128
129 /* Return the completion status. */
130 return(status);
131
132 case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
133
134 /* The deactivate command is used when the device has been extracted.
135 The device endpoints have to be dismounted and the storage thread canceled. */
136 status = _ux_device_class_storage_deactivate(command);
137
138 /* Return the completion status. */
139 return(status);
140
141 case UX_SLAVE_CLASS_COMMAND_REQUEST:
142
143 /* The request command is used when the host sends a command on the control endpoint. */
144 status = _ux_device_class_storage_control_request(command);
145
146 /* Return the completion status. */
147 return(status);
148
149 default:
150
151 /* Error trap. */
152 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
153
154 /* If trace is enabled, insert this event into the trace buffer. */
155 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
156
157 /* Return an error. */
158 return(UX_FUNCTION_NOT_SUPPORTED);
159 }
160 }
161
162