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