Browse Source

Ignore mass storage commands after receiving SCSI stop/eject

USG_1.0 1.0r04
Robert Fisk 4 years ago
parent
commit
086158525b
  1. 2
      Upstream/Inc/upstream_msc.h
  2. 2
      Upstream/Inc/upstream_statemachine.h
  3. 9
      Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c
  4. 1
      Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c
  5. 10
      Upstream/Src/upstream_msc.c
  6. 27
      Upstream/Src/upstream_statemachine.c

2
Upstream/Inc/upstream_msc.h

@ -36,7 +36,7 @@ HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
uint32_t writeBlockCount);
HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength8);
void Upstream_MSC_RegisterDisconnect(void);
#endif /* INC_UPSTREAM_MSC_H_ */

2
Upstream/Inc/upstream_statemachine.h

@ -24,6 +24,7 @@ typedef enum
STATE_WAIT_DEVICE,
STATE_DEVICE_ACTIVE,
STATE_SUSPENDED,
STATE_DISCONNECTING,
STATE_ERROR
} UpstreamStateTypeDef;
@ -46,6 +47,7 @@ void Upstream_StateMachine_DeviceDisconnected(void);
void Upstream_StateMachine_Suspend(void);
void Upstream_StateMachine_CheckResume(void);
void Upstream_StateMachine_Wakeup(void);
void Upstream_StateMachine_RegisterDisconnect(void);

9
Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c

@ -379,13 +379,12 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
USBD_LL_CloseEP(pdev,
MSC_EPIN_ADDR);
/* De-Init the BOT layer */
MSC_BOT_DeInit(pdev);
/* Free MSC Class Resources */
if(pdev->pClassData != NULL)
{
/* De-Init the BOT layer */
MSC_BOT_DeInit(pdev);
/* Free MSC Class Resources */
USBD_free(pdev->pClassData);
pdev->pClassData = NULL;
}

1
Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c

@ -550,6 +550,7 @@ static void SCSI_StartStopUnit(void)
if ((SCSI_ProcessCmd_params[4] & START_STOP_DATA_MASK) == START_STOP_DATA_EJECT_STOP_MOTOR)
{
USBD_RequestStop(SCSI_ProcessCmd_pdev); //Host is signalling us to disconnect
Upstream_MSC_RegisterDisconnect();
}
SCSI_ProcessCmd_hmsc->bot_data_length = 0;

10
Upstream/Src/upstream_msc.c

@ -369,7 +369,15 @@ HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packet
packetToSend->Command = COMMAND_MSC_WRITE;
return Upstream_TransmitPacket(packetToSend);
}
#endif
#endif //#ifdef CONFIG_MASS_STORAGE_WRITES_PERMITTED
void Upstream_MSC_RegisterDisconnect(void)
{
Upstream_StateMachine_RegisterDisconnect();
}
#endif //#ifdef CONFIG_MASS_STORAGE_ENABLED

27
Upstream/Src/upstream_statemachine.c

@ -79,19 +79,21 @@ void Upstream_StateMachine_SetErrorState(void)
InterfaceCommandClassTypeDef Upstream_StateMachine_CheckActiveClass(void)
{
if (UpstreamState == STATE_ERROR)
if ((UpstreamState == STATE_ERROR) ||
(UpstreamState == STATE_DISCONNECTING))
{
return COMMAND_CLASS_ERROR;
}
if ((UpstreamState != STATE_DEVICE_ACTIVE) &&
(UpstreamState != STATE_SUSPENDED))
if ((UpstreamState == STATE_DEVICE_ACTIVE) ||
(UpstreamState == STATE_SUSPENDED))
{
UPSTREAM_STATEMACHINE_FREAKOUT;
return COMMAND_CLASS_INTERFACE;
return ConfiguredDeviceClass;
}
return ConfiguredDeviceClass;
//else:
UPSTREAM_STATEMACHINE_FREAKOUT;
return COMMAND_CLASS_INTERFACE;
}
@ -293,3 +295,16 @@ void Upstream_StateMachine_Wakeup(void)
USBD_Start(&hUsbDeviceFS);
}
//Host sends a SCSI motor stop command, so we shouldn't process any more commands.
void Upstream_StateMachine_RegisterDisconnect(void)
{
if ((UpstreamState != STATE_DEVICE_ACTIVE) &&
(UpstreamState != STATE_SUSPENDED))
{
UPSTREAM_STATEMACHINE_FREAKOUT;
return;
}
UpstreamState = STATE_DISCONNECTING;
}

Loading…
Cancel
Save