File tree Expand file tree Collapse file tree
firmware/hw_layer/mass_storage Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,11 +99,15 @@ void MassStorageController::ThreadTask() {
9999 }
100100
101101 if (cbwValid (m_cbw, status) && cbwMeaningful (m_cbw)) {
102- auto target = &m_luns[m_cbw.lun ].target ;
103- if (SCSI_SUCCESS == scsiExecCmd (target, m_cbw.cmd_data )) {
104- sendCsw (CSW_STATUS_PASSED , 0 );
105- } else {
106- sendCsw (CSW_STATUS_FAILED , scsiResidue (target));
102+ // Get the LUN from the incoming CBW packet
103+ uint8_t target_lun = m_cbw.lun & 0x0F ; // Mask out reserved bits
104+ if (target_lun <= USB_MSD_LUN_COUNT ) {
105+ auto target = &m_luns[target_lun].target ;
106+ if (SCSI_SUCCESS == scsiExecCmd (target, m_cbw.cmd_data )) {
107+ sendCsw (CSW_STATUS_PASSED , 0 );
108+ } else {
109+ sendCsw (CSW_STATUS_FAILED , scsiResidue (target));
110+ }
107111 }
108112 } else {
109113 // ignore incorrect CBW
You can’t perform that action at this time.
0 commit comments