+       return ErrorCode;\r
+}\r
+\r
+uint8_t MS_Host_ResetMSInterface(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo)\r
+{\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
+                       .bRequest      = REQ_MassStorageReset,\r
+                       .wValue        = 0,\r
+                       .wIndex        = MSInterfaceInfo->State.InterfaceNumber,\r
+                       .wLength       = 0,\r
+               };\r
+       \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
+       return USB_Host_SendControlRequest(NULL);\r
+}\r
+\r
+uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, uint8_t* const MaxLUNIndex)\r
+{\r
+       uint8_t ErrorCode = HOST_SENDCONTROL_Successful;\r
+\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),\r
+                       .bRequest      = REQ_GetMaxLUN,\r
+                       .wValue        = 0,\r
+                       .wIndex        = MSInterfaceInfo->State.InterfaceNumber,\r
+                       .wLength       = 1,\r
+               };\r
+               \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
+       if ((ErrorCode = USB_Host_SendControlRequest(MaxLUNIndex)) != HOST_SENDCONTROL_Successful)\r
+       {\r
+               *MaxLUNIndex = 0;\r
+               ErrorCode = HOST_SENDCONTROL_Successful;\r
+       }\r
+       \r
+       return ErrorCode;\r
+}\r
+\r
+uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex,\r
+                               SCSI_Inquiry_Response_t* const InquiryData)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+         \r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = sizeof(SCSI_Inquiry_Response_t),\r
+                       .Flags              = COMMAND_DIRECTION_DATA_IN,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 6,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_INQUIRY,\r
+                                       0x00,                            // Reserved\r
+                                       0x00,                            // Reserved\r
+                                       0x00,                            // Reserved\r
+                                       sizeof(SCSI_Inquiry_Response_t), // Allocation Length\r
+                                       0x00                             // Unused (control)\r
+                               }\r
+               };\r
+       \r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, InquiryData)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;     \r
+       \r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;      \r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = 0,\r
+                       .Flags              = COMMAND_DIRECTION_DATA_IN,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 6,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_TEST_UNIT_READY,\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Reserved\r
+                                       0x00                    // Unused (control)\r
+                               }\r
+               };\r
+       \r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;     \r
+       \r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex,\r
+                                   SCSI_Capacity_t* const DeviceCapacity)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = sizeof(SCSI_Capacity_t),\r
+                       .Flags              = COMMAND_DIRECTION_DATA_IN,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 10,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_READ_CAPACITY_10,\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // MSB of Logical block address\r
+                                       0x00,\r
+                                       0x00,\r
+                                       0x00,                   // LSB of Logical block address\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Partial Medium Indicator\r
+                                       0x00                    // Unused (control)\r
+                               }\r
+               };\r
+       \r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, DeviceCapacity)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       SwapEndian_n(&DeviceCapacity->Blocks,    sizeof(DeviceCapacity->Blocks));\r
+       SwapEndian_n(&DeviceCapacity->BlockSize, sizeof(DeviceCapacity->BlockSize));\r
+       \r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex,\r
+                             SCSI_Request_Sense_Response_t* const SenseData)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = sizeof(SCSI_Request_Sense_Response_t),\r
+                       .Flags              = COMMAND_DIRECTION_DATA_IN,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 6,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_REQUEST_SENSE,\r
+                                       0x00,                                  // Reserved\r
+                                       0x00,                                  // Reserved\r
+                                       0x00,                                  // Reserved\r
+                                       sizeof(SCSI_Request_Sense_Response_t), // Allocation Length\r
+                                       0x00                                   // Unused (control)\r
+                               }\r
+               };\r
+       \r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, SenseData)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex,\r
+                                          const bool PreventRemoval)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = 0,\r
+                       .Flags              = COMMAND_DIRECTION_DATA_OUT,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 6,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL,\r
+                                       0x00,                   // Reserved\r
+                                       0x00,                   // Reserved\r
+                                       PreventRemoval,         // Prevent flag\r
+                                       0x00,                   // Reserved\r
+                                       0x00                    // Unused (control)\r
+                               }\r
+               };\r
+       \r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+       \r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex, const uint32_t BlockAddress,\r
+                                 const uint8_t Blocks, const uint16_t BlockSize, void* BlockBuffer)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = ((uint32_t)Blocks * BlockSize),\r
+                       .Flags              = COMMAND_DIRECTION_DATA_IN,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 10,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_READ_10,\r
+                                       0x00,                   // Unused (control bits, all off)\r
+                                       (BlockAddress >> 24),   // MSB of Block Address\r
+                                       (BlockAddress >> 16),\r
+                                       (BlockAddress >> 8),\r
+                                       (BlockAddress & 0xFF),  // LSB of Block Address\r
+                                       0x00,                   // Unused (reserved)\r
+                                       0x00,                   // MSB of Total Blocks to Read\r
+                                       Blocks,                 // LSB of Total Blocks to Read\r
+                                       0x00                    // Unused (control)\r
+                               }\r
+               };\r
+\r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, const uint8_t LUNIndex, const uint32_t BlockAddress,\r
+                                  const uint8_t Blocks, const uint16_t BlockSize, const void* BlockBuffer)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
+       uint8_t ErrorCode;\r
+\r
+       MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)\r
+               {\r
+                       .DataTransferLength = ((uint32_t)Blocks * BlockSize),\r
+                       .Flags              = COMMAND_DIRECTION_DATA_OUT,\r
+                       .LUN                = LUNIndex,\r
+                       .SCSICommandLength  = 10,\r
+                       .SCSICommandData    =\r
+                               {\r
+                                       SCSI_CMD_WRITE_10,\r
+                                       0x00,                   // Unused (control bits, all off)\r
+                                       (BlockAddress >> 24),   // MSB of Block Address\r
+                                       (BlockAddress >> 16),\r
+                                       (BlockAddress >> 8),\r
+                                       (BlockAddress & 0xFF),  // LSB of Block Address\r
+                                       0x00,                   // Unused (reserved)\r
+                                       0x00,                   // MSB of Total Blocks to Write\r
+                                       Blocks,                 // LSB of Total Blocks to Write\r
+                                       0x00                    // Unused (control)\r
+                               }\r
+               };\r
+\r
+       MS_CommandStatusWrapper_t SCSICommandStatus;\r
+\r
+       if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+       \r
+       if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       return PIPE_RWSTREAM_NoError;\r