Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic USB CDROM support via USB MSC #2954

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/device/cdc_msc/src/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
return (int32_t) resplen;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
(void)lun;
return MSC_SCSI_DEVICE_BLOCK;
}

#endif
6 changes: 6 additions & 0 deletions examples/device/cdc_msc_freertos/src/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
return (int32_t) resplen;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
(void)lun;
return MSC_SCSI_DEVICE_BLOCK;
}

#endif
6 changes: 6 additions & 0 deletions examples/device/dynamic_configuration/src/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
return resplen;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
(void)lun;
return MSC_SCSI_DEVICE_BLOCK;
}

#endif
6 changes: 6 additions & 0 deletions examples/device/msc_dual_lun/src/msc_disk_dual.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,10 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, u
return resplen;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
(void)lun;
return MSC_SCSI_DEVICE_BLOCK;
}

#endif
7 changes: 7 additions & 0 deletions src/class/msc/msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ typedef enum
MSC_CSW_STATUS_PHASE_ERROR ///< MSC_CSW_STATUS_PHASE_ERROR
}msc_csw_status_t;

/// MassStorage SCSI device type
typedef enum
{
MSC_SCSI_DEVICE_BLOCK = 0 , ///< USB removable disk
MSC_SCSI_DEVICE_CDROM , ///< USB CDROM
}msc_scsi_device_type_t;

/// Command Block Wrapper
typedef struct TU_ATTR_PACKED
{
Expand Down
6 changes: 6 additions & 0 deletions src/class/msc/msc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
.additional_length = sizeof(scsi_inquiry_resp_t) - 5,
};

if (tud_msc_scsi_device_type(lun) == MSC_SCSI_DEVICE_CDROM)
{
inquiry_rsp.peripheral_device_type = 0x05;
inquiry_rsp.peripheral_qualifier = 0x0;
}

// vendor_id, product_id, product_rev is space padded string
memset(inquiry_rsp.vendor_id , ' ', sizeof(inquiry_rsp.vendor_id));
memset(inquiry_rsp.product_id , ' ', sizeof(inquiry_rsp.product_id));
Expand Down
3 changes: 3 additions & 0 deletions src/class/msc/msc_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[1
// Invoked to check if device is writable as part of SCSI WRITE10
TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);

// Invoked when INQUIRY received to return the correct SCSI device type.
msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun);

//--------------------------------------------------------------------+
// Internal Class Driver API
//--------------------------------------------------------------------+
Expand Down
6 changes: 6 additions & 0 deletions test/fuzz/msc_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer,

return 0;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
(void)lun;
return MSC_SCSI_DEVICE_BLOCK;
}
}

#endif
6 changes: 6 additions & 0 deletions test/unit-test/test/device/msc/test_msc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
return resplen;
}

msc_scsi_device_type_t tud_msc_scsi_device_type(uint8_t lun)
{
return MSC_SCSI_DEVICE_BLOCK;
}


//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
Expand Down
Loading