diff --git a/Asuro.iso b/Asuro.iso index 7d7e7b7c..a95d4e2e 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/bin/kernel.bin b/bin/kernel.bin index e4247951..61776e4f 100755 Binary files a/bin/kernel.bin and b/bin/kernel.bin differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index e4247951..61776e4f 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/arp.ppu b/lib/arp.ppu index c7e05eae..f3418e4d 100644 Binary files a/lib/arp.ppu and b/lib/arp.ppu differ diff --git a/lib/asuro.ppu b/lib/asuro.ppu index 6f089654..861e639a 100644 Binary files a/lib/asuro.ppu and b/lib/asuro.ppu differ diff --git a/lib/eth2.ppu b/lib/eth2.ppu index 51de1e0c..00d1313f 100644 Binary files a/lib/eth2.ppu and b/lib/eth2.ppu differ diff --git a/lib/ipv4.ppu b/lib/ipv4.ppu index 84da8a75..c25761f7 100644 Binary files a/lib/ipv4.ppu and b/lib/ipv4.ppu differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index 230fb4fc..e58e6562 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 0e2eda84..fc7a7d91 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 0cc2bdb3..73b47f8b 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/lib/net.ppu b/lib/net.ppu index d3847083..d85036f6 100644 Binary files a/lib/net.ppu and b/lib/net.ppu differ diff --git a/lib/shell.ppu b/lib/shell.ppu index 67257d2f..1a33b840 100644 Binary files a/lib/shell.ppu and b/lib/shell.ppu differ diff --git a/lib/terminal.ppu b/lib/terminal.ppu index 2348e274..1ea87a67 100644 Binary files a/lib/terminal.ppu and b/lib/terminal.ppu differ diff --git a/src/driver/net/l2/eth2.pas b/src/driver/net/l2/eth2.pas index b12b51bc..2bf1bcb4 100644 --- a/src/driver/net/l2/eth2.pas +++ b/src/driver/net/l2/eth2.pas @@ -3,12 +3,14 @@ unit eth2; interface uses + lmemorymanager, util, tracer, nettypes, netutils, net, netlog, console; +procedure send(p_data : void; p_len : uint16; p_context : PPacketContext); procedure registerType(eType : uint16; RecvCB : TRecvCallback); procedure register; @@ -27,6 +29,27 @@ begin pop_trace; end; +procedure send(p_data : void; p_len : uint16; p_context : PPacketContext); +var + buffer : void; + hdr : TEthernetHeader; + +begin + push_trace('eth2.send'); + writeToLogLn(' L2: eth2.send'); + if p_context <> nil then begin + buffer:= kalloc(p_len + sizeof(TEthernetHeader)); + copyMAC(@p_context^.MAC.Source[0], @hdr.src[0]); + copyMAC(@p_context^.MAC.Destination[0], @hdr.dst[0]); + hdr.EthTypeHi:= 0; + hdr.EthTypeLo:= 1; + memcpy(uint32(@hdr), uint32(buffer), sizeof(TEthernetHeader)); + memcpy(uint32(p_data), uint32(buffer+sizeof(TEthernetHeader)), p_len); + net.send(buffer, p_len + sizeof(TEthernetHeader)); + kfree(buffer); + end; +end; + procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); var Header : PEthernetHeader; diff --git a/src/driver/net/l3/arp.pas b/src/driver/net/l3/arp.pas index 37756e12..65185e97 100644 --- a/src/driver/net/l3/arp.pas +++ b/src/driver/net/l3/arp.pas @@ -3,11 +3,11 @@ unit arp; interface uses - tracer, + tracer, lmemorymanager, util, lists, console, net, nettypes, netutils, netlog, - eth2; + eth2, ipv4; type PARPCacheRecord = ^TARPCacheRecord; @@ -62,15 +62,57 @@ begin pop_trace; end; +procedure send(hType : uint16; pType : uint16; op : uint16; p_context : PPacketContext); +var + buf : void; + hdr : PARPHeader; + hSize, pSize : uint8; + +begin + push_trace('arp.send'); + writeToLogLn(' L3: arp.send'); + if p_context <> nil then begin + buf:= kalloc(sizeof(TARPHeader)); + hdr:= PARPHeader(buf); + case hType of + $1 : hSize:= 6; + else hSize:= 0; + end; + case pType of + $8000 : pSize:= 4; + else pSize:= 0; + end; + if (hSize > 0) and (pSize > 0) then begin + hdr^.Hardware_Type_Hi:= hType SHR 8; + hdr^.Hardware_Type_Lo:= hType AND $FF; + hdr^.Protocol_Type_Hi:= pType SHR 8; + hdr^.Protocol_Type_Lo:= pType AND $FF; + hdr^.Hardware_Address_Length:= hSize; + hdr^.Protocol_Address_Length:= pSize; + hdr^.Operation_Hi:= op SHR 8; + hdr^.Operation_Lo:= op AND $FF; + copyMAC(@p_context^.MAC.Source[0], @hdr^.Source_Hardware[0]); + copyIPv4(@p_context^.IP.Source[0], @hdr^.Source_Protocol[0]); + copyMAC(@p_context^.MAC.Destination[0], @hdr^.Destination_Hardware[0]); + copyIPv4(@p_context^.IP.Destination[0], @hdr^.Destination_Protocol[0]); + eth2.send(buf, sizeof(TARPHeader), p_context); + end; + kfree(buf); + end; +end; + procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); var Header : PARPHeader; AHeader : TARPAbstractHeader; CacheElement : PARPCacheRecord; + Merge : boolean; + context : PPacketContext; begin push_trace('arp.recv'); writeToLogLn(' L3: arp.recv'); + { Get our converted Header } Header:= PARPHeader(p_data); AHeader.Hardware_Type:= (Header^.Hardware_Type_Hi SHL 8) + Header^.Hardware_Type_Lo; @@ -82,36 +124,59 @@ begin copyIPv4(@Header^.Source_Protocol[0], @AHeader.Source_Protocol[0]); copyMAC(@Header^.Destination_Hardware[0], @AHeader.Destination_Hardware[0]); copyIPv4(@Header^.Destination_Protocol[0], @AHeader.Destination_Protocol[0]); - case AHeader.Operation of - $1:begin { ARP Request } - writeToLogLn(' arp.recv.arp.req'); - end; - $2:begin { ARP Reply } - writeToLogLn(' arp.recv.arp.rep'); - end; - $3:begin { RARP Request } - writeToLogLn(' arp.recv.rarp.req'); - end; - $4:begin { RARP Reply } - writeToLogLn(' arp.recv.rarp.rep'); - end; - $5:begin { DRARP Request } - writeToLogLn(' arp.recv.drarp.req'); - end; - $6:begin { DRARP Reply } - writeToLogLn(' arp.recv.drarp.rep'); - end; - $7:begin { DRARP Error } - writeToLogLn(' arp.recv.drarp.err'); - end; - $8:begin { InARP Request } - writeToLogLn(' arp.recv.inarp.req'); - end; - $9:begin { InARP Reply } - writeToLogLn(' arp.recv.inarp.rep'); + + { Process ARP Packet } + Merge:= false; + CacheElement:= findCacheRecordByIP(@AHeader.Source_Protocol[0]); + if CacheElement <> nil then begin + copyMAC(@AHeader.Source_Hardware[0], @CacheElement^.MAC[0]); + Merge:= true; + end else begin + if IPEqual(@AHeader.Destination_Protocol[0], @getIPv4Config^.Address[0]) then begin + if not Merge then begin + CacheElement:= PARPCacheRecord(LL_Add(Cache)); + CopyMAC(@AHeader.Source_Hardware[0], @CacheElement^.MAC[0]); + copyIPv4(@AHeader.Source_Protocol[0], @CacheElement^.IP[0]); + end; + case AHeader.Operation of + $1:begin { ARP Request } + writeToLogLn(' arp.recv.arp.req'); + context:= newPacketContext; + //context^. + copyMAC(@AHeader.Source_Hardware[0], @context^.MAC.Destination[0]); + copyIPv4(@AHeader.Source_Protocol[0], @context^.IP.Destination[0]); + copyMAC(getMAC, @context^.MAC.Source[0]); + copyIPv4(@getIPv4Config^.Address[0], @context^.IP.Source[0]); + send($1, $8000, $2, context); + freePacketContext(context); + end; + $2:begin { ARP Reply } + writeToLogLn(' arp.recv.arp.rep'); + end; + $3:begin { RARP Request } + writeToLogLn(' arp.recv.rarp.req'); + end; + $4:begin { RARP Reply } + writeToLogLn(' arp.recv.rarp.rep'); + end; + $5:begin { DRARP Request } + writeToLogLn(' arp.recv.drarp.req'); + end; + $6:begin { DRARP Reply } + writeToLogLn(' arp.recv.drarp.rep'); + end; + $7:begin { DRARP Error } + writeToLogLn(' arp.recv.drarp.err'); + end; + $8:begin { InARP Request } + writeToLogLn(' arp.recv.inarp.req'); + end; + $9:begin { InARP Reply } + writeToLogLn(' arp.recv.inarp.rep'); + end; + end; end; end; - pop_trace; end; procedure register; diff --git a/src/driver/net/l3/ipv4.pas b/src/driver/net/l3/ipv4.pas index 6775d261..8f0059c6 100644 --- a/src/driver/net/l3/ipv4.pas +++ b/src/driver/net/l3/ipv4.pas @@ -10,6 +10,7 @@ uses eth2; procedure registerProtocol(Protocol_ID : uint8; recv_callback : TRecvCallback); +function getIPv4Config : PIPv4Configuration; procedure register; implementation @@ -19,6 +20,11 @@ var Protocols : Array[0..255] of TRecvCallback; Config : TIPv4Configuration; +function getIPv4Config : PIPv4Configuration; +begin + getIPv4Config:= @Config; +end; + procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); var Header : PIPV4Header; diff --git a/src/include/asuro.pas b/src/include/asuro.pas index 8e6780d6..c54bdcfa 100644 --- a/src/include/asuro.pas +++ b/src/include/asuro.pas @@ -9,14 +9,14 @@ const VERSION_SUB = '1'; REVISION = '677'; RELEASE = 'ia'; - LINE_COUNT = 27683; + LINE_COUNT = 27777; FILE_COUNT = 89; DRIVER_COUNT = 32; FPC_VERSION = '2.6.4'; NASM_VERSION = '2.10.09'; MAKE_VERSION = '3.81'; COMPILE_DATE = '10/05/18'; - COMPILE_TIME = '10:07:09'; + COMPILE_TIME = '11:33:11'; implementation