#27 Functionality will not transmit packets to the tap device ras0. Need to manually enable the link using 'ip link set dev ras0 up'

This commit is contained in:
akuker
2020-09-20 17:08:08 -05:00
parent 0a21896fd3
commit f375f7a8d2
7 changed files with 468 additions and 187 deletions

View File

@@ -62,13 +62,6 @@ SCSINuvolink::SCSINuvolink() : Disk()
tap->GetMacAddr(mac_addr);
mac_addr[5]++;
}
mac_addr[0]=0x01;
mac_addr[1]=0x02;
mac_addr[2]=0x03;
mac_addr[3]=0x04;
mac_addr[4]=0x05;
mac_addr[5]=0x06;
// Packet reception flag OFF
packet_enable = FALSE;
#endif // RASCSI && !BAREMETAL
@@ -99,7 +92,7 @@ SCSINuvolink::~SCSINuvolink()
//
//---------------------------------------------------------------------------
int FASTCALL SCSINuvolink::Inquiry(
const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor)
const DWORD *cdb, BYTE *buffer, DWORD major, DWORD minor)
{
DWORD response_size;
DWORD temp_data_dword;
@@ -107,7 +100,7 @@ int FASTCALL SCSINuvolink::Inquiry(
ASSERT(this);
ASSERT(cdb);
ASSERT(buf);
ASSERT(buffer);
ASSERT(cdb[0] == 0x12);
LOGTRACE("%s Inquiry with major %ld, minor %ld",__PRETTY_FUNCTION__, major, minor);
@@ -115,7 +108,7 @@ int FASTCALL SCSINuvolink::Inquiry(
// The LSB of cdb[3] is used as an extension to the size
// field in cdb[4]
response_size = (((DWORD)cdb[3] & 0x1) << 8) + cdb[4];
LOGWARN("size is %d (%08X)",response_size, response_size);
LOGWARN("size is %d (%08X)",(int)response_size, (WORD)response_size);
for(int i=0; i< 5; i++)
{
@@ -130,95 +123,95 @@ int FASTCALL SCSINuvolink::Inquiry(
}
// Clear the buffer
memset(buf, 0, response_size);
memset(buffer, 0, response_size);
// Basic data
// buf[0] ... Communication Device
// buf[2] ... SCSI-2 compliant command system
// buf[3] ... SCSI-2 compliant Inquiry response
// buf[4] ... Inquiry additional data
buf[0] = 0x09; /* Communication device */
// buffer[0] ... Communication Device
// buffer[2] ... SCSI-2 compliant command system
// buffer[3] ... SCSI-2 compliant Inquiry response
// buffer[4] ... Inquiry additional data
buffer[0] = 0x09; /* Communication device */
// SCSI-2 p.104 4.4.3 Incorrect logical unit handling
if (((cdb[1] >> 5) & 0x07) != disk.lun) {
buf[0] = 0x7f;
buffer[0] = 0x7f;
}
/* SCSI 2 device */
buf[2] = 0x02;
buffer[2] = 0x02;
/* SCSI 2 response type */
buf[3] = (response_size >> 8) | 0x02;
buffer[3] = (response_size >> 8) | 0x02;
/* No additional length */
buf[4] = response_size;
buffer[4] = response_size;
// Vendor name
memcpy(&buf[8], m_vendor_name, strlen( m_vendor_name));
memcpy(&buffer[8], m_vendor_name, strlen( m_vendor_name));
// Product name
memcpy(&buf[16], m_device_name, strlen(m_device_name));
memcpy(&buffer[16], m_device_name, strlen(m_device_name));
// Revision
memcpy(&buf[32], m_revision, strlen(m_revision));
memcpy(&buffer[32], m_revision, strlen(m_revision));
// MAC Address currently configured
memcpy(&buf[36], mac_addr, sizeof(mac_addr));
memcpy(&buffer[36], mac_addr, sizeof(mac_addr));
// Build-in Hardware MAC address
memcpy(&buf[56], mac_addr, sizeof(mac_addr));
memcpy(&buffer[56], mac_addr, sizeof(mac_addr));
// For now, all of the statistics are just garbage data to
// make sure that the inquiry response is formatted correctly
if(response_size > 96){
// Header for SCSI statistics
buf[96] = 0x04; // Decimal 1234
buf[97] = 0xD2;
buffer[96] = 0x04; // Decimal 1234
buffer[97] = 0xD2;
// Header for SCSI errors section
buf[184]=0x09; // Decimal 2345
buf[185]=0x29;
buffer[184]=0x09; // Decimal 2345
buffer[185]=0x29;
// Header for network statistics
buf[244]=0x0D;
buf[245]=0x80;
buffer[244]=0x0D;
buffer[245]=0x80;
// Received Packet Count
temp_data_dword=100;
memcpy(&buf[246], &temp_data_dword, sizeof(temp_data_dword));
memcpy(&buffer[246], &temp_data_dword, sizeof(temp_data_dword));
// Transmitted Packet Count
temp_data_dword=200;
memcpy(&buf[250], &temp_data_dword, sizeof(temp_data_dword));
memcpy(&buffer[250], &temp_data_dword, sizeof(temp_data_dword));
// Transmitted Request Count
temp_data_dword=300;
memcpy(&buf[254], &temp_data_dword, sizeof(temp_data_dword));
memcpy(&buffer[254], &temp_data_dword, sizeof(temp_data_dword));
// Reset Count
temp_data_word=50;
memcpy(&buf[258], &temp_data_word, sizeof(temp_data_word));
memcpy(&buffer[258], &temp_data_word, sizeof(temp_data_word));
// Header for network errors
buf[260]=0x11; // Decimal 4567
buf[261]=0xD7;
buffer[260]=0x11; // Decimal 4567
buffer[261]=0xD7;
// unexp_rst
buf[262]=0x01;
buf[263]=0x02;
buffer[262]=0x01;
buffer[263]=0x02;
//transmit_errors
buf[264]=0x03;
buf[265]=0x04;
buffer[264]=0x03;
buffer[265]=0x04;
// re_int
buf[266]=0x05;
buf[267]=0x06;
buffer[266]=0x05;
buffer[267]=0x06;
// te_int
buf[268]=0x07;
buf[269]=0x08;
buffer[268]=0x07;
buffer[269]=0x08;
// ow_int
buf[270]=0x09;
buf[271]=0x0A;
buf[272]=0x0B;
buf[273]=0x0C;
buf[274]=0x0D;
buf[275]=0x0E;
buffer[270]=0x09;
buffer[271]=0x0A;
buffer[272]=0x0B;
buffer[273]=0x0C;
buffer[274]=0x0D;
buffer[275]=0x0E;
}
// Success
@@ -246,7 +239,7 @@ BOOL FASTCALL SCSINuvolink::TestUnitReady(const DWORD* /*cdb*/)
// GET MESSAGE(10)
//
//---------------------------------------------------------------------------
int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
int FASTCALL SCSINuvolink::GetMessage6(const DWORD *cdb, BYTE *buffer)
{
int type;
int phase;
@@ -257,7 +250,7 @@ int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
#endif // RASCSI && !BAREMETAL
ASSERT(this);
LOGTRACE("SCSINuvolink::GetMessage10");
LOGTRACE("SCSINuvolink::GetMessage");
// Type
type = cdb[2];
@@ -280,26 +273,26 @@ int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
switch (func) {
case 0: // Get MAC address
return GetMacAddr(buf);
return GetMacAddr(buffer);
case 1: // Received packet acquisition (size/buffer)
if (phase == 0) {
// Get packet size
ReceivePacket();
buf[0] = (BYTE)(packet_len >> 8);
buf[1] = (BYTE)packet_len;
buffer[0] = (BYTE)(packet_len >> 8);
buffer[1] = (BYTE)packet_len;
return 2;
} else {
// Get package data
GetPacketBuf(buf);
GetPacketBuf(buffer);
return packet_len;
}
case 2: // Received packet acquisition (size + buffer simultaneously)
ReceivePacket();
buf[0] = (BYTE)(packet_len >> 8);
buf[1] = (BYTE)packet_len;
GetPacketBuf(&buf[2]);
buffer[0] = (BYTE)(packet_len >> 8);
buffer[1] = (BYTE)packet_len;
GetPacketBuf(&buffer[2]);
return packet_len + 2;
case 3: // Simultaneous acquisition of multiple packets (size + buffer simultaneously)
@@ -308,13 +301,13 @@ int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
total_len = 0;
for (i = 0; i < 10; i++) {
ReceivePacket();
*buf++ = (BYTE)(packet_len >> 8);
*buf++ = (BYTE)packet_len;
*buffer++ = (BYTE)(packet_len >> 8);
*buffer++ = (BYTE)packet_len;
total_len += 2;
if (packet_len == 0)
break;
GetPacketBuf(buf);
buf += packet_len;
GetPacketBuf(buffer);
buffer += packet_len;
total_len += packet_len;
}
return total_len;
@@ -325,13 +318,13 @@ int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
case 2: // Host Drive
// switch (phase) {
// case 0: // Get result code
// return ReadFsResult(buf);
// return ReadFsResult(buffer);
// case 1: // Return data acquisition
// return ReadFsOut(buf);
// return ReadFsOut(buffer);
// case 2: // Return additional data acquisition
// return ReadFsOpt(buf);
// return ReadFsOpt(buffer);
// }
break;
}
@@ -346,63 +339,62 @@ int FASTCALL SCSINuvolink::GetMessage10(const DWORD *cdb, BYTE *buf)
// SEND MESSAGE(10)
//
//---------------------------------------------------------------------------
BOOL FASTCALL SCSINuvolink::SendMessage10(const DWORD *cdb, BYTE *buf)
BOOL FASTCALL SCSINuvolink::SendMessage6(const DWORD *cdb, BYTE *buffer)
{
int type;
// int type;
int func;
int len;
ASSERT(this);
ASSERT(cdb);
ASSERT(buf);
LOGTRACE("SCSINuvolink::SendMessage10");
ASSERT(buffer);
LOGTRACE("%s Entering....", __PRETTY_FUNCTION__);
// SendMessage6 is 6 bytes
for(int i=0; i< 6; i++)
{
LOGDEBUG("%s Byte %d: %02X",__PRETTY_FUNCTION__, i, (int)cdb[i]);
}
// Type
type = cdb[2];
// type = cdb[2];
// Function number
func = cdb[3];
func = cdb[0];
// Phase
// phase = cdb[9];
// Get the number of lights
len = cdb[6];
len <<= 8;
len |= cdb[7];
len <<= 8;
len |= cdb[8];
// Get the number of bytes
len = cdb[4];
switch (type) {
#if defined(RASCSI) && !defined(BAREMETAL)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
return FALSE;
}
// // Do not process if TAP is invalid
// if (!m_bTapEnable) {
// LOGWARN("%s TAP is invalid and not working...", __PRETTY_FUNCTION__);
// return FALSE;
// }
switch (func) {
case 0: // MAC address setting
SetMacAddr(buf);
return TRUE;
switch (func) {
case 0x06: // MAC address setting
LOGWARN("%s Unhandled Set MAC Address happening here...", __PRETTY_FUNCTION__);
SetMacAddr(buffer);
return TRUE;
case 0x09: // Set Multicast Registers
LOGWARN("%s Set Multicast registers happening here...", __PRETTY_FUNCTION__);
SetMulticastRegisters(buffer, len);
return TRUE;
case 1: // Send packet
SendPacket(buf, len);
return TRUE;
}
break;
#endif // RASCSI && !BAREMETAL
case 0x05: // Send message
LOGWARN("%s Send message happening here...(%d)", __PRETTY_FUNCTION__, len);
// SendPacket(buffer,len);
return TRUE;
case 2: // Host drive
// switch (phase) {
// case 0: // issue command
// WriteFs(func, buf);
// return TRUE;
// case 1: // additional data writing
// WriteFsOpt(buf, len);
// return TRUE;
// }
// case 1: // Send packet
// SendPacket(buffer, len);
// return TRUE;
default:
LOGWARN("%s Unexpected command type found %02X",__PRETTY_FUNCTION__, func);
break;
}
@@ -411,6 +403,23 @@ BOOL FASTCALL SCSINuvolink::SendMessage10(const DWORD *cdb, BYTE *buf)
return FALSE;
}
//---------------------------------------------------------------------------
//
// Set the Multicast Configuration
//
//---------------------------------------------------------------------------
void FASTCALL SCSINuvolink::SetMulticastRegisters(BYTE *buffer, int len){
LOGINFO("%s I should be setting the multicast registers here, but I'll just print instead...", __PRETTY_FUNCTION__);
LOGINFO("%s Got %d bytes", __PRETTY_FUNCTION__, len)
for(int i=0; i<len; i++){
LOGINFO("%s Byte %d: %02X", __PRETTY_FUNCTION__, i, (WORD)buffer[i]);
}
}
#if defined(RASCSI) && !defined(BAREMETAL)
//---------------------------------------------------------------------------
//
@@ -436,9 +445,14 @@ void FASTCALL SCSINuvolink::SetMacAddr(BYTE *mac)
{
ASSERT(this);
ASSERT(mac);
LOGTRACE("SCSINuvolink::SetMacAddr");
LOGTRACE("%s Setting mac address", __PRETTY_FUNCTION__);
memcpy(mac_addr, mac, 6);
for(size_t i=0; i<sizeof(mac_addr); i++)
{
LOGTRACE("%d: %02X",i,(WORD)mac[i]);
}
memcpy(mac_addr, mac, sizeof(mac_addr));
}
//---------------------------------------------------------------------------
@@ -487,13 +501,13 @@ void FASTCALL SCSINuvolink::ReceivePacket()
// Get Packet
//
//---------------------------------------------------------------------------
void FASTCALL SCSINuvolink::GetPacketBuf(BYTE *buf)
void FASTCALL SCSINuvolink::GetPacketBuf(BYTE *buffer)
{
int len;
ASSERT(this);
ASSERT(tap);
ASSERT(buf);
ASSERT(buffer);
LOGTRACE("SCSINuvolink::GetPacketBuf");
// Size limit
@@ -503,7 +517,7 @@ void FASTCALL SCSINuvolink::GetPacketBuf(BYTE *buf)
}
// Copy
memcpy(buf, packet_buf, len);
memcpy(buffer, packet_buf, len);
// Received
packet_enable = FALSE;
@@ -514,14 +528,36 @@ void FASTCALL SCSINuvolink::GetPacketBuf(BYTE *buf)
// Send Packet
//
//---------------------------------------------------------------------------
void FASTCALL SCSINuvolink::SendPacket(BYTE *buf, int len)
BOOL SCSINuvolink::SendPacket(BYTE *buffer, int len)
{
ASSERT(this);
ASSERT(tap);
ASSERT(buf);
LOGTRACE("SCSINuvolink::SendPacket");
ASSERT(buffer);
tap->Tx(buf, len);
LOGERROR("%s buffer addr %016lX len:%d", __PRETTY_FUNCTION__, (DWORD)buffer, len);
LOGDEBUG("%s Total Len: %d", __PRETTY_FUNCTION__, len);
LOGDEBUG("%s Destination Addr: %02X:%02X:%02X:%02X:%02X:%02X",\
__PRETTY_FUNCTION__, (WORD)buffer[0], (WORD)buffer[1], (WORD)buffer[2], (WORD)buffer[3], (WORD)buffer[4], (WORD)buffer[5]);
LOGDEBUG("%s Source Addr: %02X:%02X:%02X:%02X:%02X:%02X",\
__PRETTY_FUNCTION__, (WORD)buffer[6], (WORD)buffer[7], (WORD)buffer[8], (WORD)buffer[9], (WORD)buffer[10], (WORD)buffer[11]);
LOGDEBUG("%s EtherType: %02X:%02X", __PRETTY_FUNCTION__, (WORD)buffer[12], (WORD)buffer[13]);
for(int i=0; i<len; i+=8){
LOGDEBUG("Packet contents: %02X: %02X %02X %02X %02X %02X %02X %02X %02X", i,\
(WORD)buffer[i],\
(WORD)buffer[i+1],\
(WORD)buffer[i+2],\
(WORD)buffer[i+3],\
(WORD)buffer[i+4],\
(WORD)buffer[i+5],\
(WORD)buffer[i+6],\
(WORD)buffer[i+7]);
}
tap->Tx(buffer, len);
return TRUE;
}
#endif // RASCSI && !BAREMETAL