📄 ms_bot.c
字号:
_status = rbc_write_10(&_bot_cdb->write);
break;
case RBC_READ_10:
/* Process the RBC READ_10 command */
TRACE_DEBUG_H( "READ_10\n\r");
usbms_context.usb_lun[usbms_context.current_lun].cur_request.transferred_size = 0L;
usbms_context.usb_lun[usbms_context.current_lun].cur_request.buffer_size = (_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0);
_status = rbc_read_10(&_bot_cdb->read);
break;
case RBC_INQUIRY:
/* Process the RBC INQUIRY request */
TRACE_DEBUG_H( "INQUIRY\n\r");
_status = rbc_inquiry(&_bot_cdb->inquiry);
usbms_context.usb_lun[usbms_context.current_lun].cur_request.buffer_size = (_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0);
if (USBMS_OK == _status)
{
/* the command has been fully processed */
ms_computeCSW(GOOD_STATUS,0);
usbms_context.state = USB_SEND_NO_FLASH;
}
else
{
/* an error occured during the processing */
ms_update_sense_data( SENSE_KEY_ILLEGAL_REQUEST, ASC_INVALID_FIELD_IN_CDB, ASCQ_00 );
ms_computeCSW(COMMAND_FAILED,usbms_context.usb_lun[usbms_context.current_lun].cur_request.buffer_size);
ms_stallPipe(FW_EP_BULK_IN);
/* an error occured, so the internal state changes to RESET_IN_PROGRESS */
usbms_context.state = RESET_IN_PROGRESS;
}
break;
case RBC_MODE_SELECT:
/* Process the RBC MODE_SELECT request */
TRACE_DEBUG_H( "MODE_SELECT\n\r");
_status = rbc_mode_select();
if (USBMS_OK == _status )
{
/* the command has been fully processed */
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
}
else
{
/* an error occured during the processing */
ms_send_bot_status(COMMAND_FAILED,0);
usbms_context.state = PROCESS_CSW;
}
/* The internal state changes to the CBW status phase */
break;
case RBC_MODE_SENSE:
/* Process the RBC REQUEST_SENSE command */
TRACE_DEBUG_H( "MODE_SENSE\n\r");
_status = rbc_mode_sense(&_bot_cdb->mode_sense);
break;
case RBC_PREVENT_ALLOW_REMOVAL:
/* Process the RBC PREVENT_ALLOW_REMOVAL request */
TRACE_DEBUG_H( "PRE ALLOW_REMV\n\r");
_status = rbc_prevent_allow_removal();
if (USBMS_OK == _status )
{
/* the command has been fully processed */
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
}
else
{
/* an error occured during the processing */
ms_send_bot_status(COMMAND_FAILED,0);
usbms_context.state = PROCESS_CSW;
}
break;
case RBC_START_STOP_UNIT:
/* Process the RBC START_STOP_UNIT request */
TRACE_DEBUG_H( "ST_STOP_UNIT\n\r");
_status = rbc_start_stop_unit(&_bot_cdb->start_stop);
if (USBMS_OK == _status )
{
/* the command has been fully processed */
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
}
else
{
/* an error occured during the processing */
ms_send_bot_status(COMMAND_FAILED,0);
usbms_context.state = PROCESS_CSW;
}
break;
case RBC_READ_CAPACITY:
/* Process the RBC READ_CAPACITY command */
TRACE_DEBUG_H( "READ_CAPA\n\r");
_status = rbc_read_capacity();
ms_computeCSW(GOOD_STATUS,0);
/*state set by read capacity*/
break;
case RBC_TEST_UNIT_READY:
/* Process the RBC TEST_UNIT_READY command */
TRACE_DEBUG_H( "TEST_UNIT\n\r");
/* media ready */
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
break;
case RBC_VERIFY:
/* Process the RBC VERIFY command */
TRACE_DEBUG_H( "VERIFY\n\r");
_status = rbc_verify_10();
if (USBMS_OK == _status)
{
/* Verify ok */
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
}
else
{
TRACE_DEBUG_H( "ERROR\n\r");
/* verify detected an error on the media */
ms_send_bot_status(COMMAND_FAILED,0);
usbms_context.state = PROCESS_CSW;
}
break;
case RBC_REQUEST_SENSE:
/* Process the RBC REQUEST_SENSE command */
TRACE_DEBUG_H( "REQ_SENSE\n\r");
_status = rbc_request_sense();
/* the internal remains unchanged */
ms_computeCSW(GOOD_STATUS,0);
usbms_context.state = USB_SEND_NO_FLASH;
break;
default:
TRACE_ERROR( "def uc%xh\n\r",_bot_cdb->generic_rbc.operation_code);
/* We don't know this command */
/* the Mass Storage device is not able to satisfy this request so it stalls the appropriate endpoint */
if( !(_cbw->bmCBWFlags&0x80)
&& ((_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0) ) )
{
/* Data OUT : host to device */
/* Stall the endpoint OUT */
ms_stallPipe( FW_EP_BULK_OUT );
}
else
{
/* Data IN : device to host */
/* Stall the endpoint IN */
ms_stallPipe( FW_EP_BULK_IN );
}
/* Update the state of the driver*/
ms_computeCSW(COMMAND_FAILED,
(_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0) );
ms_update_sense_data( SENSE_KEY_ILLEGAL_REQUEST, ASC_INVALID_COMMAND_OPERATION_CODE, ASCQ_00 );
usbms_context.state = RESET_IN_PROGRESS;
}
}
else
{
TRACE_ERROR( "Error TB\n\r");
/* We don't know this command */
/* the Mass Storage device is not able to satisfy this request so it stalls the appropriate endpoint*/
if( !(_cbw->bmCBWFlags&0x80)
&& ((_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0) ) )
{
/* Data OUT : host to device */
/* Stall the endpoint OUT */
ms_stallPipe( FW_EP_BULK_OUT );
}
else
{
/* Data IN : device to host */
/* Stall the endpoint IN */
ms_stallPipe( FW_EP_BULK_IN );
}
/* Update the state of the driver */
ms_computeCSW(COMMAND_FAILED,
(_cbw->dCBWDataTransferLength_3<<24)
|(_cbw->dCBWDataTransferLength_2<<16)
|(_cbw->dCBWDataTransferLength_1<<8)
|(_cbw->dCBWDataTransferLength_0) );
usbms_context.state = RESET_IN_PROGRESS;
}
}
/******************************************************************
*
* SUB-ROUTINE : ms_getRx
*
*------------------------------------------------------------------
*
* purpose : Recept of data from USB
*
* input parameters : none
*
* output parameters : none
*
* global data :
*
******************************************************************/
void ms_getRx( void )
{
USBMS_XFER *_request = NULL;
USB_LUN *_lun = NULL;
TRACE_DEBUG_H( "ms_getRx\n\r");
_request = &usbms_context.usb_lun[usbms_context.current_lun].cur_request;
_lun = &usbms_context.usb_lun[usbms_context.current_lun];
if( USBMS_ERROR == rbc_commun_write( _request, _lun ) )
{
TRACE_ERROR( "ms_getRx ERROR\n\r");
}
}
/******************************************************************
*
* SUB-ROUTINE : ms_sendTx
*
*------------------------------------------------------------------
*
* purpose : Send data to USB
*
* input parameters : none
*
* output parameters : none
*
* global data :
*
******************************************************************/
void ms_sendTx( void )
{
USBMS_XFER *_request = NULL;
USB_LUN *_lun = NULL;
UCHAR pDataBuff[FW_FIFO_SIZE];
ULONG _expected,_nbBlock;
USHORT _length;
/* initialize the temporary variables */
_request = &usbms_context.usb_lun[usbms_context.current_lun].cur_request;
_lun = &usbms_context.usb_lun[usbms_context.current_lun];
/* How much data do we want to send USB */
_expected = _request->buffer_size - _request->transferred_size;
/* We are called once more at the end of the request */
if(_expected == 0)
{
ms_send_bot_status(GOOD_STATUS,0);
usbms_context.state = PROCESS_CSW;
return;
}
/* fifo should be empty when we get here */
/* make sure we have room for at least one block */
if(fw_fifoId.NbOctetsLibres < _lun->BlockSize)
{
/* we must be able to send at least one bloc */
usbms_context.state = SEND_TO_USB;
return;
}
if(_expected > fw_fifoId.NbOctetsLibres)
{
_expected = fw_fifoId.NbOctetsLibres;
}
/* here we know that we will be able to send _expected data */
/* we write always FULL USB packets except for the last packet */
if( _expected < _lun->BlockSize )
{
/* remainig data size of the command is less than a BLOCK */
/* so we are at the end of the command */
_length = _expected;
_nbBlock = 0;
}
else
{
/* we are not at the end of the SCSI command */
/* only send full blocks and FULL USB packets */
_length = (_expected / _lun->BlockSize)*_lun->BlockSize ; /* Size in blocks */
_length = (_length / MAX_PACKET_SIZE)*MAX_PACKET_SIZE;
_nbBlock = (_length / _lun->BlockSize);
}
/* Read the FLASH and send the buffer */
AT91F_ReadMedia((unsigned int)(FILE_MGR_BEGIN_ADDRESS+(_request->current_block*usbms_context.usb_lun[usbms_context.current_lun].BlockSize)),
_length,
pDataBuff);
if( _length != usb_send( (char*)pDataBuff, _length ) )
{
/* error in writing in USB FIFO */
/* Cannot append per construction */
TRACE_ERROR( "ERROR FIFO\n\r");
usbms_context.state = PROCESS_CSW;
}
/* update request context */
_request->transferred_size += _length;
_request->current_block += _nbBlock;
usbms_context.state = SEND_TO_USB;
}
/******************************************************************
*
* SUB-ROUTINE : ms_finishNoFlash
*
*------------------------------------------------------------------
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -