mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-12 03:01:32 +00:00
RTL - Promiscuous mode and some TCR changes.
This commit is contained in:
parent
b56844dbf1
commit
1502cd7ff9
7 changed files with 130 additions and 44 deletions
|
|
@ -34,7 +34,7 @@ namespace KudzuTest {
|
|||
//Cosmos.Kernel.Temp.Kudzu.PCI.Test();
|
||||
|
||||
// Load
|
||||
var xNICs = RTLDriver.RTL8139.FindRTL8139Devices();
|
||||
var xNICs = RTLDriver.RTL8139.FindAll();
|
||||
if (xNICs.Count == 0) {
|
||||
throw new Exception("Unable to find RTL8139 network card!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ namespace Cosmos.Build.Windows {
|
|||
// Ethernet card - Later the model should be a QEMU option on
|
||||
// options screen
|
||||
+ " -net nic,model=rtl8139,macaddr=52:54:00:12:34:57"
|
||||
//+ " -net tap,ifname=CosmosTAP" //for network testing
|
||||
+ " -net user"
|
||||
, ToolsPath + @"qemu\", false, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
/// Retrieve all Realtek 8139 network cards found on computer.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<RTL8139> FindRTL8139Devices()
|
||||
public static List<RTL8139> FindAll()
|
||||
{
|
||||
List<RTL8139> found = new List<RTL8139>();
|
||||
|
||||
|
|
@ -39,11 +39,6 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
private byte[] TxBuffer2;
|
||||
private byte[] TxBuffer3;
|
||||
private byte[] RxBuffer;
|
||||
//private byte[] RxBuffer2 = new byte[2048];
|
||||
//private byte[] RxBuffer3 = new byte[2048];
|
||||
//private byte[] RxBuffer4 = new byte[2048];
|
||||
|
||||
|
||||
|
||||
public RTL8139(PCIDevice device)
|
||||
{
|
||||
|
|
@ -101,6 +96,7 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
//Setting Receive configuration
|
||||
var rcr = Register.ReceiveConfigurationRegister.Load(pciCard);
|
||||
rcr.Init();
|
||||
rcr.PromiscuousMode = true;
|
||||
|
||||
//Enable IRQ Interrupt
|
||||
SetIRQMaskRegister();
|
||||
|
|
@ -108,22 +104,43 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
Cosmos.Hardware.PC.Interrupts.IRQ11 = new Cosmos.Hardware.PC.Interrupts.InterruptDelegate(HandleNetworkInterrupt);
|
||||
}
|
||||
|
||||
#region Operational properties
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Loopback mode.
|
||||
/// </summary>
|
||||
/// <param name="value">True to enable Loopback. False for normal operation.</param>
|
||||
public void SetLoopbackMode(bool value)
|
||||
public bool LoopbackMode
|
||||
{
|
||||
var tcr = Register.TransmitConfigurationRegister.Load(pciCard);
|
||||
tcr.LoopbackMode = value;
|
||||
get
|
||||
{
|
||||
var tcr = Register.TransmitConfigurationRegister.Load(pciCard);
|
||||
return tcr.LoopbackMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
var tcr = Register.TransmitConfigurationRegister.Load(pciCard);
|
||||
tcr.LoopbackMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetLoopbackMode()
|
||||
public bool PromiscuousMode
|
||||
{
|
||||
var tcr = Register.TransmitConfigurationRegister.Load(pciCard);
|
||||
return tcr.LoopbackMode;
|
||||
get
|
||||
{
|
||||
var rcr = Register.ReceiveConfigurationRegister.Load(pciCard);
|
||||
return rcr.PromiscuousMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
var rcr = Register.ReceiveConfigurationRegister.Load(pciCard);
|
||||
rcr.PromiscuousMode = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override bool QueueBytes(byte[] buffer, int offset, int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
@ -155,11 +172,18 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
get { return "Generic RTL8139 Network device"; }
|
||||
}
|
||||
|
||||
#region Power and Initilization
|
||||
|
||||
/// <summary>
|
||||
/// Enables RTL network card by setting CONFIG_1 register.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool Enable()
|
||||
{
|
||||
//Writes 0x00 to CONFIG_1 registers to enable card
|
||||
regs.Config1 = 0x00;
|
||||
return true;
|
||||
regs.Config1 = 0x00;
|
||||
|
||||
return base.Enable(); //enables PCI card as well
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -181,6 +205,11 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
Console.WriteLine("Reset Complete!");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Receive and Interrupt
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// (Should be) Called when the PCI network card raises an Interrupt.
|
||||
/// </summary>
|
||||
|
|
@ -221,6 +250,8 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enable the NIC to be able to Recieve data.
|
||||
/// </summary>
|
||||
|
|
@ -369,7 +400,7 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool TransmitRaw(byte[] aData) {
|
||||
WriteAddressToPCI(ref aData, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD0);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
/// <summary>
|
||||
/// Receive Configuration Register is used to set receive configuration.
|
||||
/// Offset 44h from main memory.
|
||||
/// Is 32 bits wide.
|
||||
/// </summary>
|
||||
public class ReceiveConfigurationRegister
|
||||
{
|
||||
|
|
@ -34,13 +35,35 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
IOSpace.Write32(rcrAddress, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or Sets all 32 bits in Receive Configuration Register
|
||||
/// </summary>
|
||||
public UInt32 RCR
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOSpace.Read32(rcrAddress);
|
||||
}
|
||||
private set { ;}
|
||||
private set
|
||||
{
|
||||
IOSpace.Write32(rcrAddress, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the promiscuous mode. When Promisuous mode set ALL detected packets on network are put into Receive buffer, not
|
||||
/// just the packets sent directly to us.
|
||||
/// </summary>
|
||||
public bool PromiscuousMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return BinaryHelper.CheckBit(IOSpace.Read32(rcrAddress), 0);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.RCR = BinaryHelper.FlipBit(this.RCR, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public enum BitValue : uint
|
||||
|
|
|
|||
|
|
@ -14,12 +14,10 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
/// </summary>
|
||||
public class TransmitConfigurationRegister
|
||||
{
|
||||
private UInt32 tcr;
|
||||
private PCIDevice pci;
|
||||
private UInt32 tcrAddress;
|
||||
private TransmitConfigurationRegister(UInt32 data, PCIDevice hw, UInt32 adr)
|
||||
{
|
||||
tcr = data;
|
||||
pci = hw;
|
||||
tcrAddress = adr;
|
||||
}
|
||||
|
|
@ -35,40 +33,45 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
{
|
||||
//Set Interframe Gap and Max Burst Size (to 128 bytes)
|
||||
UInt32 data = (UInt32)(BitValue.IFG0 | BitValue.IFG1 | BitValue.MAXDMA0 | BitValue.MAXDMA1);
|
||||
//Console.WriteLine("Data in INIT for TX:" + data);
|
||||
IOSpace.Write32(tcrAddress, data);
|
||||
this.TCR = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves 6 bits
|
||||
/// Get or Sets all 32 bits in Transmit Configuration Register
|
||||
/// </summary>
|
||||
public UInt32 TCR
|
||||
{
|
||||
get
|
||||
{
|
||||
return IOSpace.Read32(tcrAddress);
|
||||
}
|
||||
private set
|
||||
{
|
||||
IOSpace.Write32(tcrAddress, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a number which indicates the Hardware Revision ID of the RTL card.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte GetHWVERID()
|
||||
{
|
||||
byte mask = 249; // 1111 1001
|
||||
byte hwverid = BinaryHelper.GetByteFrom32bit(tcr, (byte)(23));
|
||||
byte hwverid = BinaryHelper.GetByteFrom32bit(this.TCR, (byte)(23));
|
||||
return (byte)(mask & hwverid);
|
||||
}
|
||||
|
||||
//internal void SetLoopBack(bool value)
|
||||
//{
|
||||
// //Change bits LBK0 and LBK1 to HIGH for Loopback, or LOW for Normal mode.
|
||||
// if (value)
|
||||
|
||||
|
||||
|
||||
//}
|
||||
|
||||
public bool LoopbackMode
|
||||
{
|
||||
get
|
||||
{
|
||||
UInt32 data = IOSpace.Read32(tcrAddress);
|
||||
UInt32 data = this.TCR;
|
||||
bool low = BinaryHelper.CheckBit(data, 17);
|
||||
bool high = BinaryHelper.CheckBit(data, 18);
|
||||
|
||||
|
||||
if (low != high)
|
||||
Console.WriteLine("Warning: Loopback bits should always be the same!");
|
||||
throw new Exception("Loopback bits are mismatched in RTL drivers TCR PCI register!");
|
||||
|
||||
if (low && high)
|
||||
return true;
|
||||
|
|
@ -76,14 +79,14 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
return false;
|
||||
}
|
||||
set
|
||||
{
|
||||
UInt32 data = IOSpace.Read32(tcrAddress);
|
||||
{
|
||||
UInt32 data = this.TCR;
|
||||
if (value) //turn ON
|
||||
data = (UInt32)(data | (uint)BitValue.LBK0 | (uint)BitValue.LBK1);
|
||||
else //turn OFF
|
||||
data = (UInt32)(data & (uint)~BitValue.LBK0 & (uint)~BitValue.LBK1);
|
||||
|
||||
IOSpace.Write32(tcrAddress, data);
|
||||
this.TCR = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace FrodeTest.Shell
|
|||
}
|
||||
*/ else if(command.Equals("load"))
|
||||
{
|
||||
var list = RTL8139.FindRTL8139Devices();
|
||||
var list = RTL8139.FindAll();
|
||||
if (list.Count != 0)
|
||||
nic = list[0];
|
||||
else
|
||||
|
|
@ -46,6 +46,7 @@ namespace FrodeTest.Shell
|
|||
Console.WriteLine(nic.Name);
|
||||
Console.WriteLine("Revision: " + nic.GetHardwareRevision());
|
||||
Console.WriteLine("MAC: " + nic.MACAddress);
|
||||
|
||||
|
||||
nic.Enable();
|
||||
nic.InitializeDriver();
|
||||
|
|
@ -78,6 +79,29 @@ namespace FrodeTest.Shell
|
|||
}
|
||||
//List<Packet> incomingPackets = nic.Recieve();
|
||||
}
|
||||
else if (command.Equals("info"))
|
||||
{
|
||||
if (nic == null)
|
||||
{
|
||||
Console.WriteLine("Network card not initialized yet.");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Network card: " + nic.Name);
|
||||
Console.WriteLine("Hardware revision: " + nic.GetHardwareRevision());
|
||||
Console.WriteLine("MAC Address: " + nic.MACAddress);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Loopback enabled?: " + nic.LoopbackMode.ToString());
|
||||
Console.WriteLine("NIC enabled?: " + nic.IsEnabled.ToString());
|
||||
Console.WriteLine("Promiscuous mode?: " + nic.PromiscuousMode.ToString());
|
||||
|
||||
int xByteCount = 0;
|
||||
foreach (byte b in nic.ReadReceiveBuffer())
|
||||
{
|
||||
if (b != 0x00)
|
||||
xByteCount++;
|
||||
}
|
||||
Console.WriteLine("Read buffer contains " + xByteCount.ToString() + " bytes with data.");
|
||||
}
|
||||
else if (command.Equals("reset"))
|
||||
{
|
||||
//nic.TimerCount = 1;
|
||||
|
|
@ -87,15 +111,19 @@ namespace FrodeTest.Shell
|
|||
}
|
||||
else if (command.Equals("loop"))
|
||||
{
|
||||
Console.WriteLine("Toggeling loopback mode from : " + nic.GetLoopbackMode().ToString());
|
||||
nic.SetLoopbackMode(!nic.GetLoopbackMode());
|
||||
Console.WriteLine("to: " + nic.GetLoopbackMode().ToString());
|
||||
Console.WriteLine("Toggeling loopback mode from : " + nic.LoopbackMode.ToString());
|
||||
nic.LoopbackMode = !nic.LoopbackMode;
|
||||
Console.WriteLine("to: " + nic.LoopbackMode.ToString());
|
||||
}
|
||||
|
||||
else if (command.Equals("crash"))
|
||||
{
|
||||
throw new Exception("User forced an Exception", new Exception("Inner bug"));
|
||||
}
|
||||
else if (command.Equals("prom"))
|
||||
{
|
||||
nic.PromiscuousMode = !nic.PromiscuousMode;
|
||||
}
|
||||
|
||||
else if (command.Equals("help"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ namespace FrodeTest.Test
|
|||
{
|
||||
public class RTL8139Test
|
||||
{
|
||||
[Obsolete]
|
||||
public static void RunTest()
|
||||
{
|
||||
// Testing RTL8139 PCI networkcard
|
||||
//Load card
|
||||
var nics = RTL8139.FindRTL8139Devices();
|
||||
var nics = RTL8139.FindAll();
|
||||
|
||||
if (nics.Count == 0)
|
||||
{
|
||||
|
|
@ -29,7 +30,6 @@ namespace FrodeTest.Test
|
|||
//Console.WriteLine("BaseAddress0 is : " + pciNic.BaseAddress0);
|
||||
Console.WriteLine("BaseAddress1 is : " + nic.PCICard.BaseAddress1);
|
||||
Console.WriteLine("Enabling card...");
|
||||
//nic.SoftReset();
|
||||
nic.Enable();
|
||||
Console.WriteLine("Initializing driver...");
|
||||
nic.InitializeDriver();
|
||||
|
|
|
|||
Loading…
Reference in a new issue