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 /**   Storage 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_storage.h"
30 #include "ux_host_stack.h"
31 
32 
33 #if defined(UX_HOST_STANDALONE) && defined(UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT)
34 #error Only Mass Storage BulkOnly (BO) is supported in standalone mode right now.
35 #endif
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _ux_host_class_storage_device_support_check         PORTABLE C      */
41 /*                                                           6.1.10       */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Chaoqiong Xiao, Microsoft Corporation                               */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function verifies the support for the subclass and protocol    */
49 /*    of the USB device. If the device is supported it will update the    */
50 /*    storage class instances with the transport layer functions.         */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    storage                               Pointer to storage class      */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    None                                                                */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Storage 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 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            added standalone support,   */
77 /*                                            resulting in version 6.1.10 */
78 /*                                                                        */
79 /**************************************************************************/
_ux_host_class_storage_device_support_check(UX_HOST_CLASS_STORAGE * storage)80 UINT  _ux_host_class_storage_device_support_check(UX_HOST_CLASS_STORAGE *storage)
81 {
82 
83     /* Check for the protocol type (BO/CB/CBI) and update the transport functions.  */
84     switch(storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol)
85     {
86 
87     case UX_HOST_CLASS_STORAGE_PROTOCOL_BO:
88 
89 #if !defined(UX_HOST_STANDALONE)
90         storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_bo;
91 #endif
92         break;
93 
94 #ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
95     case UX_HOST_CLASS_STORAGE_PROTOCOL_CB:
96 
97 #if !defined(UX_HOST_STANDALONE)
98         storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cb;
99 #endif
100         break;
101 
102 
103     case UX_HOST_CLASS_STORAGE_PROTOCOL_CBI:
104 
105 #if !defined(UX_HOST_STANDALONE)
106 
107         /* In case of CBI, the subclass must be UFI, if not, default back to CB transport.  */
108         if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass == UX_HOST_CLASS_STORAGE_SUBCLASS_UFI)
109             storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cbi;
110         else
111             storage -> ux_host_class_storage_transport =  _ux_host_class_storage_transport_cb;
112 #endif
113         break;
114 
115 #endif
116 
117     default:
118 
119         /* Error trap. */
120         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_PROTOCOL_ERROR);
121 
122         /* If trace is enabled, insert this event into the trace buffer.  */
123         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_PROTOCOL_ERROR, storage, 0, 0, UX_TRACE_ERRORS, 0, 0)
124 
125         return(UX_HOST_CLASS_PROTOCOL_ERROR);
126     }
127 
128     /* Check for the sub class and make sure we support it.  */
129     switch (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass)
130     {
131 
132 #ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
133     case UX_HOST_CLASS_STORAGE_SUBCLASS_UFI:
134 #endif
135     case UX_HOST_CLASS_STORAGE_SUBCLASS_RBC:
136     case UX_HOST_CLASS_STORAGE_SUBCLASS_SCSI:
137     case UX_HOST_CLASS_STORAGE_SUBCLASS_SFF8020:
138     case UX_HOST_CLASS_STORAGE_SUBCLASS_SFF8070:
139 
140         return(UX_SUCCESS);
141 
142     default:
143 
144         /* Error trap. */
145         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_PROTOCOL_ERROR);
146 
147         /* If trace is enabled, insert this event into the trace buffer.  */
148         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_PROTOCOL_ERROR, storage, 0, 0, UX_TRACE_ERRORS, 0, 0)
149 
150         return(UX_HOST_CLASS_PROTOCOL_ERROR);
151     }
152 }
153