git-svn-id: https://spexeah.com:8443/svn/Asuro@423 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
51
src/driver/net/eth2.pas
Normal file
51
src/driver/net/eth2.pas
Normal file
@ -0,0 +1,51 @@
|
||||
unit eth2;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
net, nettypes, console;
|
||||
|
||||
procedure register;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
Registered : Boolean = false;
|
||||
EthTypes : Array[0..65535] of TRecvCallback;
|
||||
MAC : puint8;
|
||||
|
||||
procedure registerType(eType : uint16; RecvCB : TRecvCallback);
|
||||
begin
|
||||
if EthTypes[eType] = nil then EthTypes[eType]:= RecvCB;
|
||||
end;
|
||||
|
||||
procedure recv(p_data : void; p_len : uint16);
|
||||
var
|
||||
src, dst : puint8;
|
||||
proto_type : uint16;
|
||||
|
||||
begin
|
||||
dst:= puint8(p_data);
|
||||
src:= puint8(p_data + 6);
|
||||
console.output('net.eth2', 'DEST: ');
|
||||
writeMACAddress(dst);
|
||||
console.output('net.eth2', 'SRC: ');
|
||||
writeMACAddress(src);
|
||||
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.
|
@ -2,6 +2,50 @@ unit net;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
nettypes;
|
||||
|
||||
procedure registerNetworkCard(SendCallback : TNetSendCallback; _MAC : puint8);
|
||||
procedure registerNextLayer(RecvCallback : TRecvCallback);
|
||||
procedure send(p_data : void; p_len : uint16);
|
||||
procedure recv(p_data : void; p_len : uint16);
|
||||
function getMAC : puint8;
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
CBSend : TNetSendCallback = nil;
|
||||
CBNext : TRecvCallback = nil;
|
||||
MAC : puint8 = nil;
|
||||
|
||||
procedure registerNetworkCard(SendCallback : TNetSendCallback; _MAC : puint8);
|
||||
begin
|
||||
if CBSend = nil then begin
|
||||
CBSend:= SendCallback;
|
||||
MAC:= _MAC;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure registerNextLayer(RecvCallback : TRecvCallback);
|
||||
begin
|
||||
if CBNext = nil then begin
|
||||
CBNext:= RecvCallback;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure send(p_data : void; p_len : uint16);
|
||||
begin
|
||||
CBSend(p_data, p_len);
|
||||
end;
|
||||
|
||||
procedure recv(p_data : void; p_len : uint16);
|
||||
begin
|
||||
CBNext(p_data, p_len);
|
||||
end;
|
||||
|
||||
function getMAC : puint8;
|
||||
begin
|
||||
getMAC:= MAC;
|
||||
end;
|
||||
|
||||
end.
|
29
src/driver/net/nettypes.pas
Normal file
29
src/driver/net/nettypes.pas
Normal file
@ -0,0 +1,29 @@
|
||||
unit nettypes;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
console;
|
||||
|
||||
type
|
||||
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
||||
TRecvCallback = procedure(p_data : void; p_len : uint16);
|
||||
|
||||
procedure writeMACAddress(mac : puint8);
|
||||
|
||||
implementation
|
||||
|
||||
procedure writeMACAddress(mac : puint8);
|
||||
var
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
console.writehexpair(mac[0]);
|
||||
for i:=1 to 5 do begin
|
||||
console.writestring(':');
|
||||
console.writehexpair(mac[i]);
|
||||
end;
|
||||
console.writestringln(' ');
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user