Skip to content

Commit

Permalink
Fix support for UMS devices that don't byteswap the CSW signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkMatterCore committed Dec 16, 2021
1 parent 8821e8b commit de50aeb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ Thanks to
Changelog
--------------

**v0.2.6:**

* Updated codebase to use `localtime_r()` instead of `localtime()` to avoid possible race conditions with other threads.
* Fixed `fs-libs` building under Linux distros with pacman. Thanks to [ITotalJustice](https://github.com/ITotalJustice) for reporting this issue!
* Implemented support for UMS devices that don't byteswap the Command Status Wrapper signature before sending back SCSI command responses.Thanks to [rdmrocha](https://github.com/rdmrocha) for reporting this issue!

**v0.2.5:**

* Updated lwext4 patch to fix mountpoint corruption issues if a mountpoint name is reused after a previous call to `ext4_mount` failed.
Expand Down
2 changes: 1 addition & 1 deletion include/usbhsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {
/// Library version.
#define LIBUSBHSFS_VERSION_MAJOR 0
#define LIBUSBHSFS_VERSION_MINOR 2
#define LIBUSBHSFS_VERSION_MICRO 5
#define LIBUSBHSFS_VERSION_MICRO 6

/// Helper macro to generate a string based on a filesystem type value.
#define LIBUSBHSFS_FS_TYPE_STR(x) ((x) == UsbHsFsDeviceFileSystemType_FAT12 ? "FAT12" : ((x) == UsbHsFsDeviceFileSystemType_FAT16 ? "FAT16" : ((x) == UsbHsFsDeviceFileSystemType_FAT32 ? "FAT32" : \
Expand Down
4 changes: 2 additions & 2 deletions source/usbhsfs_scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ static bool usbHsFsScsiTransferCommand(UsbHsFsDriveContext *drive_ctx, ScsiComma
if (receive && rest_size == sizeof(ScsiCommandStatusWrapper))
{
memcpy(&csw, xfer_buf, sizeof(ScsiCommandStatusWrapper));
if (csw.dCSWSignature == __builtin_bswap32(SCSI_CSW_SIGNATURE) && csw.dCSWTag == cbw->dCBWTag)
if ((csw.dCSWSignature == SCSI_CSW_SIGNATURE || csw.dCSWSignature == __builtin_bswap32(SCSI_CSW_SIGNATURE)) && csw.dCSWTag == cbw->dCBWTag)
{
USBHSFS_LOG_DATA(&csw, sizeof(ScsiCommandStatusWrapper), "Data from unexpected CSW (interface %d, LUN %u):", drive_ctx->usb_if_id, cbw->bCBWLUN);

Expand Down Expand Up @@ -1150,7 +1150,7 @@ static bool usbHsFsScsiReceiveCommandStatusWrapper(UsbHsFsDriveContext *drive_ct
USBHSFS_LOG_DATA(csw, sizeof(ScsiCommandStatusWrapper), "Data from received CSW (interface %d, LUN %u):", drive_ctx->usb_if_id, cbw->bCBWLUN);

/* Check CSW signature. */
if (csw->dCSWSignature != __builtin_bswap32(SCSI_CSW_SIGNATURE))
if (csw->dCSWSignature != SCSI_CSW_SIGNATURE && csw->dCSWSignature != __builtin_bswap32(SCSI_CSW_SIGNATURE))
{
USBHSFS_LOG_MSG("Invalid CSW signature! (0x%08X) (interface %d, LUN %u).", __builtin_bswap32(csw->dCSWSignature), drive_ctx->usb_if_id, cbw->bCBWLUN);
goto end;
Expand Down

0 comments on commit de50aeb

Please sign in to comment.