1
1
/***************************************************************************
2
- * Copyright (c) 2024 Microsoft Corporation
3
- *
2
+ * Copyright (c) 2024 Microsoft Corporation
3
+ *
4
4
* This program and the accompanying materials are made available under the
5
5
* terms of the MIT License which is available at
6
6
* https://opensource.org/licenses/MIT.
7
- *
7
+ *
8
8
* SPDX-License-Identifier: MIT
9
9
**************************************************************************/
10
10
30
30
31
31
/* Define the Slave Storage Class Inquiry data : DO NOT CHANGE THE LENGTH OF THESE ITEMS */
32
32
33
- UCHAR _ux_system_slave_class_storage_vendor_id [] = "AzureRTO " ;
34
- UCHAR _ux_system_slave_class_storage_product_id [] = "USBX storage dev " ;
35
- UCHAR _ux_system_slave_class_storage_product_rev [] = "2000" ;
36
- UCHAR _ux_system_slave_class_storage_product_serial [] = "12345678901234567890" ;
33
+ UCHAR _ux_system_slave_class_storage_vendor_id [] = "Eclipse " ;
34
+ UCHAR _ux_system_slave_class_storage_product_id [] = "USBX STORAGE DEV " ;
35
+ UCHAR _ux_system_slave_class_storage_product_rev [] = "2000" ;
36
+ UCHAR _ux_system_slave_class_storage_product_serial [] = "12345678901234567890" ;
37
37
38
38
/**************************************************************************/
39
39
/* */
@@ -92,6 +92,8 @@ UINT _ux_device_class_storage_initialize(UX_SLAVE_CLASS_COMMAND *command)
92
92
93
93
UINT status = UX_SUCCESS ;
94
94
UX_SLAVE_CLASS_STORAGE * storage ;
95
+ UX_SLAVE_CLASS_STORAGE_LUN * lun ;
96
+ UX_SLAVE_CLASS_STORAGE_LUN * parameter_lun ;
95
97
UX_SLAVE_CLASS_STORAGE_PARAMETER * storage_parameter ;
96
98
UX_SLAVE_CLASS * class_inst ;
97
99
ULONG lun_index ;
@@ -119,18 +121,20 @@ ULONG lun_index;
119
121
120
122
/* Allocate bulk endpoint buffer. */
121
123
UX_ASSERT (!UX_DEVICE_CLASS_STORAGE_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW );
122
- storage -> ux_device_class_storage_endpoint_buffer = _ux_utility_memory_allocate (UX_NO_ALIGN ,
123
- UX_CACHE_SAFE_MEMORY , UX_DEVICE_CLASS_STORAGE_ENDPOINT_BUFFER_SIZE );
124
- #else
124
+
125
+ storage -> ux_device_class_storage_endpoint_buffer =
126
+ _ux_utility_memory_allocate (UX_NO_ALIGN , UX_CACHE_SAFE_MEMORY , UX_DEVICE_CLASS_STORAGE_ENDPOINT_BUFFER_SIZE );
127
+ #else /* UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1 */
125
128
status = UX_SUCCESS ;
126
- #endif
129
+ #endif /* UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1 */
127
130
128
131
#if !defined(UX_DEVICE_STANDALONE )
129
132
130
133
/* Allocate some memory for the thread stack. */
131
134
if (status == UX_SUCCESS )
132
135
{
133
- class_inst -> ux_slave_class_thread_stack = _ux_utility_memory_allocate (UX_NO_ALIGN , UX_REGULAR_MEMORY , UX_THREAD_STACK_SIZE );
136
+ class_inst -> ux_slave_class_thread_stack = _ux_utility_memory_allocate (UX_NO_ALIGN , UX_REGULAR_MEMORY ,
137
+ UX_THREAD_STACK_SIZE );
134
138
135
139
/* If it's OK, create thread. */
136
140
if (class_inst -> ux_slave_class_thread_stack != UX_NULL )
@@ -139,18 +143,18 @@ ULONG lun_index;
139
143
a new thread. We pass a pointer to the class to the new thread. This thread
140
144
does not start until we have a instance of the class. */
141
145
status = _ux_device_thread_create (& class_inst -> ux_slave_class_thread , "ux_slave_storage_thread" ,
142
- _ux_device_class_storage_thread ,
143
- ( ULONG ) ( ALIGN_TYPE ) class_inst , (VOID * ) class_inst -> ux_slave_class_thread_stack ,
144
- UX_THREAD_STACK_SIZE , UX_THREAD_PRIORITY_CLASS ,
145
- UX_THREAD_PRIORITY_CLASS , UX_NO_TIME_SLICE , UX_DONT_START );
146
+ _ux_device_class_storage_thread , ( ULONG ) ( ALIGN_TYPE ) class_inst ,
147
+ (VOID * ) class_inst -> ux_slave_class_thread_stack ,
148
+ UX_THREAD_STACK_SIZE , UX_THREAD_PRIORITY_CLASS ,
149
+ UX_THREAD_PRIORITY_CLASS , UX_NO_TIME_SLICE , UX_DONT_START );
146
150
else
147
151
status = UX_MEMORY_INSUFFICIENT ;
148
152
}
149
- #else
153
+ #else /* !UX_DEVICE_STANDALONE */
150
154
151
155
/* Save tasks run entry. */
152
156
class_inst -> ux_slave_class_task_function = _ux_device_class_storage_tasks_run ;
153
- #endif
157
+ #endif /* !UX_DEVICE_STANDALONE */
154
158
155
159
/* If thread resources allocated, go on. */
156
160
if (status == UX_SUCCESS )
@@ -159,59 +163,97 @@ ULONG lun_index;
159
163
UX_THREAD_EXTENSION_PTR_SET (& (class_inst -> ux_slave_class_thread ), class_inst )
160
164
161
165
/* Store the number of LUN declared. */
162
- storage -> ux_slave_class_storage_number_lun = storage_parameter -> ux_slave_class_storage_parameter_number_lun ;
166
+ storage -> ux_slave_class_storage_number_lun =
167
+ storage_parameter -> ux_slave_class_storage_parameter_number_lun ;
163
168
164
169
/* Copy each individual LUN parameters. */
165
170
for (lun_index = 0 ; lun_index < storage -> ux_slave_class_storage_number_lun ; lun_index ++ )
166
171
{
167
172
173
+ lun = & storage -> ux_slave_class_storage_lun [lun_index ];
174
+ parameter_lun = & storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ];
175
+
168
176
/* Check block length size. */
169
- if (storage_parameter -> ux_slave_class_storage_parameter_lun [ lun_index ]. ux_slave_class_storage_media_block_length > UX_SLAVE_CLASS_STORAGE_BUFFER_SIZE )
177
+ if (parameter_lun -> ux_slave_class_storage_media_block_length > UX_SLAVE_CLASS_STORAGE_BUFFER_SIZE )
170
178
{
171
179
/* Cannot proceed. */
172
180
status = (UX_MEMORY_INSUFFICIENT );
173
181
break ;
174
182
}
175
183
176
184
/* Store all the application parameter information about the media. */
177
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_last_lba = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_last_lba ;
178
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_block_length = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_block_length ;
179
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_type = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_type ;
180
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_removable_flag = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_removable_flag ;
181
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_read_only_flag = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_read_only_flag ;
182
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_read = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_read ;
183
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_flush = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_flush ;
184
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_write = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_write ;
185
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_status = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_status ;
186
- storage -> ux_slave_class_storage_lun [lun_index ].ux_slave_class_storage_media_notification = storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ].ux_slave_class_storage_media_notification ;
185
+ lun -> ux_slave_class_storage_media_last_lba =
186
+ parameter_lun -> ux_slave_class_storage_media_last_lba ;
187
+
188
+ lun -> ux_slave_class_storage_media_block_length =
189
+ parameter_lun -> ux_slave_class_storage_media_block_length ;
190
+
191
+ lun -> ux_slave_class_storage_media_type =
192
+ parameter_lun -> ux_slave_class_storage_media_type ;
193
+
194
+ lun -> ux_slave_class_storage_media_removable_flag =
195
+ parameter_lun -> ux_slave_class_storage_media_removable_flag ;
196
+
197
+ lun -> ux_slave_class_storage_media_read_only_flag =
198
+ parameter_lun -> ux_slave_class_storage_media_read_only_flag ;
199
+
200
+ lun -> ux_slave_class_storage_media_read =
201
+ parameter_lun -> ux_slave_class_storage_media_read ;
202
+
203
+ lun -> ux_slave_class_storage_media_flush =
204
+ parameter_lun -> ux_slave_class_storage_media_flush ;
205
+
206
+ lun -> ux_slave_class_storage_media_write =
207
+ parameter_lun -> ux_slave_class_storage_media_write ;
208
+
209
+ lun -> ux_slave_class_storage_media_status =
210
+ parameter_lun -> ux_slave_class_storage_media_status ;
211
+
212
+ lun -> ux_slave_class_storage_media_notification =
213
+ parameter_lun -> ux_slave_class_storage_media_notification ;
187
214
}
188
215
189
216
/* If it's OK, complete it. */
190
217
if (status == UX_SUCCESS )
191
218
{
192
219
193
220
/* Store the start and stop signals if needed by the application. */
194
- storage -> ux_slave_class_storage_instance_activate = storage_parameter -> ux_slave_class_storage_instance_activate ;
195
- storage -> ux_slave_class_storage_instance_deactivate = storage_parameter -> ux_slave_class_storage_instance_deactivate ;
221
+ storage -> ux_slave_class_storage_instance_activate =
222
+ storage_parameter -> ux_slave_class_storage_instance_activate ;
223
+
224
+ storage -> ux_slave_class_storage_instance_deactivate =
225
+ storage_parameter -> ux_slave_class_storage_instance_deactivate ;
196
226
197
227
/* Store the vendor id, product id, product revision and product serial. */
198
228
if (storage_parameter -> ux_slave_class_storage_parameter_vendor_id )
199
- storage -> ux_slave_class_storage_vendor_id = storage_parameter -> ux_slave_class_storage_parameter_vendor_id ;
229
+ {
230
+ storage -> ux_slave_class_storage_vendor_id =
231
+ storage_parameter -> ux_slave_class_storage_parameter_vendor_id ;
232
+ }
200
233
else
201
234
storage -> ux_slave_class_storage_vendor_id = _ux_system_slave_class_storage_vendor_id ;
202
235
203
236
if (storage_parameter -> ux_slave_class_storage_parameter_product_id )
204
- storage -> ux_slave_class_storage_product_id = storage_parameter -> ux_slave_class_storage_parameter_product_id ;
237
+ {
238
+ storage -> ux_slave_class_storage_product_id =
239
+ storage_parameter -> ux_slave_class_storage_parameter_product_id ;
240
+ }
205
241
else
206
242
storage -> ux_slave_class_storage_product_id = _ux_system_slave_class_storage_product_id ;
207
243
208
244
if (storage_parameter -> ux_slave_class_storage_parameter_product_rev )
209
- storage -> ux_slave_class_storage_product_rev = storage_parameter -> ux_slave_class_storage_parameter_product_rev ;
245
+ {
246
+ storage -> ux_slave_class_storage_product_rev =
247
+ storage_parameter -> ux_slave_class_storage_parameter_product_rev ;
248
+ }
210
249
else
211
250
storage -> ux_slave_class_storage_product_rev = _ux_system_slave_class_storage_product_rev ;
212
251
213
252
if (storage_parameter -> ux_slave_class_storage_parameter_product_serial )
214
- storage -> ux_slave_class_storage_product_serial = storage_parameter -> ux_slave_class_storage_parameter_product_serial ;
253
+ {
254
+ storage -> ux_slave_class_storage_product_serial =
255
+ storage_parameter -> ux_slave_class_storage_parameter_product_serial ;
256
+ }
215
257
else
216
258
storage -> ux_slave_class_storage_product_serial = _ux_system_slave_class_storage_product_serial ;
217
259
@@ -228,12 +270,12 @@ ULONG lun_index;
228
270
#if !defined(UX_DEVICE_STANDALONE )
229
271
if (class_inst -> ux_slave_class_thread_stack != UX_NULL )
230
272
_ux_utility_memory_free (& class_inst -> ux_slave_class_thread_stack );
231
- #endif
273
+ #endif /* !UX_DEVICE_STANDALONE*/
232
274
233
275
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
234
276
if (storage -> ux_device_class_storage_endpoint_buffer != UX_NULL )
235
277
_ux_utility_memory_free (storage -> ux_device_class_storage_endpoint_buffer );
236
- #endif
278
+ #endif /* UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1 */
237
279
238
280
/* Free instance. */
239
281
_ux_utility_memory_free (storage );
@@ -242,7 +284,7 @@ ULONG lun_index;
242
284
return (status );
243
285
}
244
286
245
-
287
+ #ifdef UX_ENABLE_ERROR_CHECKING
246
288
/**************************************************************************/
247
289
/* */
248
290
/* FUNCTION RELEASE */
@@ -284,26 +326,36 @@ UINT _uxe_device_class_storage_initialize(UX_SLAVE_CLASS_COMMAND *command)
284
326
{
285
327
286
328
UX_SLAVE_CLASS_STORAGE_PARAMETER * storage_parameter ;
287
- UINT i ;
329
+ UX_SLAVE_CLASS_STORAGE_LUN * lun ;
330
+ UINT lun_index ;
288
331
289
332
/* Get the pointer to the application parameters for the storage class. */
290
333
storage_parameter = command -> ux_slave_class_command_parameter ;
291
334
292
335
/* Sanity checks. */
293
336
if (storage_parameter -> ux_slave_class_storage_parameter_number_lun > UX_MAX_SLAVE_LUN )
294
337
return (UX_INVALID_PARAMETER );
295
- for (i = 0 ; i < storage_parameter -> ux_slave_class_storage_parameter_number_lun ; i ++ )
338
+
339
+ if ((storage_parameter -> ux_slave_class_storage_parameter_vendor_id != UX_NULL ) &&
340
+ (( _ux_utility_string_length_get (storage_parameter -> ux_slave_class_storage_parameter_vendor_id ) != 8 )) ||
341
+ ((storage_parameter -> ux_slave_class_storage_parameter_product_id != UX_NULL ) &&
342
+ ( _ux_utility_string_length_get (storage_parameter -> ux_slave_class_storage_parameter_product_id ) != 16 )) ||
343
+ ((storage_parameter -> ux_slave_class_storage_parameter_product_rev != UX_NULL ) &&
344
+ ( _ux_utility_string_length_get (storage_parameter -> ux_slave_class_storage_parameter_product_rev ) != 4 )) ||
345
+ ((storage_parameter -> ux_slave_class_storage_parameter_product_serial != UX_NULL ) &&
346
+ ( _ux_utility_string_length_get (storage_parameter -> ux_slave_class_storage_parameter_product_serial ) != 20 )))
347
+ return (UX_INVALID_PARAMETER );
348
+
349
+ for (lun_index = 0 ; lun_index < storage_parameter -> ux_slave_class_storage_parameter_number_lun ; lun_index ++ )
296
350
{
297
- if ((storage_parameter -> ux_slave_class_storage_parameter_lun [i ].
298
- ux_slave_class_storage_media_read == UX_NULL ) ||
299
- (storage_parameter -> ux_slave_class_storage_parameter_lun [i ].
300
- ux_slave_class_storage_media_write == UX_NULL ) ||
301
- (storage_parameter -> ux_slave_class_storage_parameter_lun [i ].
302
- ux_slave_class_storage_media_status == UX_NULL )
351
+ lun = & storage_parameter -> ux_slave_class_storage_parameter_lun [lun_index ];
352
+
353
+ if ((lun -> ux_slave_class_storage_media_read == UX_NULL ) ||
354
+ (lun -> ux_slave_class_storage_media_write == UX_NULL ) ||
355
+ (lun -> ux_slave_class_storage_media_status == UX_NULL )
303
356
#if defined(UX_SLAVE_CLASS_STORAGE_INCLUDE_MMC )
304
- || (storage_parameter -> ux_slave_class_storage_parameter_lun [i ].
305
- ux_slave_class_storage_media_notification == UX_NULL )
306
- #endif
357
+ || (lun -> ux_slave_class_storage_media_notification == UX_NULL )
358
+ #endif /* UX_SLAVE_CLASS_STORAGE_INCLUDE_MMC */
307
359
)
308
360
{
309
361
return (UX_INVALID_PARAMETER );
@@ -313,3 +365,4 @@ UINT i;
313
365
/* Invoke storage initialize function. */
314
366
return (_ux_device_class_storage_initialize (command ));
315
367
}
368
+ #endif /* UX_ENABLE_ERROR_CHECKING */
0 commit comments