Skip to content

Commit 465304f

Browse files
committed
USB MSC: Fix SCIS mode sense write protection bit
1 parent 6749f7b commit 465304f

File tree

3 files changed

+35
-0
lines changed
  • lib/main
    • STM32F4/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src
    • STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src
    • STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src

3 files changed

+35
-0
lines changed

lib/main/STM32F4/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+12
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
343343
len--;
344344
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
345345
}
346+
347+
// set bit 7 of the device configuration byte to indicate write protection
348+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
349+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
350+
}
351+
346352
return 0;
347353
}
348354

@@ -365,6 +371,12 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
365371
len--;
366372
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
367373
}
374+
375+
// set bit 7 of the device configuration byte to indicate write protection
376+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
377+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
378+
}
379+
368380
return 0;
369381
}
370382

lib/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+12
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
347347
len--;
348348
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
349349
}
350+
351+
// set bit 7 of the device configuration byte to indicate write protection
352+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
353+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
354+
}
355+
350356
return 0;
351357
}
352358

@@ -370,6 +376,12 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
370376
len--;
371377
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
372378
}
379+
380+
// set bit 7 of the device configuration byte to indicate write protection
381+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
382+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
383+
}
384+
373385
return 0;
374386
}
375387

lib/main/STM32H7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

+11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p
346346
len--;
347347
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
348348
}
349+
350+
// set bit 7 of the device configuration byte to indicate write protection
351+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
352+
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
353+
}
354+
349355
return 0;
350356
}
351357

@@ -371,6 +377,11 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
371377
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
372378
}
373379

380+
// set bit 7 of the device configuration byte to indicate write protection
381+
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
382+
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
383+
}
384+
374385
return 0;
375386
}
376387

0 commit comments

Comments
 (0)