📄 rbc.c
字号:
*((unsigned long *)MSL_Param_Buffer) = (MAL_Capacity - Private_Zone_Size) - 1;
}
*((unsigned long *)(MSL_Param_Buffer + 4)) = 512; // Block size
return RBC_STATUS_GOOD;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : RBC_Read_Format_Capacities(CMD_READ_FORMAT_CAPACITIES *pCmd)
INPUT/OUTPUT : None
DESCRIPTION :
-----------------------------------------------------------------------------*/
extern DWORD Medium_Capacity[MAX_LUN+1]; // the last addres of the medium
char RBC_Read_Format_Capacities(CMD_READ_FORMAT_CAPACITIES *pCmd)
{
unsigned char index;
if(!MAL_Mediano)
while(MAL_Test_Ready()); // Wait for the media to be ready
index = READ_FORMAT_CAPACITIES_LEN;
while (index) {
index--;
MSL_Param_Buffer[index] = READ_FORMAT_CAPACITIES_data[index];
}
if(!MAL_Mediano)
{
if((Windows_2000) && (Current_Mode == 2)) // Under Win2000 and Private Mode
{
if(Private_Zone_Size == 0)
{
*((unsigned long *)(MSL_Param_Buffer + 4)) = 0;
Medium_Capacity[MAL_Mediano] = 0;
}
else{
*((unsigned long *)(MSL_Param_Buffer + 4)) = (MAL_Capacity - Private_Zone_Size) - 1;
Medium_Capacity[MAL_Mediano] = MAL_Capacity - Private_Zone_Size;
}
}
else{
if(Private_Zone_Size == 0)
{
*((unsigned long *)(MSL_Param_Buffer + 4)) = MAL_Capacity - 1;
Medium_Capacity[MAL_Mediano] = MAL_Capacity;
}
else{
*((unsigned long *)(MSL_Param_Buffer + 4)) = Private_Zone_Size - 1;
Medium_Capacity[MAL_Mediano] = Private_Zone_Size;
}
}
}
else{
if(Private_Zone_Size == 0)
{
*((unsigned long *)(MSL_Param_Buffer + 4)) = 0;
Medium_Capacity[MAL_Mediano] = 0;
}
else{
*((unsigned long *)(MSL_Param_Buffer + 4)) = (MAL_Capacity - Private_Zone_Size) - 1;
Medium_Capacity[MAL_Mediano] = MAL_Capacity - Private_Zone_Size;
}
}
MSL_Param_Size = READ_FORMAT_CAPACITIES_LEN;
return RBC_STATUS_GOOD;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : RBC_ST_CMD
INPUT/OUTPUT : None
DESCRIPTION :
-----------------------------------------------------------------------------*/
extern void SMC_Save_Parameters();
extern unsigned char Max_Lun;
char RBC_ST_CMD(void)
{
unsigned char Index;
if(RBC_Cmd[1] == 0x02) // GET_SLOTS_NUMBER
{
*((unsigned char *)MSL_Param_Buffer) = Max_Lun;
MSL_Param_Size = 1;
}
else if(RBC_Cmd[1] == 0x10) // GET_CURRENT_MODE
{
*((unsigned char *)MSL_Param_Buffer) = Current_Mode;
MSL_Param_Size = 1;
}
else if(RBC_Cmd[1] == 0x11) // SET_CURRENT_MODE
{
if(Current_Mode == 0) // Default Mode
{
if(MSL_Param_Buffer[0] == 1)
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
else if(MSL_Param_Buffer[0] == 2)
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
else if(MSL_Param_Buffer[0] == 3)
{
Current_Mode = MSL_Param_Buffer[0];
}
else
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
}
else if(Current_Mode == 1) // Public Mode
{
if(MSL_Param_Buffer[0] == 0)
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
else if(MSL_Param_Buffer[0] == 2)
{
// Check Password
Index = 34;
while (Index) {
Index--;
if(PassWord[Index] != MSL_Param_Buffer[Index+2])
{
SenseCode(VENDOR_SPECIFIC, PASSWORD_ERROR);
return RBC_STATUS_FAIL;
}
}
Current_Mode = MSL_Param_Buffer[0];
Windows_2000 = MSL_Param_Buffer[1];
if(!Windows_2000) // Not Under Win2000
{
MAL_Medium_Removing(1);
MAL_Medium_Plug(1);
}
else{
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
MAL_Medium_Removing(1);
}
}
else if(MSL_Param_Buffer[0] == 3)
{
// Check Password
Index = 34;
while (Index) {
Index--;
if(PassWord[Index] != MSL_Param_Buffer[Index+2])
{
SenseCode(VENDOR_SPECIFIC, PASSWORD_ERROR);
return RBC_STATUS_FAIL;
}
}
Current_Mode = MSL_Param_Buffer[0];
}
else
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
}
else if(Current_Mode == 2) // Private Mode
{
if(MSL_Param_Buffer[0] == 0)
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
else if(MSL_Param_Buffer[0] == 1)
{
Current_Mode = MSL_Param_Buffer[0];
Windows_2000 = MSL_Param_Buffer[1];
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
MAL_Medium_Removing(1);
}
else if(MSL_Param_Buffer[0] == 3)
{
Current_Mode = MSL_Param_Buffer[0];
Windows_2000 = MSL_Param_Buffer[1];
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
MAL_Medium_Removing(1);
}
else
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
}
else if(Current_Mode == 3) // Maintenance Mode
{
if(MSL_Param_Buffer[0] == 0)
{
Current_Mode = MSL_Param_Buffer[0];
}
else if(MSL_Param_Buffer[0] == 1)
{
Current_Mode = MSL_Param_Buffer[0];
}
else if(MSL_Param_Buffer[0] == 2)
{
Current_Mode = MSL_Param_Buffer[0];
Windows_2000 = MSL_Param_Buffer[1];
if(!Windows_2000) // Not Under Win2000
{
MAL_Medium_Removing(1);
MAL_Medium_Plug(1);
}
else{
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
}
}
else
{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
}
}
else if(RBC_Cmd[1] == 0x12) // GET_FLASH_STATE
{
// 0 not good
*((unsigned char *)MSL_Param_Buffer) = Flash_State;
MSL_Param_Size = 1;
if(!Flash_State)
{
Index = 34;
while (Index) {
Index--;
Slot_Description[Index] = 0;
PassWord[Index] = 0;
}
Index = 66;
while (Index) {
Index--;
Serial_Number[Index] = 0;
}
}
}
else if(RBC_Cmd[1] == 0x20) // GET_SLOT_SIZE
{
*((unsigned long *)MSL_Param_Buffer) = MAL_Capacity - 1;
*((unsigned long *)(MSL_Param_Buffer + 4)) = 512; // Block size
MSL_Param_Size = 8;
}
else if(RBC_Cmd[1] == 0x21) // GET_SLOT_DESCRIPTION
{
// *((unsigned long *)MSL_Param_Buffer) = Max_Lun;
if(!MAL_Mediano)
{
MSL_Param_Buffer[0] = 'P';
MSL_Param_Buffer[1] = 0;
MSL_Param_Buffer[2] = 'F';
MSL_Param_Buffer[3] = 0;
MSL_Param_Buffer[4] = 'D';
MSL_Param_Buffer[5] = 0;
MSL_Param_Buffer[6] = 'P';
MSL_Param_Buffer[7] = 0;
}
else{
MSL_Param_Buffer[0] = 'P';
MSL_Param_Buffer[1] = 0;
MSL_Param_Buffer[2] = 'F';
MSL_Param_Buffer[3] = 0;
MSL_Param_Buffer[4] = 'D';
MSL_Param_Buffer[5] = 0;
MSL_Param_Buffer[6] = 'S';
MSL_Param_Buffer[7] = 0;
}
MSL_Param_Size = 8;
}
else if(RBC_Cmd[1] == 0x22) // SLOT_SIZE
{
*((unsigned long *)MSL_Param_Buffer) = MAL_Capacity - 1;
*((unsigned long *)(MSL_Param_Buffer + 4)) = 512; // Block size
MSL_Param_Size = 8;
}
else if(RBC_Cmd[1] == 0x50) // GET_PRIVATE_ZONE_SIZE
{
if(Private_Zone_Size == 0)
*((unsigned long *)MSL_Param_Buffer) = MAL_Capacity;
else
*((unsigned long *)MSL_Param_Buffer) = Private_Zone_Size;
MSL_Param_Size = 4;
}
else if(RBC_Cmd[1] == 0x51) // SET_PRIVATE_ZONE_SIZE
{
if(Current_Mode == 3) // Maintenance Mode
{
Private_Zone_Size = *((unsigned long *)MSL_Param_Buffer);
SMC_Save_Parameters();
}
}
else if(RBC_Cmd[1] == 0x60) // CHANGE_PASSEWORD
{
if(Current_Mode == 3) // Maintenance Mode
{
Index = 34;
while (Index) {
Index--;
PassWord[Index] = MSL_Param_Buffer[Index];
}
SMC_Save_Parameters();
}
}
else if(RBC_Cmd[1] == 0x70) // GET_SERIAL_NUMBER
{
Index = 66;
while (Index) {
Index--;
MSL_Param_Buffer[Index] = Serial_Number[Index];
}
MSL_Param_Size = 66;
}
else if(RBC_Cmd[1] == 0x71) // SET_SERIAL_NUMBER
{
Index = 66;
while (Index) {
Index--;
Serial_Number[Index] = MSL_Param_Buffer[Index];
}
SMC_Save_Parameters();
}
else if(RBC_Cmd[1] == 0x80) // GET_VERSION
{
MSL_Param_Buffer[0] = RBC_EXT_MAJ;
MSL_Param_Buffer[1] = RBC_EXT_MIN;
MSL_Param_Buffer[2] = Appli_DeviceDescriptor0[8];
MSL_Param_Buffer[3] = Appli_DeviceDescriptor0[9];
MSL_Param_Buffer[4] = Appli_DeviceDescriptor0[10];
MSL_Param_Buffer[5] = Appli_DeviceDescriptor0[11];
MSL_Param_Size = 6;
}
else if(RBC_Cmd[1] == 0x90) // SET_ERROR
{
// MEDIUM_CHANGED
if((MSL_Param_Buffer[0] == 0) && (MSL_Param_Buffer[1] == 0x28))
{
/*
if(Current_Mode == 2)
{
MAL_Medium_Removing(1);
MAL_Medium_Plug(1);
}
else
MAL_Medium_Removing(1);
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
*/
MAL_Medium_Removing(0);
MAL_Medium_Plug(0);
MAL_Medium_Removing(1);
}
}
else{
SenseCode(ILLEGAL_REQUEST, INVALID_CDB_FIELD);
return RBC_STATUS_FAIL;
}
return RBC_STATUS_GOOD;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : MAL_Prevent_Removal
INPUT/OUTPUT : None
DESCRIPTION :
-----------------------------------------------------------------------------*/
char MAL_Prevent_Removal(void)
{
return RBC_STATUS_GOOD;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : RBC_Start_Stop
INPUT/OUTPUT : None
DESCRIPTION :
-----------------------------------------------------------------------------*/
char RBC_Start_Stop(char Power_Control)
{
return RBC_MAL_Error( MAL_Start_Stop(Power_Control) );
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : MAL_Verify
INPUT/OUTPUT : None
DESCRIPTION :
-----------------------------------------------------------------------------*/
char MAL_Verify( )
{
return RBC_STATUS_GOOD;
}
/********************************************************/
/* RBC Process */
/********************************************************/
char RBC_Process(unsigned char lun)
{
MAL_Mediano = lun;
if (RBC_Cmd[0] == 0x03) // Request sense
return RBC_Request_Sense();
// When there is a SenseCode or during formation
if ((Sense_Tail != Sense_Head) || (MAL_State == MAL_FORMATTING))
return RBC_STATUS_FAIL;
if (RBC_Cmd[0] == 0x00)
return RBC_Test_Ready();
else if (RBC_Cmd[0] == 0x12) // Inquiry, RBC Data Exchange IN
return RBC_Inquiry(&CMD_Inquiry);
else if (RBC_Cmd[0] == 0x15) // Mode Select 6
return RBC_Mode_Select6(&CMD_MSelect6);
else if (RBC_Cmd[0] == 0x1A) // Mode Sense 6
return RBC_Mode_Sense6(&CMD_MSense6);
else if (RBC_Cmd[0] == 0x5A) // Mode Sense 10
return RBC_Mode_Sense10(&CMD_MSense10);
else if (RBC_Cmd[0] == 0x23) // Read Format Capacities
return RBC_Read_Format_Capacities(&CMD_ReadFormat);
else if (RBC_Cmd[0] == 0x1B) // Start Stop Unit
return RBC_Start_Stop(RBC_Cmd[4]);
else if (RBC_Cmd[0] == 0x1E) // Prevent removal
return MAL_Prevent_Removal(); // Always good for the moment ...
else if (RBC_Cmd[0] == 0x25) // Read capacity, //RBC Data Exchange IN
return RBC_Read_Capacity(); // This function set the rigth values on MSL_Param_Buffer
else if (RBC_Cmd[0] == 0xF1) // ST own spec
return RBC_ST_CMD();
else {
// ((_UDWORD *)&MAL_Block_Address)->byte[3] = RBC_Cmd[5];
// ((_UDWORD *)&MAL_Block_Address)->byte[2] = RBC_Cmd[4];
// ((_UDWORD *)&MAL_Block_Address)->byte[1] = RBC_Cmd[3];
// ((_UDWORD *)&MAL_Block_Address)->byte[0] = RBC_Cmd[2];
MAL_Block_Address = *((unsigned long*)(RBC_Cmd + 2)); // more meaningful
MAL_Block_Numbers = MAKEWORD(RBC_Cmd[7],RBC_Cmd[8]);
if (RBC_Cmd[0] == 0x28) { // READ 10
Current_Operation = RBC_OP_READ; // Read
return RBC_MAL_Error( MAL_Read( ) );
}
else if (RBC_Cmd[0] == 0x2A) { // WRITE 10
Current_Operation = RBC_OP_WRITE; // WRITE
return RBC_MAL_Error( MAL_Write( ) );
}
else if (RBC_Cmd[0] == 0x2F) { // VERIFY 10
Current_Operation = RBC_OP_VERIFY; // VERIFY
return RBC_MAL_Error( MAL_Verify( ) );
}
else if (RBC_Cmd[0] == 0x04) { // FORMAT
unsigned char Format_Flags;
Current_Operation = RBC_OP_FORMAT; // FORMAT
Format_Flags = RBC_Cmd[2];
MAL_Format();
if ((Format_Flags & 0x08) == 0)
while (MAL_State) // When Immed bit is not set
asm nop; // wait the formatting finishes
return RBC_STATUS_GOOD;
}
else {
SenseCode(ILLEGAL_REQUEST, INVALID_COMMAND_CODE);
return RBC_STATUS_FAIL;
}
}
}
/******************************** RBC_Finish *********************************/
/*****************************************************************************/
unsigned int RBC_Finish(void)
{
Current_Operation = RBC_OP_IDLE;
return MAL_Block_Numbers;
}
/********************************* RBC_Reset *********************************/
/*****************************************************************************/
void RBC_Reset(void)
{
if (Current_Operation != RBC_OP_IDLE) {
DTCCTRL &= ~0x01; // Stop the DTC
BUFSR = 0x01;
BUFSR = 0x00; // Clear buffer manager flags
}
RBC_Init();
}
/**************** (c) 2000 STMicroelectronics **********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -