Fixed PCNet DE index rollover packet buffer bug.

Added few more networking tests and changed variables in some of them for making it easier to differentiate them in Wireshark .pcap results.
This commit is contained in:
TomAwezome 2021-01-18 19:22:12 -05:00
parent fc0bf860b1
commit 3ef48c1e28
9 changed files with 82 additions and 4 deletions

View file

@ -23,5 +23,6 @@ if (Fs != zenith_task)
#include "C:/Home/Net/NetHandlerTask" // needs IPV4, UDP, ICMP #include "C:/Home/Net/NetHandlerTask" // needs IPV4, UDP, ICMP
"\nNow run $FG,0$NetConfigure;$FG$ or run one of the $MA,"Tests",LM="Cd(\"C:/Home/Net/Tests\");Dir;\n"$.\n\n"; NetConfigure;
"\nNow run one of the $MA,"Tests",LM="Cd(\"C:/Home/Net/Tests\");Dir;\n"$.\n\n";

View file

@ -496,6 +496,8 @@ I64 PCNetAllocateTransmitPacket(U8 **packet_buffer_out, I64 length)
buffer_byte_count = -length; // Sets up as 2s complement of the desired length. buffer_byte_count = -length; // Sets up as 2s complement of the desired length.
buffer_byte_count &= 0x0FFF; // Masks 0 over everything except bits 0-11. buffer_byte_count &= 0x0FFF; // Masks 0 over everything except bits 0-11.
entry->status1 &= 0xFFFFF000; // Clear first 12 bits and retain other bits in DE TMD1.
entry->status1 |= buffer_byte_count; // Sets BCNT reg (first 12 bits) in DE TMD1. entry->status1 |= buffer_byte_count; // Sets BCNT reg (first 12 bits) in DE TMD1.
entry->status1 |= 0xF000; // Sets bits 12-15 (ONES) in DE TMD1 as all ones. entry->status1 |= 0xF000; // Sets bits 12-15 (ONES) in DE TMD1 as all ones.
@ -503,6 +505,8 @@ I64 PCNetAllocateTransmitPacket(U8 **packet_buffer_out, I64 length)
*packet_buffer_out = pcnet.tx_buffer_addr + (de_index * ETHERNET_FRAME_SIZE); *packet_buffer_out = pcnet.tx_buffer_addr + (de_index * ETHERNET_FRAME_SIZE);
MemSet(*packet_buffer_out, 0, ETHERNET_FRAME_SIZE); // Clear buffer contents in advance.
ZenithLog("PCNET ALLOCATE TX PACKET: de_index: %X.\n", de_index); ZenithLog("PCNET ALLOCATE TX PACKET: de_index: %X.\n", de_index);
return de_index; return de_index;
} }

View file

@ -0,0 +1,13 @@
U0 DHCPSendTrash()
{
while (TRUE)
{
DHCPSendDiscover(0xDEADBEEF);
Sleep(300);
DHCPSendRequest(0xDEADBEEF, 0xC0DEFADE, 0xFEEDFACE);
Sleep(300);
}
}
DHCPSendTrash;

View file

@ -0,0 +1,27 @@
U8 dst_mac[6] = {0xF0, 0x0D, 0xBE, 0xAD, 0xDE, 0xAF};
U32 dst_ip = 0x01020304;
U0 DHCPSendTrash()
{ // DHCPConfigure, then send UDP trash.
U8 *udp_payload;
I64 de_index;
ARPCachePut(dst_ip, dst_mac); // Force entry into ARP Cache so IPV4 can match it with GetMACAddressForIP
DHCPConfigure;
while (TRUE)
{
de_index = UDPPacketAllocate(&udp_payload, arp_globals.local_ipv4, 0xDEAD, dst_ip, 0xBEEF, 8);
*(udp_payload(U64 *)) = EndianU64(0xDEADBEEFC0DEFADE);
UDPPacketFinish(de_index);
Sleep(300);
}
}
DHCPSendTrash;

View file

@ -0,0 +1,33 @@
U8 src[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xC0, 0xDE};
U8 dst[6] = {0xF0, 0x0D, 0xBE, 0xAD, 0xDE, 0xAF};
U0 DHCPSendTrash()
{
CUDPSocket *udp_socket = UDPSocket(AF_INET);
U32 your_ip;
U32 dns_ip;
U32 router_ip;
U32 subnet_mask;
U8 *packet_buffer;
I64 de_index;
DHCPConfigureInner(udp_socket, &your_ip, &dns_ip, &router_ip, &subnet_mask);
UDPSocketClose(udp_socket);
while (TRUE)
{
de_index = EthernetFrameAllocate(&packet_buffer, src, dst, 0x0000, 8);
*(packet_buffer(U64 *)) = EndianU64(0xDEADBEEFC0DEFADE);
EthernetFrameFinish(de_index);
Sleep(300);
}
}
DHCPSendTrash;

View file

@ -11,7 +11,7 @@ U0 EthernetSendTrash()
{ {
de_index = EthernetFrameAllocate(&packet_buffer, src, dst, 0x0000, 8); de_index = EthernetFrameAllocate(&packet_buffer, src, dst, 0x0000, 8);
*(packet_buffer(U64 *)) = EndianU64(0xDEADBEEFC0DEFADE); *(packet_buffer(U64 *)) = EndianU64(0xC0DEFADEDEADBEEF);
EthernetFrameFinish(de_index); EthernetFrameFinish(de_index);
Sleep(300); Sleep(300);

View file

@ -7,7 +7,7 @@ U0 ICMPSendTrash()
{ {
U8 *data_payload = CAlloc(8); U8 *data_payload = CAlloc(8);
*(data_payload(U64 *)) = EndianU64(0xDEADBEEFC0DEFADE); *(data_payload(U64 *)) = EndianU64(0xDEADC0DEBEEFFADE);
ARPCachePut(dst_ip, dst_mac); // Force entry into ARP Cache so IPV4 can match it with GetMACAddressForIP ARPCachePut(dst_ip, dst_mac); // Force entry into ARP Cache so IPV4 can match it with GetMACAddressForIP

View file

@ -14,7 +14,7 @@ U0 IPV4SendTrash()
{ {
de_index = IPV4PacketAllocate(&ipv4_packet_buffer, 0xFF, src_ip, dst_ip, 8); de_index = IPV4PacketAllocate(&ipv4_packet_buffer, 0xFF, src_ip, dst_ip, 8);
*(ipv4_packet_buffer(U64 *)) = EndianU64(0xDEADBEEFC0DEFADE); *(ipv4_packet_buffer(U64 *)) = EndianU64(0xBEEFDEADFADEC0DE);
IPV4PacketFinish(de_index); IPV4PacketFinish(de_index);
Sleep(300); Sleep(300);