Skip to content

Commit

Permalink
Ignore mass storage commands after receiving SCSI stop/eject
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfisk committed Apr 16, 2018
1 parent 8f1d3d9 commit 0861585
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Upstream/Inc/upstream_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions Upstream/Inc/upstream_statemachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum
STATE_WAIT_DEVICE,
STATE_DEVICE_ACTIVE,
STATE_SUSPENDED,
STATE_DISCONNECTING,
STATE_ERROR
} UpstreamStateTypeDef;

Expand All @@ -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);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion Upstream/Src/upstream_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 21 additions & 6 deletions Upstream/Src/upstream_statemachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}

0 comments on commit 0861585

Please sign in to comment.