3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all 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.
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
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.
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
50 #define INCLUDE_FROM_MASSSTORE_COMMANDS_C
51 #include "MassStoreCommands.h"
53 /** Current Tag value used in issued CBWs to the device. This is automatically incremented
54 * each time a command is sent, and is not externally accessible.
56 static uint32_t MassStore_Tag
= 1;
59 /** Routine to send the current CBW to the device, and increment the Tag value as needed.
61 * \param[in] SCSICommandBlock Pointer to a SCSI command block structure to send to the attached device
62 * \param[in,out] BufferPtr Pointer to a buffer for the data to send or receive to/from the device, or NULL if no data
64 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
66 static uint8_t MassStore_SendCommand(MS_CommandBlockWrapper_t
* const SCSICommandBlock
,
69 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
71 /* Wrap Tag value when invalid - MS class defines tag values of 0 and 0xFFFFFFFF to be invalid */
72 if (++MassStore_Tag
== 0xFFFFFFFF)
75 /* Each transmission should have a unique tag value, increment before use */
76 SCSICommandBlock
->Tag
= MassStore_Tag
;
78 /* Select the OUT data pipe for CBW transmission */
79 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE
);
82 /* Write the CBW command to the OUT pipe */
83 if ((ErrorCode
= Pipe_Write_Stream_LE(SCSICommandBlock
, sizeof(MS_CommandBlockWrapper_t
), NULL
)) !=
84 PIPE_RWSTREAM_NoError
)
89 /* Send the data in the OUT pipe to the attached device */
92 /* Wait until command has been sent */
93 Pipe_WaitUntilReady();
95 /* Freeze pipe after use */
98 /* Send data if any has been given */
99 if ((BufferPtr
!= NULL
) &&
100 ((ErrorCode
= MassStore_SendReceiveData(SCSICommandBlock
, BufferPtr
)) != PIPE_READYWAIT_NoError
))
109 /** Waits until the attached device is ready to accept data following a CBW, checking
110 * to ensure that the device has not stalled the transaction.
112 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
114 static uint8_t MassStore_WaitForDataReceived(void)
116 uint16_t TimeoutMSRem
= COMMAND_DATA_TIMEOUT_MS
;
117 uint16_t PreviousFrameNumber
= USB_Host_GetFrameNumber();
119 /* Select the IN data pipe for data reception */
120 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
123 /* Wait until data received in the IN pipe */
124 while (!(Pipe_IsINReceived()))
126 uint16_t CurrentFrameNumber
= USB_Host_GetFrameNumber();
128 /* Check to see if a new frame has been issued (1ms elapsed) */
129 if (CurrentFrameNumber
!= PreviousFrameNumber
)
131 /* Save the new frame number and decrement the timeout period */
132 PreviousFrameNumber
= CurrentFrameNumber
;
135 /* Check to see if the timeout period for the command has elapsed */
137 return PIPE_RWSTREAM_Timeout
;
141 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE
);
144 /* Check if pipe stalled (command failed by device) */
145 if (Pipe_IsStalled())
147 /* Clear the stall condition on the OUT pipe */
148 USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress());
150 return PIPE_RWSTREAM_PipeStalled
;
154 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
157 /* Check if pipe stalled (command failed by device) */
158 if (Pipe_IsStalled())
160 /* Clear the stall condition on the IN pipe */
161 USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress());
163 return PIPE_RWSTREAM_PipeStalled
;
166 /* Check to see if the device was disconnected, if so exit function */
167 if (USB_HostState
== HOST_STATE_Unattached
)
168 return PIPE_RWSTREAM_DeviceDisconnected
;
171 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
174 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE
);
177 return PIPE_RWSTREAM_NoError
;
180 /** Sends or receives the transaction's data stage to or from the attached device, reading or
181 * writing to the nominated buffer.
183 * \param[in] SCSICommandBlock Pointer to a SCSI command block structure being sent to the attached device
184 * \param[in,out] BufferPtr Pointer to the data buffer to read from or write to
186 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
188 static uint8_t MassStore_SendReceiveData(MS_CommandBlockWrapper_t
* const SCSICommandBlock
,
191 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
192 uint16_t BytesRem
= SCSICommandBlock
->DataTransferLength
;
194 /* Check the direction of the SCSI command data stage */
195 if (SCSICommandBlock
->Flags
& MS_COMMAND_DIR_DATA_IN
)
197 /* Wait until the device has replied with some data */
198 if ((ErrorCode
= MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError
)
201 /* Select the IN data pipe for data reception */
202 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
205 /* Read in the block data from the pipe */
206 if ((ErrorCode
= Pipe_Read_Stream_LE(BufferPtr
, BytesRem
, NULL
)) != PIPE_RWSTREAM_NoError
)
209 /* Acknowledge the packet */
214 /* Select the OUT data pipe for data transmission */
215 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE
);
218 /* Write the block data to the pipe */
219 if ((ErrorCode
= Pipe_Write_Stream_LE(BufferPtr
, BytesRem
, NULL
)) != PIPE_RWSTREAM_NoError
)
222 /* Acknowledge the packet */
225 while (!(Pipe_IsOUTReady()))
227 if (USB_HostState
== HOST_STATE_Unattached
)
228 return PIPE_RWSTREAM_DeviceDisconnected
;
232 /* Freeze used pipe after use */
235 return PIPE_RWSTREAM_NoError
;
238 /** Routine to receive the current CSW from the device.
240 * \param[out] SCSICommandStatus Pointer to a destination where the returned status data should be stored
242 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
244 static uint8_t MassStore_GetReturnedStatus(MS_CommandStatusWrapper_t
* const SCSICommandStatus
)
246 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
248 /* If an error in the command occurred, abort */
249 if ((ErrorCode
= MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError
)
252 /* Select the IN data pipe for data reception */
253 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
256 /* Load in the CSW from the attached device */
257 if ((ErrorCode
= Pipe_Read_Stream_LE(SCSICommandStatus
, sizeof(MS_CommandStatusWrapper_t
), NULL
)) !=
258 PIPE_RWSTREAM_NoError
)
263 /* Clear the data ready for next reception */
266 /* Freeze the IN pipe after use */
269 /* Check to see if command failed */
270 if (SCSICommandStatus
->Status
!= MS_SCSI_COMMAND_Pass
)
271 ErrorCode
= MASS_STORE_SCSI_COMMAND_FAILED
;
276 /** Issues a Mass Storage class specific request to reset the attached device's Mass Storage interface,
277 * readying the device for the next CBW. The Data endpoints are cleared of any STALL condition once this
278 * command completes sucessfuly.
280 * \return A value from the USB_Host_SendControlErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
282 uint8_t MassStore_MassStorageReset(void)
286 USB_ControlRequest
= (USB_Request_Header_t
)
288 .bmRequestType
= (REQDIR_HOSTTODEVICE
| REQTYPE_CLASS
| REQREC_INTERFACE
),
289 .bRequest
= MS_REQ_MassStorageReset
,
295 /* Select the control pipe for the request transfer */
296 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
298 if ((ErrorCode
= USB_Host_SendControlRequest(NULL
)) != HOST_SENDCONTROL_Successful
)
301 /* Select first data pipe to clear STALL condition if one exists */
302 Pipe_SelectPipe(MASS_STORE_DATA_IN_PIPE
);
304 if ((ErrorCode
= USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress())) != HOST_SENDCONTROL_Successful
)
307 /* Select second data pipe to clear STALL condition if one exists */
308 Pipe_SelectPipe(MASS_STORE_DATA_OUT_PIPE
);
310 if ((ErrorCode
= USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress())) != HOST_SENDCONTROL_Successful
)
313 return HOST_SENDCONTROL_Successful
;
316 /** Issues a Mass Storage class specific request to determine the index of the highest numbered Logical
317 * Unit in the attached device.
319 * \note Some devices do not support this request, and will STALL it when issued. To get around this,
320 * on unsupported devices the max LUN index will be reported as zero and no error will be returned
321 * if the device STALLs the request.
323 * \param[out] MaxLUNIndex Pointer to the location that the maximum LUN index value should be stored
325 * \return A value from the USB_Host_SendControlErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
327 uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex
)
329 uint8_t ErrorCode
= HOST_SENDCONTROL_Successful
;
331 USB_ControlRequest
= (USB_Request_Header_t
)
333 .bmRequestType
= (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
),
334 .bRequest
= MS_REQ_GetMaxLUN
,
340 /* Select the control pipe for the request transfer */
341 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
343 if ((ErrorCode
= USB_Host_SendControlRequest(MaxLUNIndex
)) == HOST_SENDCONTROL_SetupStalled
)
345 /* Clear the pipe stall */
348 /* Some faulty Mass Storage devices don't implement the GET_MAX_LUN request, so assume a single LUN */
351 /* Clear the error, and pretend the request executed correctly if the device STALLed it */
352 ErrorCode
= HOST_SENDCONTROL_Successful
;
358 /** Issues a SCSI Inquiry command to the attached device, to determine the device's information. This
359 * gives information on the device's capabilities.
361 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
362 * \param[out] InquiryPtr Pointer to the inquiry data structure where the inquiry data from the device is to be stored
364 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
366 uint8_t MassStore_Inquiry(const uint8_t LUNIndex
,
367 SCSI_Inquiry_Response_t
* const InquiryPtr
)
369 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
371 /* Create a CBW with a SCSI command to issue INQUIRY command */
372 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
374 .Signature
= MS_CBW_SIGNATURE
,
375 .DataTransferLength
= sizeof(SCSI_Inquiry_Response_t
),
376 .Flags
= MS_COMMAND_DIR_DATA_IN
,
378 .SCSICommandLength
= 6,
385 sizeof(SCSI_Inquiry_Response_t
), // Allocation Length
386 0x00 // Unused (control)
390 MS_CommandStatusWrapper_t SCSICommandStatus
;
392 /* Send the command and any data to the attached device */
393 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, InquiryPtr
)) != PIPE_RWSTREAM_NoError
)
399 /* Retrieve status information from the attached device */
400 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
409 /** Issues a SCSI Request Sense command to the attached device, to determine the current SCSI sense information. This
410 * gives error codes for the last issued SCSI command to the device.
412 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
413 * \param[out] SensePtr Pointer to the sense data structure where the sense data from the device is to be stored
415 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
417 uint8_t MassStore_RequestSense(const uint8_t LUNIndex
,
418 SCSI_Request_Sense_Response_t
* const SensePtr
)
420 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
422 /* Create a CBW with a SCSI command to issue REQUEST SENSE command */
423 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
425 .Signature
= MS_CBW_SIGNATURE
,
426 .DataTransferLength
= sizeof(SCSI_Request_Sense_Response_t
),
427 .Flags
= MS_COMMAND_DIR_DATA_IN
,
429 .SCSICommandLength
= 6,
432 SCSI_CMD_REQUEST_SENSE
,
436 sizeof(SCSI_Request_Sense_Response_t
), // Allocation Length
437 0x00 // Unused (control)
441 MS_CommandStatusWrapper_t SCSICommandStatus
;
443 /* Send the command and any data to the attached device */
444 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, SensePtr
)) != PIPE_RWSTREAM_NoError
)
450 /* Retrieve status information from the attached device */
451 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
460 /** Issues a SCSI Device Block Read command to the attached device, to read in one or more data blocks from the
461 * storage medium into a buffer.
463 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
464 * \param[in] BlockAddress Start block address to read from
465 * \param[in] Blocks Number of blocks to read from the device
466 * \param[in] BlockSize Size in bytes of each block to read
467 * \param[out] BufferPtr Pointer to the buffer where the read data is to be written to
469 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
471 uint8_t MassStore_ReadDeviceBlock(const uint8_t LUNIndex
,
472 const uint32_t BlockAddress
,
473 const uint8_t Blocks
,
474 const uint16_t BlockSize
,
477 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
479 /* Create a CBW with a SCSI command to read in the given blocks from the device */
480 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
482 .Signature
= MS_CBW_SIGNATURE
,
483 .DataTransferLength
= ((uint32_t)Blocks
* BlockSize
),
484 .Flags
= MS_COMMAND_DIR_DATA_IN
,
486 .SCSICommandLength
= 10,
490 0x00, // Unused (control bits, all off)
491 (BlockAddress
>> 24), // MSB of Block Address
492 (BlockAddress
>> 16),
494 (BlockAddress
& 0xFF), // LSB of Block Address
496 0x00, // MSB of Total Blocks to Read
497 Blocks
, // LSB of Total Blocks to Read
498 0x00 // Unused (control)
502 MS_CommandStatusWrapper_t SCSICommandStatus
;
504 /* Send the command and any data to the attached device */
505 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, BufferPtr
)) != PIPE_RWSTREAM_NoError
)
511 /* Retrieve status information from the attached device */
512 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
521 /** Issues a SCSI Device Block Write command to the attached device, to write one or more data blocks to the
522 * storage medium from a buffer.
524 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
525 * \param[in] BlockAddress Start block address to write to
526 * \param[in] Blocks Number of blocks to write to in the device
527 * \param[in] BlockSize Size in bytes of each block to write
528 * \param[in] BufferPtr Pointer to the buffer where the write data is to be sourced from
530 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
532 uint8_t MassStore_WriteDeviceBlock(const uint8_t LUNIndex
,
533 const uint32_t BlockAddress
,
534 const uint8_t Blocks
,
535 const uint16_t BlockSize
,
538 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
540 /* Create a CBW with a SCSI command to write the given blocks to the device */
541 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
543 .Signature
= MS_CBW_SIGNATURE
,
544 .DataTransferLength
= ((uint32_t)Blocks
* BlockSize
),
545 .Flags
= MS_COMMAND_DIR_DATA_OUT
,
547 .SCSICommandLength
= 10,
551 0x00, // Unused (control bits, all off)
552 (BlockAddress
>> 24), // MSB of Block Address
553 (BlockAddress
>> 16),
555 (BlockAddress
& 0xFF), // LSB of Block Address
556 0x00, // Unused (reserved)
557 0x00, // MSB of Total Blocks to Write
558 Blocks
, // LSB of Total Blocks to Write
559 0x00 // Unused (control)
563 MS_CommandStatusWrapper_t SCSICommandStatus
;
565 /* Send the command and any data to the attached device */
566 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, BufferPtr
)) != PIPE_RWSTREAM_NoError
)
572 /* Retrieve status information from the attached device */
573 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
582 /** Issues a SCSI Device Test Unit Ready command to the attached device, to determine if the device is ready to accept
585 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
587 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
589 uint8_t MassStore_TestUnitReady(const uint8_t LUNIndex
)
591 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
593 /* Create a CBW with a SCSI command to issue TEST UNIT READY command */
594 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
596 .Signature
= MS_CBW_SIGNATURE
,
597 .DataTransferLength
= 0,
598 .Flags
= MS_COMMAND_DIR_DATA_IN
,
600 .SCSICommandLength
= 6,
603 SCSI_CMD_TEST_UNIT_READY
,
608 0x00 // Unused (control)
612 MS_CommandStatusWrapper_t SCSICommandStatus
;
614 /* Send the command and any data to the attached device */
615 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, NULL
)) != PIPE_RWSTREAM_NoError
)
621 /* Retrieve status information from the attached device */
622 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
631 /** Issues a SCSI Device Read Capacity command to the attached device, to determine the capacity of the
632 * given Logical Unit within the device.
634 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
635 * \param[out] CapacityPtr Device capacity structure where the capacity data is to be stored
637 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
639 uint8_t MassStore_ReadCapacity(const uint8_t LUNIndex
,
640 SCSI_Capacity_t
* const CapacityPtr
)
642 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
644 /* Create a CBW with a SCSI command to issue READ CAPACITY command */
645 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
647 .Signature
= MS_CBW_SIGNATURE
,
648 .DataTransferLength
= sizeof(SCSI_Capacity_t
),
649 .Flags
= MS_COMMAND_DIR_DATA_IN
,
651 .SCSICommandLength
= 10,
654 SCSI_CMD_READ_CAPACITY_10
,
656 0x00, // MSB of Logical block address
659 0x00, // LSB of Logical block address
662 0x00, // Partial Medium Indicator
663 0x00 // Unused (control)
667 MS_CommandStatusWrapper_t SCSICommandStatus
;
669 /* Send the command and any data to the attached device */
670 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, CapacityPtr
)) != PIPE_RWSTREAM_NoError
)
676 /* Endian-correct the read data */
677 CapacityPtr
->Blocks
= SwapEndian_32(CapacityPtr
->Blocks
);
678 CapacityPtr
->BlockSize
= SwapEndian_32(CapacityPtr
->BlockSize
);
680 /* Retrieve status information from the attached device */
681 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)
690 /** Issues a SCSI Device Prevent/Allow Medium Removal command to the attached device, to lock the physical media from
691 * being removed. This is a legacy command for SCSI disks with removable storage (such as ZIP disks), but should still
692 * be issued before the first read or write command is sent.
694 * \param[in] LUNIndex Index of the LUN inside the device the command is being addressed to
695 * \param[in] PreventRemoval Whether or not the LUN media should be locked to prevent removal or not
697 * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails
699 uint8_t MassStore_PreventAllowMediumRemoval(const uint8_t LUNIndex
,
700 const bool PreventRemoval
)
702 uint8_t ErrorCode
= PIPE_RWSTREAM_NoError
;
704 /* Create a CBW with a SCSI command to issue PREVENT ALLOW MEDIUM REMOVAL command */
705 MS_CommandBlockWrapper_t SCSICommandBlock
= (MS_CommandBlockWrapper_t
)
707 .Signature
= MS_CBW_SIGNATURE
,
708 .DataTransferLength
= 0,
709 .Flags
= MS_COMMAND_DIR_DATA_OUT
,
711 .SCSICommandLength
= 6,
714 SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
,
717 PreventRemoval
, // Prevent flag
719 0x00 // Unused (control)
723 MS_CommandStatusWrapper_t SCSICommandStatus
;
725 /* Send the command and any data to the attached device */
726 if ((ErrorCode
= MassStore_SendCommand(&SCSICommandBlock
, NULL
)) != PIPE_RWSTREAM_NoError
)
732 /* Retrieve status information from the attached device */
733 if ((ErrorCode
= MassStore_GetReturnedStatus(&SCSICommandStatus
)) != PIPE_RWSTREAM_NoError
)