From 8a477f4f31fc54e494e33bfe2ff4dc99c0639869 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Sat, 23 Jun 2012 07:14:19 +0000 Subject: [PATCH] Finally got bastard Intel PXE ROM to acknowledge us.... --- source2/Cosmos.Deploy.Pixie/DHCP.cs | 15 +++++++++------ source2/Cosmos.Deploy.Pixie/DhcpPacket.cs | 12 ++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source2/Cosmos.Deploy.Pixie/DHCP.cs b/source2/Cosmos.Deploy.Pixie/DHCP.cs index c62997554..47d14ef7e 100644 --- a/source2/Cosmos.Deploy.Pixie/DHCP.cs +++ b/source2/Cosmos.Deploy.Pixie/DHCP.cs @@ -30,25 +30,28 @@ namespace Cosmos.Deploy.Pixie { xOut.YourAddr = BitConverter.ToUInt32(new byte[] { 192, 168, 42, 2 }, 0); xOut.ServerAddr = BitConverter.ToUInt32(new byte[] { 192, 168, 42, 1 }, 0); xOut.HwAddr = xIn.HwAddr; + xOut.Flags = xIn.Flags; xOut.Msg = DhcpPacket.MsgType.Offer; xOut.Options.Add(1, new byte[] { 255, 255, 255, 0 }); xOut.Options.Add(51, new byte[] { 0, 0, 255, 255 }); xOut.Options.Add(54, new byte[] { 192, 168, 42, 1 }); + xOut.Options.Add(13, new byte[] { 4, 255 }); var xOutBytes = xOut.GetBytes(); var xBroadcastIP = new IPAddress(new byte[] { 192, 168, 42, 255 }); - mUDP.Send(xOutBytes, xOutBytes.Length, new IPEndPoint(xBroadcastIP, 68)); + mUDP.Send(xOutBytes, xOutBytes.Length, new IPEndPoint(IPAddress.Broadcast, 68)); while (true) { xData = mUDP.Receive(ref xEndpoint); xIn = new DhcpPacket(xData); - if (xIn.Msg != DhcpPacket.MsgType.Discover) { - int i = 0; - } - if (xIn.Msg != DhcpPacket.MsgType.Request) { - //throw new Exception("Expected Request"); + if (xIn.Msg == DhcpPacket.MsgType.Discover) { + break; + } else if (xIn.Msg != DhcpPacket.MsgType.Request) { + throw new Exception("Unexpected DHCP message.") } } + + } } diff --git a/source2/Cosmos.Deploy.Pixie/DhcpPacket.cs b/source2/Cosmos.Deploy.Pixie/DhcpPacket.cs index f6dc38c67..c727e2c80 100644 --- a/source2/Cosmos.Deploy.Pixie/DhcpPacket.cs +++ b/source2/Cosmos.Deploy.Pixie/DhcpPacket.cs @@ -27,8 +27,7 @@ namespace Cosmos.Deploy.Pixie { //secs 2 filled in by client, seconds elapsed since client started trying to boot. xReader.ReadUInt16(); - //flags 2 - xReader.ReadUInt16(); + Flags = xReader.ReadUInt16(); // Dont reverse IP Addresses, byte arrays end up big endian as we write them back ClientAddr = xReader.ReadUInt32(); @@ -83,14 +82,18 @@ namespace Cosmos.Deploy.Pixie { xWriter.Write((byte)0); xWriter.Write(TxID); - xWriter.Write(0); + xWriter.Write((UInt16)0); + xWriter.Write(Flags); xWriter.Write(0); xWriter.Write(YourAddr); xWriter.Write(ServerAddr); xWriter.Write(0); xWriter.Write(HwAddr); xWriter.Write(new byte[64]); - xWriter.Write(new byte[128]); + + xWriter.Write(ASCIIEncoding.ASCII.GetBytes("TEST")); + xWriter.Write(new byte[124]); + xWriter.Write(mMagicCookie); xWriter.Write((byte)53); @@ -120,6 +123,7 @@ namespace Cosmos.Deploy.Pixie { public byte HwLength; public byte Hops; public UInt32 TxID; + public UInt16 Flags; public UInt32 ClientAddr; public UInt32 YourAddr; public UInt32 ServerAddr;