📄 lun.c
字号:
{
_lun_data(sensep) = &sense_no_media;
}
break;
}
_thread_return_dfa(result);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_prevent_allow_access()
//
// Declaration:
// void dfa_lun_prevent_allow_access(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - Should not need to be overridden. This function will automatically use
// lun instance data to respond to the host.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_prevent_allow_access(void)reentrant
{
if (g_bot_cbw.cdb[4] & 0x01)
{
trace0(0, lun, 0, "dfa_lun_prevent_allow_access(prevent) - warning: impossible to control with this hardware");
_lun_data(sensep) = &sense_illegal_cmdpkt;
_thread_return_dfa(k_command_failed);
}
trace0(0, lun, 0, "dfa_lun_prevent_allow_access(allow) - warning: impossible to control with this hardware");
_lun_data(sensep) = &sense_none;
_thread_return_dfa(k_command_passed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_sync_cache()
//
// Declaration:
// void dfa_lun_sync_cache(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - Should not need to be overridden. This function will automatically use
// lun instance data to respond to the host.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_sync_cache(void)reentrant
{
trace0(0, lun, 0, "dfa_lun_sync_cache() - warning: not implemented");
_lun_data(sensep) = &sense_illegal_opcode;
_thread_return_dfa(k_command_failed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_erase_media()
//
// Declaration:
// void dfa_lun_erase_media(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - luns that support erasing the media should override this function
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_erase_media(void) reentrant
{
trace0(0, lun, 0, "dfa_lun_erase_media() - not implemented on this lun");
_lun_data(sensep) = &sense_illegal_opcode;
_thread_return_dfa(k_command_failed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_report_media_geometry()
//
// Declaration:
// void dfa_lun_report_media_geometry(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - luns that support mapped media override this function
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_report_media_geometry(void) reentrant
{
trace0(0, lun, 0, "dfa_lun_report_media_geometry() - not implemented on this lun");
_lun_data(sensep) = &sense_illegal_opcode;
_thread_return_dfa(k_command_failed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_secure_memory_write()
//
// Declaration:
// void dfa_lun_secure_memory_write(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - should not be overridden. Vendor specific command. independant of what lun it is
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_secure_memory_write(void) reentrant
{
#if defined(k_mcu_97211) || defined(k_mcu_97242)
uint8 i, len;
trace0(0, lun, 0, "dfa_lun_secure_memory_write()");
_lun_data(sensep) = &sense_none;
len = g_bot_cbw.cdb[8];
// receive the data
if (k_success != mscbot_rx_data_buffer(g_sector_buffer, len))
_thread_return_dfa(k_command_failed);
//get the nvstore ready to write
nvstore_write_enable();
for (i= 0; i < len; i++)
{
//TRACE2(387, lun, 0, "buffer[%d] = %02x",i,g_sector_buffer[i]);
nvstore_write((k_ix_secure_mem + i), g_sector_buffer[i]);
}
//Post write operation
nvstore_write_disable();
//verify the writes
for (i=0; i < len; i++)
{
if (nvstore_read((k_ix_secure_mem + i)) != g_sector_buffer[i])
{
_thread_return_dfa(k_command_failed);
}
}
_mscbot_decr_residue(len); //Decrement the residue
_thread_return_dfa(k_command_passed);
#endif
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_secure_memory_read()
//
// Declaration:
// void dfa_lun_secure_memory_read(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - should not be overridden. Vendor specific command. independant of what lun it is
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_secure_memory_read(void) reentrant
{
#if defined(k_mcu_97211) || defined(k_mcu_97242)
uint8 i, len;
trace0(0, lun, 0, "dfa_lun_secure_memory_read()");
_lun_data(sensep) = &sense_none;
len = g_bot_cbw.cdb[8];
for (i= 0; i < len; i++)
{
g_sector_buffer[i] = nvstore_read((k_ix_secure_mem + i));
}
// send it
mscbot_tx_data_buffer(g_sector_buffer, len);
_thread_return_dfa(k_command_passed);
#endif
}
//------------------------------------------
void dfa_lun_get_format_status(void) reentrant
{
_thread_return_dfa(k_command_passed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_device_diagnostics()
//
// Declaration:
// void dfa_lun_device_diagnostics(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - Should not need to be overridden. This function will automatically use
// lun instance data to respond to the host.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_device_diagnostics(void) reentrant
{
trace0(0, lun, 0, "dfa_lun_device_diagnostics() - warning: not implemented");
_lun_data(sensep) = &sense_illegal_opcode;
_thread_return_dfa(k_command_failed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_unsupported()
//
// Declaration:
// void dfa_lun_unsupported(void) reentrant ;
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - Should not need to be overridden. This function will automatically use
// lun instance data to respond to the host.
//
// Since:
// fmc-1.0
//------------------------------------------------------------------------------
void dfa_lun_unsupported(void) reentrant
{
trace0(0, lun, 0, "dfa_lun_unsupported() - warning: host delivered unsupported command");
_lun_data(sensep) = &sense_illegal_opcode;
_thread_return_dfa(k_command_failed);
}
//+-----------------------------------------------------------------------------
// Name:
// dfa_lun_inquiry()
//
// Declaration:
// void dfa_lun_inquiry(void) reentrant ;
//
// Purpose:
// Default mass storage class inquiry handling, utilizing
// info that should be present in the _lun_data instances
// during lun initialization.
//
// Arguments:
//
// Return:
//
// Notes:
// - This is a dfa.
// - Should not need to be overridden. This function will automatically use
// lun instance data to respond to the host.
//
// Since:
// atapi.20
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// clearly we need "nvstore.h", but since brian has device.c checked out,
// and as usual i'm in a hurry, i'll do a smidegon of hackmeistering to
// quick-n-dirty this. the enterprising reader should take it upon his/herself
// to fabricate nvstore.h and nvstore.c
//
// offsets into the nvstore - COMBINE THESE WITH THOSE IN DEVICE.C AND PUT INTO DEV.H!!!
#define k_ix_mfr 34
#define k_sz_mfr 60
#define k_ix_prd 94
#define k_sz_prd 60
#define k_ix_vid_lo 26
#define k_ix_vid_hi 27
#define k_ix_pid_lo 28
#define k_ix_pid_hi 29
//------------------------------------------------------------------------------
#define k_sz_lun_inquiry 36
#define kbm_inquiry_rmb 0x80
code uint8 lun_inquiry_template[k_sz_lun_inquiry] =
{
0x00, // PeripheralDeviceType = DASD
0x00, // Removable bit set in process_inquiry
0x00, // IsoEcmaAnsiVersion
0x02, // ResponseDataFormat
0x20, // AdditionalLength
0x00, 0x00, 0x00, // Reserved[3]
// VendorInfo[8]
'S', 'M', 'S', 'C', 0, 0, 0, 0,
// ProductInfo[16]
'U', 'S', 'B', ' ', '2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'0' + kbcd_dev_version_major, // ProductVersion[0]
'.', // ProductVersion[1]
'0' + (kbcd_dev_version_minor >> 4), // ProductVersion[2]
'0' + (kbcd_dev_version_minor & 0x0F) // ProductVersion[3]
};
//------------------------------------------------------------------------------
void dfa_lun_inquiry(void) reentrant
{
uint8 length;
// uint8 pnr;
uint8 off;
uint8 n;
trace0(0, lun, 0, "dfa_lun_inquiry()");
trace1(0, lun, 0, "alloc length:%02X", g_bot_cbw.cdb[4]);
mcu_begin_critical_section();
// load template into buffer
memcpy((uint8 xdata *)g_sector_buffer, (uint8 code *)lun_inquiry_template, k_sz_lun_inquiry);
// offset 1: overwrite the rmb bit
g_sector_buffer[1] = (_lun_is_media_removable(g_active_lun))
? lun_inquiry_template[1] |kbm_inquiry_rmb
: lun_inquiry_template[1] & ~kbm_inquiry_rmb;
// offset 8..15: overwrite the vendor up to 8 chars from the mfg string dscr
memcpy(g_sector_buffer+8, g_inq_vid, k_sz_inq_vid);
// offset 16..<24>: overwrite the product up to 9 chars from the Inquiry Prd ID header
memcpy(g_sector_buffer+16, g_inq_pid_hdr, k_sz_inq_pid_hdr) ;
off=16+k_sz_inq_pid_hdr;
// offset <16>..<16>+5: _XS-, should always be HS as per jwc
g_sector_buffer[off++] = ' ';
g_sector_buffer[off++] = 'H';
g_sector_buffer[off++] = 'S';
g_sector_buffer[off++] = '-';
// offset <16>+3..31: lun device id
n = k_sz_lun
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -