Ignore mass storage commands after receiving SCSI stop/eject

USG_1.0 1.0r04
Robert Fisk 7 years ago
parent 8f1d3d9a72
commit 086158525b

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

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

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

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

@ -369,7 +369,15 @@ HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packet
packetToSend->Command = COMMAND_MSC_WRITE; packetToSend->Command = COMMAND_MSC_WRITE;
return Upstream_TransmitPacket(packetToSend); 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 #endif //#ifdef CONFIG_MASS_STORAGE_ENABLED

@ -79,19 +79,21 @@ void Upstream_StateMachine_SetErrorState(void)
InterfaceCommandClassTypeDef Upstream_StateMachine_CheckActiveClass(void) InterfaceCommandClassTypeDef Upstream_StateMachine_CheckActiveClass(void)
{ {
if (UpstreamState == STATE_ERROR) if ((UpstreamState == STATE_ERROR) ||
(UpstreamState == STATE_DISCONNECTING))
{ {
return COMMAND_CLASS_ERROR; return COMMAND_CLASS_ERROR;
} }
if ((UpstreamState != STATE_DEVICE_ACTIVE) && if ((UpstreamState == STATE_DEVICE_ACTIVE) ||
(UpstreamState != STATE_SUSPENDED)) (UpstreamState == STATE_SUSPENDED))
{ {
UPSTREAM_STATEMACHINE_FREAKOUT; return ConfiguredDeviceClass;
return COMMAND_CLASS_INTERFACE;
} }
return ConfiguredDeviceClass; //else:
UPSTREAM_STATEMACHINE_FREAKOUT;
return COMMAND_CLASS_INTERFACE;
} }
@ -293,3 +295,16 @@ void Upstream_StateMachine_Wakeup(void)
USBD_Start(&hUsbDeviceFS); 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