Fix makefiles -- the auto-addition of -D switches to each LUFA compile time option...
[pub/USBasp.git] / Demos / Host / LowLevel / MassStorageHost / Lib / MassStoreCommands.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Mass Storage Device commands, to issue MSD commands to the device for
34 * reading device status, capacity, and other characteristics. This file
35 * also contains block read and write functions, so that device blocks
36 * can be read and written. In general, these functions would be chained
37 * to a FAT library to give file-level access to an attached device's contents.
38 *
39 * \note Many Mass Storage devices on the market are non-compliant to the
40 * specifications and thus can prove difficult to interface with. It
41 * may be necessary to retry the functions in the module several times
42 * after they have returned and error to successfully send the command
43 * to the device. Some devices may also need to have the stream function
44 * timeout period extended beyond 100ms (some badly designed devices exceeding
45 * 1.5 seconds occasionally) by defining USB_STREAM_TIMEOUT_MS to a
46 * larger value in the project makefile and passing it to the compiler
47 * via the -D switch.
48 */
49
50 #define INCLUDE_FROM_MASSSTORE_COMMANDS_C
51 #include "MassStoreCommands.h"
52
53 /* Globals: */
54 /** Current CBW to send to the device. This is automatically filled by the routines
55 * in this file and is not externally accessible.
56 */
57 static CommandBlockWrapper_t SCSICommandBlock;
58
59 /** Current CSW received from the device. This is automatically filled by the routines
60 * in this file and is externally accessible so that the return codes may be checked.
61 */
62 CommandStatusWrapper_t SCSICommandStatus;
63
64 /** Current Tag value used in issued CBWs to the device. This is automatically incremented
65 * by the routines in this file, and is not externally accessible.
66 */
67 static uint32_t MassStore_Tag = 1;
68
69
70 /** Routine to send the current CBW to the device, and increment the Tag value as needed.
71 *
72 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
73 */
74 static uint8_t MassStore_SendCommand(void)
75 {
76 uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
77
78 /* Each transmission should have a unique tag value, excluding values 0 and 0xFFFFFFFF */
79 if (++MassStore_Tag == 0xFFFFFFFF)
80 MassStore_Tag = 1;
81
82 /* Select the OUT data pipe for CBW transmission */
83 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE);
84 Pipe_Unfreeze();
85
86 /* Write the CBW command to the OUT pipe */
87 if ((ErrorCode = Pipe_Write_Stream_LE(&SCSICommandBlock, sizeof(CommandBlockWrapper_t))) != PIPE_RWSTREAM_NoError)
88 return ErrorCode;
89
90 /* Send the data in the OUT pipe to the attached device */
91 Pipe_ClearOUT();
92
93 while(!(Pipe_IsOUTReady()));
94
95 /* Freeze pipe after use */
96 Pipe_Freeze();
97
98 return PIPE_RWSTREAM_NoError;
99 }
100
101 /** Waits until the attached device is ready to accept data following a CBW, checking
102 * to ensure that the device has not stalled the transaction.
103 *
104 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
105 */
106 static uint8_t MassStore_WaitForDataReceived(void)
107 {
108 uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;
109
110 /* Select the IN data pipe for data reception */
111 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE);
112 Pipe_Unfreeze();
113
114 /* Wait until data received in the IN pipe */
115 while (!(Pipe_IsINReceived()))
116 {
117 /* Check to see if a new frame has been issued (1ms elapsed) */
118 if (USB_INT_HasOccurred(USB_INT_HSOFI))
119 {
120 /* Clear the flag and decrement the timeout period counter */
121 USB_INT_Clear(USB_INT_HSOFI);
122 TimeoutMSRem--;
123
124 /* Check to see if the timeout period for the command has elapsed */
125 if (!(TimeoutMSRem))
126 return PIPE_RWSTREAM_Timeout;
127 }
128
129 Pipe_Freeze();
130 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE);
131 Pipe_Unfreeze();
132
133 /* Check if pipe stalled (command failed by device) */
134 if (Pipe_IsStalled())
135 {
136 /* Clear the stall condition on the OUT pipe */
137 USB_Host_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE);
138
139 return PIPE_RWSTREAM_PipeStalled;
140 }
141
142 Pipe_Freeze();
143 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE);
144 Pipe_Unfreeze();
145
146 /* Check if pipe stalled (command failed by device) */
147 if (Pipe_IsStalled())
148 {
149 /* Clear the stall condition on the IN pipe */
150 USB_Host_ClearPipeStall(MASS_STORE_DATA_IN_PIPE);
151
152 return PIPE_RWSTREAM_PipeStalled;
153 }
154
155 /* Check to see if the device was disconnected, if so exit function */
156 if (!(USB_IsConnected))
157 return PIPE_RWSTREAM_DeviceDisconnected;
158 };
159
160 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE);
161 Pipe_Freeze();
162
163 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE);
164 Pipe_Freeze();
165
166 return PIPE_RWSTREAM_NoError;
167 }
168
169 /** Sends or receives the transaction's data stage to or from the attached device, reading or
170 * writing to the nominated buffer.
171 *
172 * \param BufferPtr Pointer to the data buffer to read from or write to
173 *
174 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
175 */
176 static uint8_t MassStore_SendReceiveData(void* BufferPtr)
177 {
178 uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
179 uint16_t BytesRem = SCSICommandBlock.Header.DataTransferLength;
180
181 /* Check the direction of the SCSI command data stage */
182 if (SCSICommandBlock.Header.Flags & COMMAND_DIRECTION_DATA_IN)
183 {
184 /* Select the IN data pipe for data reception */
185 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE);
186 Pipe_Unfreeze();
187
188 /* Read in the block data from the pipe */
189 if ((ErrorCode = Pipe_Read_Stream_LE(BufferPtr, BytesRem)) != PIPE_RWSTREAM_NoError)
190 return ErrorCode;
191
192 /* Acknowledge the packet */
193 Pipe_ClearIN();
194 }
195 else
196 {
197 /* Select the OUT data pipe for data transmission */
198 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE);
199 Pipe_Unfreeze();
200
201 /* Write the block data to the pipe */
202 if ((ErrorCode = Pipe_Write_Stream_LE(BufferPtr, BytesRem)) != PIPE_RWSTREAM_NoError)
203 return ErrorCode;
204
205 /* Acknowledge the packet */
206 Pipe_ClearOUT();
207
208 while (!(Pipe_IsOUTReady()));
209 }
210
211 /* Freeze used pipe after use */
212 Pipe_Freeze();
213
214 return PIPE_RWSTREAM_NoError;
215 }
216
217 /** Routine to receive the current CSW from the device.
218 *
219 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
220 */
221 static uint8_t MassStore_GetReturnedStatus(void)
222 {
223 uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
224
225 /* If an error in the command ocurred, abort */
226 if ((ErrorCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)
227 return ErrorCode;
228
229 /* Select the IN data pipe for data reception */
230 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE);
231 Pipe_Unfreeze();
232
233 /* Load in the CSW from the attached device */
234 if ((ErrorCode = Pipe_Read_Stream_LE(&SCSICommandStatus, sizeof(CommandStatusWrapper_t))) != PIPE_RWSTREAM_NoError)
235 return ErrorCode;
236
237 /* Clear the data ready for next reception */
238 Pipe_ClearIN();
239
240 /* Freeze the IN pipe after use */
241 Pipe_Freeze();
242
243 return PIPE_RWSTREAM_NoError;
244 }
245
246 /** Issues a Mass Storage class specific request to reset the attached device's Mass Storage interface,
247 * readying the device for the next CBW.
248 *
249 * \return A value from the USB_Host_SendControlErrorCodes_t enum
250 */
251 uint8_t MassStore_MassStorageReset(void)
252 {
253 USB_ControlRequest = (USB_Request_Header_t)
254 {
255 .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),
256 .bRequest = REQ_MassStorageReset,
257 .wValue = 0,
258 .wIndex = 0,
259 .wLength = 0,
260 };
261
262 /* Select the control pipe for the request transfer */
263 Pipe_SelectPipe(PIPE_CONTROLPIPE);
264
265 return USB_Host_SendControlRequest(NULL);
266 }
267
268 /** Issues a Mass Storage class specific request to determine the index of the highest numbered Logical
269 * Unit in the attached device.
270 *
271 * \param MaxLUNIndex Pointer to the location that the maximum LUN index value should be stored
272 *
273 * \return A value from the USB_Host_SendControlErrorCodes_t enum
274 */
275 uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)
276 {
277 uint8_t ErrorCode;
278
279 USB_ControlRequest = (USB_Request_Header_t)
280 {
281 .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
282 .bRequest = REQ_GetMaxLUN,
283 .wValue = 0,
284 .wIndex = 0,
285 .wLength = 1,
286 };
287
288 /* Select the control pipe for the request transfer */
289 Pipe_SelectPipe(PIPE_CONTROLPIPE);
290
291 if ((ErrorCode = USB_Host_SendControlRequest(MaxLUNIndex)) == HOST_SENDCONTROL_SetupStalled)
292 {
293 /* Clear the pipe stall */
294 Pipe_ClearStall();
295
296 /* Some faulty Mass Storage devices don't implement the GET_MAX_LUN request, so assume a single LUN */
297 *MaxLUNIndex = 0;
298 }
299
300 return ErrorCode;
301 }
302
303 /** Issues a SCSI Request Sense command to the attached device, to determine the current SCSI sense information. This
304 * gives error codes for the last issued SCSI command to the device.
305 *
306 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
307 * \param SensePtr Pointer to the sense data structure where the sense data from the device is to be stored
308 *
309 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
310 */
311 uint8_t MassStore_RequestSense(const uint8_t LUNIndex, const SCSI_Request_Sense_Response_t* const SensePtr)
312 {
313 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
314
315 /* Create a CBW with a SCSI command to issue REQUEST SENSE command */
316 SCSICommandBlock = (CommandBlockWrapper_t)
317 {
318 .Header =
319 {
320 .Signature = CBW_SIGNATURE,
321 .Tag = MassStore_Tag,
322 .DataTransferLength = sizeof(SCSI_Request_Sense_Response_t),
323 .Flags = COMMAND_DIRECTION_DATA_IN,
324 .LUN = LUNIndex,
325 .SCSICommandLength = 6
326 },
327
328 .SCSICommandData =
329 {
330 SCSI_CMD_REQUEST_SENSE,
331 0x00, // Reserved
332 0x00, // Reserved
333 0x00, // Reserved
334 sizeof(SCSI_Request_Sense_Response_t), // Allocation Length
335 0x00 // Unused (control)
336 }
337 };
338
339 /* Send SCSI command to the attached device */
340 MassStore_SendCommand();
341
342 /* Wait until data received from the device */
343 if ((ReturnCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)
344 {
345 Pipe_Freeze();
346 return ReturnCode;
347 }
348
349 /* Read the returned sense data into the buffer */
350 if ((ReturnCode = MassStore_SendReceiveData((uint8_t*)SensePtr)) != PIPE_RWSTREAM_NoError)
351 {
352 Pipe_Freeze();
353 return ReturnCode;
354 }
355
356 /* Read in the returned CSW from the device */
357 if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError)
358 {
359 Pipe_Freeze();
360 return ReturnCode;
361 }
362
363 return PIPE_RWSTREAM_NoError;
364 }
365
366 /** Issues a SCSI Device Block Read command to the attached device, to read in one or more data blocks from the
367 * storage medium into a buffer.
368 *
369 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
370 * \param BlockAddress Start block address to read from
371 * \param Blocks Number of blocks to read from the device
372 * \param BlockSize Size in bytes of each block to read
373 * \param BufferPtr Pointer to the buffer where the read data is to be written to
374 *
375 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
376 */
377 uint8_t MassStore_ReadDeviceBlock(const uint8_t LUNIndex, const uint32_t BlockAddress,
378 const uint8_t Blocks, const uint16_t BlockSize, void* BufferPtr)
379 {
380 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
381
382 /* Create a CBW with a SCSI command to read in the given blocks from the device */
383 SCSICommandBlock = (CommandBlockWrapper_t)
384 {
385 .Header =
386 {
387 .Signature = CBW_SIGNATURE,
388 .Tag = MassStore_Tag,
389 .DataTransferLength = ((uint32_t)Blocks * BlockSize),
390 .Flags = COMMAND_DIRECTION_DATA_IN,
391 .LUN = LUNIndex,
392 .SCSICommandLength = 10
393 },
394
395 .SCSICommandData =
396 {
397 SCSI_CMD_READ_10,
398 0x00, // Unused (control bits, all off)
399 (BlockAddress >> 24), // MSB of Block Address
400 (BlockAddress >> 16),
401 (BlockAddress >> 8),
402 (BlockAddress & 0xFF), // LSB of Block Address
403 0x00, // Unused (reserved)
404 0x00, // MSB of Total Blocks to Read
405 Blocks, // LSB of Total Blocks to Read
406 0x00 // Unused (control)
407 }
408 };
409
410 /* Send SCSI command to the attached device */
411 MassStore_SendCommand();
412
413 /* Wait until data received from the device */
414 if ((ReturnCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)
415 {
416 Pipe_Freeze();
417 return ReturnCode;
418 }
419
420 /* Read the returned block data into the buffer */
421 if ((ReturnCode = MassStore_SendReceiveData(BufferPtr)) != PIPE_RWSTREAM_NoError)
422 {
423 Pipe_Freeze();
424 return ReturnCode;
425 }
426
427 /* Read in the returned CSW from the device */
428 if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError)
429 {
430 Pipe_Freeze();
431 return ReturnCode;
432 }
433
434 return PIPE_RWSTREAM_NoError;
435 }
436
437 /** Issues a SCSI Device Block Write command to the attached device, to write one or more data blocks to the
438 * storage medium from a buffer.
439 *
440 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
441 * \param BlockAddress Start block address to write to
442 * \param Blocks Number of blocks to write to in the device
443 * \param BlockSize Size in bytes of each block to write
444 * \param BufferPtr Pointer to the buffer where the write data is to be sourced from
445 *
446 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
447 */
448 uint8_t MassStore_WriteDeviceBlock(const uint8_t LUNIndex, const uint32_t BlockAddress,
449 const uint8_t Blocks, const uint16_t BlockSize, void* BufferPtr)
450 {
451 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
452
453 /* Create a CBW with a SCSI command to write the given blocks to the device */
454 SCSICommandBlock = (CommandBlockWrapper_t)
455 {
456 .Header =
457 {
458 .Signature = CBW_SIGNATURE,
459 .Tag = MassStore_Tag,
460 .DataTransferLength = ((uint32_t)Blocks * BlockSize),
461 .Flags = COMMAND_DIRECTION_DATA_OUT,
462 .LUN = LUNIndex,
463 .SCSICommandLength = 10
464 },
465
466 .SCSICommandData =
467 {
468 SCSI_CMD_WRITE_10,
469 0x00, // Unused (control bits, all off)
470 (BlockAddress >> 24), // MSB of Block Address
471 (BlockAddress >> 16),
472 (BlockAddress >> 8),
473 (BlockAddress & 0xFF), // LSB of Block Address
474 0x00, // Unused (reserved)
475 0x00, // MSB of Total Blocks to Write
476 Blocks, // LSB of Total Blocks to Write
477 0x00 // Unused (control)
478 }
479 };
480
481 /* Send SCSI command to the attached device */
482 MassStore_SendCommand();
483
484 /* Write the data to the device from the buffer */
485 if ((ReturnCode = MassStore_SendReceiveData(BufferPtr)) != PIPE_RWSTREAM_NoError)
486 {
487 Pipe_Freeze();
488 return ReturnCode;
489 }
490
491 /* Read in the returned CSW from the device */
492 if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError)
493 {
494 Pipe_Freeze();
495 return ReturnCode;
496 }
497
498 return PIPE_RWSTREAM_NoError;
499 }
500
501 /** Issues a SCSI Device Test Unit Ready command to the attached device, to determine if the device is ready to accept
502 * other commands.
503 *
504 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
505 *
506 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
507 */
508 uint8_t MassStore_TestUnitReady(const uint8_t LUNIndex)
509 {
510 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
511
512 /* Create a CBW with a SCSI command to issue TEST UNIT READY command */
513 SCSICommandBlock = (CommandBlockWrapper_t)
514 {
515 .Header =
516 {
517 .Signature = CBW_SIGNATURE,
518 .Tag = MassStore_Tag,
519 .DataTransferLength = 0,
520 .Flags = COMMAND_DIRECTION_DATA_IN,
521 .LUN = LUNIndex,
522 .SCSICommandLength = 6
523 },
524
525 .SCSICommandData =
526 {
527 SCSI_CMD_TEST_UNIT_READY,
528 0x00, // Reserved
529 0x00, // Reserved
530 0x00, // Reserved
531 0x00, // Reserved
532 0x00 // Unused (control)
533 }
534 };
535
536 /* Send SCSI command to the attached device */
537 MassStore_SendCommand();
538
539 /* Read in the returned CSW from the device */
540 if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError)
541 {
542 Pipe_Freeze();
543 return ReturnCode;
544 }
545
546 return PIPE_RWSTREAM_NoError;
547 }
548
549 /** Issues a SCSI Device Read Capacity command to the attached device, to determine the capacity of the
550 * given Logical Unit within the device.
551 *
552 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
553 * \param CapacityPtr Device capacity structure where the capacity data is to be stored
554 *
555 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
556 */
557 uint8_t MassStore_ReadCapacity(const uint8_t LUNIndex, SCSI_Capacity_t* const CapacityPtr)
558 {
559 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
560
561 /* Create a CBW with a SCSI command to issue READ CAPACITY command */
562 SCSICommandBlock = (CommandBlockWrapper_t)
563 {
564 .Header =
565 {
566 .Signature = CBW_SIGNATURE,
567 .Tag = MassStore_Tag,
568 .DataTransferLength = sizeof(SCSI_Capacity_t),
569 .Flags = COMMAND_DIRECTION_DATA_IN,
570 .LUN = LUNIndex,
571 .SCSICommandLength = 10
572 },
573
574 .SCSICommandData =
575 {
576 SCSI_CMD_READ_CAPACITY_10,
577 0x00, // Reserved
578 0x00, // MSB of Logical block address
579 0x00,
580 0x00,
581 0x00, // LSB of Logical block address
582 0x00, // Reserved
583 0x00, // Reserved
584 0x00, // Partial Medium Indicator
585 0x00 // Unused (control)
586 }
587 };
588
589 /* Send SCSI command to the attached device */
590 MassStore_SendCommand();
591
592 /* Wait until data received from the device */
593 if ((ReturnCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)
594 {
595 Pipe_Freeze();
596 return ReturnCode;
597 }
598
599 /* Read the returned capacity data into the buffer */
600 if ((ReturnCode = MassStore_SendReceiveData(CapacityPtr)) != PIPE_RWSTREAM_NoError)
601 {
602 Pipe_Freeze();
603 return ReturnCode;
604 }
605
606 /* Endian-correct the read data */
607 CapacityPtr->Blocks = SwapEndian_32(CapacityPtr->Blocks);
608 CapacityPtr->BlockSize = SwapEndian_32(CapacityPtr->BlockSize);
609
610 /* Read in the returned CSW from the device */
611 if ((ReturnCode = MassStore_GetReturnedStatus()) != PIPE_RWSTREAM_NoError)
612 {
613 Pipe_Freeze();
614 return ReturnCode;
615 }
616
617 return PIPE_RWSTREAM_NoError;
618 }
619
620 /** Issues a SCSI Device Prevent/Allow Medium Removal command to the attached device, to lock the physical media from
621 * being removed. This is a legacy command for SCSI disks with removable storage (such as ZIP disks), but should still
622 * be issued before the first read or write command is sent.
623 *
624 * \param LUNIndex Index of the LUN inside the device the command is being addressed to
625 * \param PreventRemoval Whether or not the LUN media should be locked to prevent removal or not
626 *
627 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
628 */
629 uint8_t MassStore_PreventAllowMediumRemoval(const uint8_t LUNIndex, const bool PreventRemoval)
630 {
631 uint8_t ReturnCode = PIPE_RWSTREAM_NoError;
632
633 /* Create a CBW with a SCSI command to issue PREVENT ALLOW MEDIUM REMOVAL command */
634 SCSICommandBlock = (CommandBlockWrapper_t)
635 {
636 .Header =
637 {
638 .Signature = CBW_SIGNATURE,
639 .Tag = MassStore_Tag,
640 .DataTransferLength = 0,
641 .Flags = COMMAND_DIRECTION_DATA_OUT,
642 .LUN = LUNIndex,
643 .SCSICommandLength = 6
644 },
645
646 .SCSICommandData =
647 {
648 SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL,
649 0x00, // Reserved
650 0x00, // Reserved
651 PreventRemoval, // Prevent flag
652 0x00, // Reserved
653 0x00 // Unused (control)
654 }
655 };
656
657 /* Send SCSI command to the attached device */
658 MassStore_SendCommand();
659
660 /* Read in the returned CSW from the device */
661 if ((ReturnCode = MassStore_GetReturnedStatus()))
662 {
663 Pipe_Freeze();
664 return ReturnCode;
665 }
666
667 return PIPE_RWSTREAM_NoError;
668 }