Restructure.
git-svn-id: https://spexeah.com:8443/svn/Asuro@471 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
73
src/driver/net/l2/eth2.pas
Normal file
73
src/driver/net/l2/eth2.pas
Normal file
@ -0,0 +1,73 @@
|
||||
unit eth2;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
nettypes, netutils,
|
||||
net,
|
||||
console;
|
||||
|
||||
procedure registerType(eType : uint16; RecvCB : TRecvCallback);
|
||||
procedure register;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
Registered : Boolean = false;
|
||||
EthTypes : Array[0..65535] of TRecvCallback;
|
||||
MAC : puint8;
|
||||
|
||||
procedure registerType(eType : uint16; RecvCB : TRecvCallback);
|
||||
begin
|
||||
register;
|
||||
if EthTypes[eType] = nil then EthTypes[eType]:= RecvCB;
|
||||
end;
|
||||
|
||||
procedure recv(p_data : void; p_len : uint16);
|
||||
var
|
||||
Header : PEthernetHeader;
|
||||
proto_type : uint16;
|
||||
buf : puint8;
|
||||
|
||||
begin
|
||||
console.outputln('net.eth2', 'RECV.');
|
||||
buf:= puint8(p_data);
|
||||
|
||||
Header:= PEthernetHeader(buf);
|
||||
|
||||
console.output('net.eth2', 'DEST: ');
|
||||
writeMACAddress(@Header^.dst[0]);
|
||||
console.output('net.eth2', 'SRC: ');
|
||||
writeMACAddress(@Header^.src[0]);
|
||||
|
||||
proto_type:= Header^.EthTypeHi SHL 8;
|
||||
proto_type:= proto_type + Header^.EthTypeLo;
|
||||
console.output('net.eth2', 'PROTO: ');
|
||||
console.writehexln(proto_type);
|
||||
|
||||
buf:= buf + 14;
|
||||
|
||||
if MACEqual(@Header^.dst[0], @Header^.src[0]) or MACEqual(@Header^.dst[0], @BROADCAST_MAC[0]) then begin
|
||||
console.outputln('net.eth2', 'MAC HIT');
|
||||
if EthTypes[proto_type] <> nil then begin
|
||||
EthTypes[proto_type](void(buf), p_len - 14);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure register;
|
||||
var
|
||||
i : uint16;
|
||||
|
||||
begin
|
||||
if not Registered then begin
|
||||
for i:=0 to 65535 do begin
|
||||
EthTypes[i]:= nil;
|
||||
end;
|
||||
net.registerNextLayer(@recv);
|
||||
MAC:= net.getMAC;
|
||||
Registered:= true;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user