Cosmos/source/FrodeTest/Shell/Session.cs
sschocke_cp 7af62315ec RTL8139 Driver Changes
Update Global to call driver initialization routines for different drivers. Devices are enumerated during startup regardless of what hardware you are using.
Update FrodeTest workspace to run via new NetworkDevice interface
Update Builder.cs so that QEMU gets called with only either "-net tap" or "-net user", as these two options conflict
Internalized most of the TCP/IP stack leaving only the User needed classes available to use.
Commented most of TCP/IP stack public methods, and cleaned out code a little bit.
2009-03-31 20:33:22 +00:00

204 lines
7.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.Hardware.Network.Devices.RTL8139;
using Cosmos.Kernel;
using FrodeTest.Application;
namespace FrodeTest.Shell
{
public class Session
{
static Cosmos.Hardware.Network.NetworkDevice nic = null;
/// <summary>
/// Starts an interactive session where user can input commands.
/// </summary>
public static void Run()
{
//Console.Write(@"Cosmos:\>");
Console.Write(System.IO.Directory.GetCurrentDirectory() + ">");
string command = Console.ReadLine();
if (command.Equals("exit") || command.Equals("test"))
return;
//else if (command.Equals("reboot"))
// Cosmos.Sys.Deboot.Reboot();
else if (command.Equals("ether"))
{
Test.Ethernet2FrameTest.RunTest();
}
else if (command.Equals("ip"))
{
Test.IPv4Test.RunTest();
}
else if (command.Equals("udp"))
{
Test.UDPTest.RunTests();
}
//else if (command.Equals("ping"))
//{
// ping xPingApplication = new ping();
// xPingApplication.Execute("172.28.5.1");
//}
//else if (command.Equals("ping"))
//{
//}
else if (command.Equals("icmp"))
{
Test.ICMPv4Test.RunTest();
}
else if (command.Equals("mac"))
{
if (nic == null)
{
Console.WriteLine("Enable NIC with command 'load' first");
}
else
{
Console.WriteLine("MAC: " + nic.MACAddress);
}
}
else if (command.Equals("load"))
{
var list = Cosmos.Hardware.Network.NetworkDevice.NetworkDevices;
if (list.Count != 0)
{
nic = list[0];
Console.WriteLine("Enabling network card!");
Console.WriteLine(nic.Name);
Console.WriteLine("MAC: " + nic.MACAddress);
nic.Enable();
}
else
{
Console.WriteLine("Unable to find RTL8139 network card!");
}
}
//else if (command.Equals("send"))
//{
// if (nic == null)
// {
// Console.WriteLine("Enable NIC with command 'load' first");
// }
// else
// {
// var head = new PacketHeader(0xFF);
// byte[] data = FrodeTest.Test.Mock.FakeBroadcastPacket.GetFakePacket();
// var packet = new Packet(head, data);
// //nic.Transmit(packet);
// nic.TransmitBytes(data); //TODO: Wrap data in physical packet with header.
// //nic.TransmitBytes(data);
// }
//}
else if (command.Equals("read"))
{
if (nic == null)
{
Console.WriteLine("Enable NIC with command 'load' first");
return;
}
else
{
Console.WriteLine("Data in RX Buffer:");
foreach (byte item in nic.ReceivePacket())
{
Console.Write(item.ToHex() + ":");
}
}
}
else if (command.Equals("info"))
{
if (nic == null)
{
Console.WriteLine("Network card not initialized yet.");
}
else
{
Console.WriteLine("Network card: " + nic.Name);
Console.WriteLine("MAC Address: " + nic.MACAddress);
Console.WriteLine();
Console.WriteLine("NIC enabled?: " + nic.IsEnabled.ToString());
int xByteCount = 0;
foreach (byte b in nic.ReceivePacket())
{
if (b != 0x00)
xByteCount++;
}
Console.WriteLine("Read buffer contains " + xByteCount.ToString() + " non-zero bytes with data.");
}
}
else if (command.Equals("dump"))
{
if (nic == null)
{
Console.WriteLine("Network card not initialized yet.");
}
else
{
//nic.DumpRegisters();
}
}
else if (command.Equals("reset"))
{
if (nic == null)
Console.WriteLine("Network card not initialized yet.");
else
{
//nic.TimerCount = 1;
//nic.SoftReset();
//nic.InitializeDriver();
Console.WriteLine("NIC has been reset");
}
}
else if (command.Equals("disable"))
{
nic.Disable();
}
else if (command.Equals("enable"))
{
nic.Enable();
}
else if (command.Equals("unload"))
{
nic.Disable();
nic = null;
}
else if (command.Equals("loop"))
{
//Console.WriteLine("Toggeling loopback mode from : " + nic.LoopbackMode.ToString());
//nic.LoopbackMode = !nic.LoopbackMode;
//Console.WriteLine("to: " + nic.LoopbackMode.ToString());
}
else if (command.Equals("prom"))
{
//nic.PromiscuousMode = !nic.PromiscuousMode;
}
else
{
Application.ConsoleApplicationManager conAppManager = new FrodeTest.Application.ConsoleApplicationManager();
ConsoleApplicationManager.CommandLineSentence xCommand = new ConsoleApplicationManager.CommandLineSentence(command);
//Console.WriteLine("cmd:" + xCommand.Command + ":");
//Console.WriteLine("args:" + xCommand.Arguments[ + ":");
//foreach (string arg in xCommand.Arguments)
//{
// Console.WriteLine("Argument:" + arg + ":");
//}
Application.IConsoleApplication xConsoleApp = conAppManager.GetConsoleApplication(xCommand.Command);
if (xConsoleApp != null)
{
xConsoleApp.Execute(xCommand.Arguments);
}
else
Console.WriteLine("Unknown command or application: " + xCommand.Command + ". Try typing 'help'.");
}
Run(); //Recursive call
}
}
}