Unit Network

From Ultibo.org
Revision as of 02:37, 27 March 2017 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Network interface unit

To be documented

Constants



Network specific constants NETWORK_*
NETWORK_NAME_PREFIX = 'Network'; Name prefix for Network Devices
 
Generic Network
HARDWARE_DEFAULT:THardwareAddress = ($00,$00,$00,$00,$00,$00);  
HARDWARE_LOOPBACK:THardwareAddress = ($00,$00,$00,$00,$00,$01);  
HARDWARE_BROADCAST:THardwareAddress = ($FF,$FF,$FF,$FF,$FF,$FF);  


Network device type NETWORK_TYPE_*
NETWORK_TYPE_NONE = 0;  
NETWORK_TYPE_ETHERNET = 1;  
NETWORK_TYPE_TOKENRING = 2;  
NETWORK_TYPE_80211 = 3; IEEE 802.11 Wireless (WiFi) network
 
NETWORK_TYPE_MAX = 3;  


Network device state NETWORK_STATE_*
NETWORK_STATE_CLOSED = 0;  
NETWORK_STATE_CLOSING = 1;  
NETWORK_STATE_OPENING = 2;  
NETWORK_STATE_OPEN = 3;  
 
NETWORK_STATE_MAX = 3;  


Network device status NETWORK_STATUS_*
NETWORK_STATUS_DOWN = 0;  
NETWORK_STATUS_UP = 1;  
 
NETWORK_STATUS_MAX = 1;  


Network device flag NETWORK_FLAG_*
NETWORK_FLAG_NONE = $00000000;  
NETWORK_FLAG_RX_BUFFER = $00000001; Device supports Receive Buffer (NetworkBufferReceive/NetworkBufferRelease)
NETWORK_FLAG_TX_BUFFER = $00000002; Device supports Transmit Buffer (NetworkBufferAllocate/NetworkBufferTransmit)


Network device control code NETWORK_CONTROL_*
NETWORK_CONTROL_CLEAR_STATS = 1; Clear Statistics
NETWORK_CONTROL_SET_MAC = 2; Set the MAC for this device
NETWORK_CONTROL_GET_MAC = 3; Get the MAC for this device
NETWORK_CONTROL_SET_LOOPBACK = 4; Set Loopback Mode
NETWORK_CONTROL_RESET = 5; Reset the device
NETWORK_CONTROL_DISABLE = 6; Disable the device
NETWORK_CONTROL_GET_BROADCAST = 8; Get Broadcast address for this device
NETWORK_CONTROL_GET_MTU = 9; Get MTU for this device
NETWORK_CONTROL_GET_HEADERLEN = 10; Get Header length for this device


Network lock state NETWORK_LOCK_*
NETWORK_LOCK_NONE = 0;  
NETWORK_LOCK_READ = 1;  
NETWORK_LOCK_WRITE = 2;  


Network buffer size NETWORK_BUFFER_*
NETWORK_BUFFER_SIZE = 1024;  


Network event NETWORK_EVENT_*
NETWORK_EVENT_NONE = $00000000;  
NETWORK_EVENT_SYSTEM_START = $00000001; The network sub system is starting
NETWORK_EVENT_SYSTEM_STOP = $00000002; The network sub system has stopped
NETWORK_EVENT_ADAPTERS_START = $00000004; All network adapters are being started
NETWORK_EVENT_ADAPTERS_STOP = $00000008; All network adapters have been stopped
NETWORK_EVENT_TRANSPORTS_START = $00000010; All network transports are being started
NETWORK_EVENT_TRANSPORTS_STOP = $00000020; All network transports have been stopped
NETWORK_EVENT_PROTOCOLS_START = $00000040; All network protocols are being started
NETWORK_EVENT_PROTOCOLS_STOP = $00000080; All network protocols have been stopped


Network event signature NETWORK_EVENT_SIGNATURE*
NETWORK_EVENT_SIGNATURE = $BE1D50C2;  


Network event state NETWORK_EVENT_STATE_*
NETWORK_EVENT_STATE_UNREGISTERED = 0;  
NETWORK_EVENT_STATE_REGISTERED = 1;  


Network event flag NETWORK_EVENT_FLAG_*
NETWORK_EVENT_FLAG_NONE = $00000000;  


Adapter type ADAPTER_TYPE_*
ADAPTER_TYPE_UNKNOWN = 0;  
ADAPTER_TYPE_WIRED = 1;  
ADAPTER_TYPE_LOOPBACK = 2;  
ADAPTER_TYPE_WIRELESS = 3;  


Adapter thread ADAPTER_THREAD_*
ADAPTER_THREAD_NAME = 'Network Adapter'; Thread name for Network adapter threads
ADAPTER_THREAD_PRIORITY = THREAD_PRIORITY_HIGHER; Thread priority for Network adapter threads


Adapter state ADAPTER_STATE_*
ADAPTER_STATE_DISABLED = 0;  
ADAPTER_STATE_ENABLED = 1;  


Adapter status ADAPTER_STATUS_*
ADAPTER_STATUS_DOWN = 0;  
ADAPTER_STATUS_UP = 1;  


Configuration type CONFIG_TYPE_*
CONFIG_TYPE_AUTO = 0;  
CONFIG_TYPE_STATIC = 1;  
CONFIG_TYPE_RARP = 2;  
CONFIG_TYPE_BOOTP = 3;  
CONFIG_TYPE_DHCP = 4;  
CONFIG_TYPE_PSEUDO = 5;  
CONFIG_TYPE_LOOPBACK = 6;  
 
CONFIG_TYPE_UNKNOWN = Word(-1);  


Authentication type AUTH_TYPE_*
AUTH_TYPE_UNKNOWN = 0;  
AUTH_TYPE_EAP = 1;  
AUTH_TYPE_RSN = 2;  


Frame type FRAME_TYPE_*
FRAME_TYPE_UNKNOWN = 0;  
FRAME_TYPE_ETHERNET_II = 1; Blue Book
FRAME_TYPE_TOKEN_RING = 3; IEEE 802.5
FRAME_TYPE_APPLETALK = 5; LocalTalk
FRAME_TYPE_ETHERNET_8022 = 11; IEEE 802.2 LLC
FRAME_TYPE_ETHERNET_SNAP = 98; IEEE 802.2 LLC with SNAP Header
FRAME_TYPE_ETHERNET_8023 = 99; 802.3 RAW (Novell)
 
FRAME_START_ETHERNET_SNAP = $AAAA;  
FRAME_START_ETHERNET_8023 = $FFFF;  
 
ADAPTER_MODE_NONE = 1;  
ADAPTER_MODE_LOCAL = 2;  
ADAPTER_MODE_BROADCAST= 3; This is the default
ADAPTER_MODE_LOCAL_MULTI = 4; Mode 3 plus directed Multicast
ADAPTER_MODE_BROADCAST_MULTI = 5; Mode 3 plus all Multicast
ADAPTER_MODE_PROMISCUOUS = 6; Promiscuous mode


Configuration command CONFIG_*
CONFIG_ADAPTER_DISCOVER = 0; Discover an Address from the ConfigHandler
CONFIG_ADAPTER_REQUEST = 1; Request an Address from the ConfigHandler (Either configured or obtained from Discover)
CONFIG_ADAPTER_RELEASE = 2; Release the Address obtained from ConfigHandler
CONFIG_ADAPTER_RENEW = 3; Renew the Address obtained from ConfigHandler
CONFIG_ADAPTER_REBIND = 4; Rebind the Address obtained from ConfigHandler
CONFIG_ADAPTER_INFORM = 5; Obtain information only from the ConfigHandler
CONFIG_ADAPTER_REBOOT = 6; Request previous Address after a Reboot
 
CONFIG_RETRY_TIMEOUT = 300000; 5 min Config Retry Timeout
CONFIG_RENEW_TIMEOUT = 60000; 1 min Config Renew Timeout
CONFIG_REBIND_TIMEOUT = 60000; 1 min Config Rebind Timeout


Authentication command AUTH_COMMAND_*
AUTH_COMMAND_ASSOCIATE = 0;  
AUTH_COMMAND_DISASSOCIATE = 1;  
AUTH_COMMAND_AUTHENTICATE = 2;  
AUTH_COMMAND_UNAUTHENTICATE = 3;  


Multicast addressing MAX_MULTICAST_*
MAX_MULTICAST_ADDRESS = 8; Maximum number of addresses per adapter
 
MAX_PHYSICAL_PACKET = 2048; Large enough for all media types


Hardware addressing HARDWARE_ADDRESS_*
HARDWARE_ADDRESS_SIZE = 6; SizeOf(THardwareAddress)


Media type MEDIA_TYPE_*
MEDIA_TYPE_UNKNOWN = $0000;  
 
MEDIA_TYPE_ETHERNET = $0001; ARP type of Ethernet Hardware (These values must not change, they are the actual values used by ARP packets)
MEDIA_TYPE_TOKENRING = $0006; ARP type of Token-Ring Hardware (These values must not change, they are the actual values used by ARP packets)


Packet type PACKET_TYPE_*
PACKET_MIN_TYPE = $0600; If the value Ethernet header TypeLength field is greater than this the frame is Ethernet II
 
PACKET_TYPE_IP = $0800;  
PACKET_TYPE_IP6 = $86DD;  
PACKET_TYPE_ARP = $0806;  
PACKET_TYPE_RARP = $8035;  
PACKET_TYPE_8021Q = $8100; 802.1Q with extended Ethernet header
PACKET_TYPE_IPX = $8137; IPX on EII
 
PACKET_TYPE_EAPOL = $888E; EAP-over-LAN (EAPOL)
PACKET_TYPE_RSN = $88C7; RSN pre-authentication
PACKET_TYPE_TDLS = $890D; Tunneled direct-link setup
 
PACKET_TYPE_RAW = $FFFF; IPX on 802.3
PACKET_TYPE_LLC = $0001; IPX on 802.2


Ethernet network *_ETHERNET_PACKET
MIN_ETHERNET_PACKET = 60;  
MAX_ETHERNET_PACKET = 1514;  


Ethernet 802.3 network LLC_HEADER_*
FRAME_TYPE_ETHERNET_8022
LLC_HEADER_SIZE = 3; SizeOf(TLLCHeader); Optionally can be 4 if Control is 2 octets


Ethernet SNAP network SNAP_HEADER_*
FRAME_TYPE_ETHERNET_SNAP
SNAP_HEADER_SIZE = 5; SizeOf(TSNAPHeader);


Service set SERVICE_SET_*
SERVICE_SET_UNKNOWN = 0;  
SERVICE_SET_BSS = 1; Basic Service Set
SERVICE_SET_ESS = 2; Extended Service Set
SERVICE_SET_IBSS = 3; Independent Basic Service Set
SERVICE_SET_MBSS = 4; Mesh Basic Service Set


Network logging NETWORK_LOG_*
NETWORK_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; Network debugging messages
NETWORK_LOG_LEVEL_INFO = LOG_LEVEL_INFO; Network informational messages, such as a device being attached or detached
NETWORK_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; Network error messages
NETWORK_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No Network messages


Ethernet specific constants ETHERNET_*
ETHERNET_ADDRESS_SIZE = 6; SizeOf(TEthernetAddress)
ETHERNET_HEADER_SIZE = 14; SizeOf(TEthernetHeader);
ETHERNET_VLAN_SIZE = 4; Length of Ethernet VLAN tag
ETHERNET_CRC_SIZE = 4; Length of Ethernet CRC
 
ETHERNET_DEFAULT:THardwareAddress = ($00,$00,$00,$00,$00,$00);  
ETHERNET_LOOPBACK:THardwareAddress = ($00,$00,$00,$00,$00,$01);  
ETHERNET_BROADCAST:THardwareAddress = ($FF,$FF,$FF,$FF,$FF,$FF);  
ETHERNET_MULTICAST:THardwareAddress = ($01,$00,$5E,$00,$00,$00);  


Ethernet size ETHERNET_*_SIZE*
ETHERNET_MTU = 1500;  
ETHERNET_MAX_PACKET_SIZE = ETHERNET_HEADER_SIZE + ETHERNET_VLAN_SIZE + ETHERNET_MTU;  
 
ETHERNET_TRANSMIT_BUFFER_SIZE = ETHERNET_MAX_PACKET_SIZE;  


Network specific constants
Generic Network
HARDWARE_DEFAULT:THardwareAddress = ($00,$00,$00,$00,$00,$00);  
HARDWARE_LOOPBACK:THardwareAddress = ($00,$00,$00,$00,$00,$01);  
HARDWARE_BROADCAST:THardwareAddress = ($FF,$FF,$FF,$FF,$FF,$FF);  


Type definitions



Hardware address

PHardwareAddress = ^THardwareAddress;

THardwareAddress = array[0..HARDWARE_ADDRESS_SIZE - 1] of Byte;

   

Hardware addresses

PHardwareAddresses = ^THardwareAddresses;

THardwareAddresses = array[0..0] of THardwareAddress;

   

Multicast addresses

PMulticastAddresses = ^TMulticastAddresses;

TMulticastAddresses = array[0..MAX_MULTICAST_ADDRESS - 1] of THardwareAddress;

   

Network packet

PNetworkPacket = ^TNetworkPacket;

TNetworkPacket = record

Buffer:Pointer; Pointer to buffer (Set by driver that owns this packet)
Data:Pointer; Start of data within buffer (Set by driver that owns this packet)
Length:LongInt; Length of packet data (Set by driver on Receive / Set by caller on Transmit, contains maximum length on Allocate)
Flags:LongWord; Packet specific flags (eg Error, Broadcast etc) (Dependent on network type)

Network Buffer

PNetworkBuffer = ^TNetworkBuffer;

TNetworkBuffer = record

Wait:TSemaphoreHandle; Packet ready semaphore
Start:LongWord; Index of first packet ready
Count:LongWord; Number of packets ready in buffer
Packets:array[0..(NETWORK_BUFFER_SIZE - 1)] of PNetworkPacket;  

Network entry

PNetworkEntry = ^TNetworkEntry;

TNetworkEntry = record

Buffer:Pointer; Pointer to buffer (Allocated by driver that owns this entry)
Size:LongWord; Size of the buffer (Total size, usable size is Size minus Offset)
Offset:LongWord; Offset to start of data (Data for first packet will be at Buffer plus Offset, must be less than size)
Count:LongWord; Number of packets in the entry (Set by driver that owns this entry, must be at least one)
DriverData:Pointer; Driver private data (Managed by driver that owns this entry)
Packets:array of TNetworkPacket; {Array of 0 to Count - 1 packets in this entry Allocated by driver that owns this entry, must be at least one)

Network queue

PNetworkQueue = ^TNetworkQueue;

TNetworkQueue = record

Buffer:TBufferHandle; Handle for entry buffers
Wait:TSemaphoreHandle; Entry ready semaphore
Start:LongWord; Index of first entry ready
Count:LongWord; Number of entries ready in queue
Flags:LongWord; Queue specific flags (eg Paused, Halted etc) (Managed by driver)
Entries:array of PNetworkEntry; Array of 0 to Total - 1 entries in this queue (Allocated by driver that owns this queue)

Network enumeration callback

TNetworkEnumerate = function(Network:PNetworkDevice; Data:Pointer):LongWord;

Network notification callback

TNetworkNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

Network device open

TNetworkDeviceOpen = function(Network:PNetworkDevice):LongWord;

Network device close

TNetworkDeviceClose = function(Network:PNetworkDevice):LongWord;

Network device read

TNetworkDeviceRead = function(Network:PNetworkDevice; Buffer:Pointer; Size:LongWord; var Length:LongWord):LongWord;

Network device write

TNetworkDeviceWrite = function(Network:PNetworkDevice; Buffer:Pointer; Size:LongWord; var Length:LongWord):LongWord;

Network device control

TNetworkDeviceControl = function(Network:PNetworkDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;

Network buffer allocate

TNetworkBufferAllocate = function(Network:PNetworkDevice; var Entry:PNetworkEntry):LongWord;

Network buffer release

TNetworkBufferRelease = function(Network:PNetworkDevice; Entry:PNetworkEntry):LongWord;

Network buffer receive

TNetworkBufferReceive = function(Network:PNetworkDevice; var Entry:PNetworkEntry):LongWord;

Network buffer transmit

TNetworkBufferTransmit = function(Network:PNetworkDevice; Entry:PNetworkEntry):LongWord;

Network device types

PNetworkDevice = ^TNetworkDevice;

TNetworkDevice = record

Device Properties
Device:TDevice; The Device entry for this Network
Network Properties
NetworkId:LongWord; Unique Id of this Network in the Network table
NetworkState:LongWord; Network state (eg NETWORK_STATE_OPEN)
NetworkStatus:LongWord; Network status (eg NETWORK_STATUS_UP)
DeviceOpen:TNetworkDeviceOpen; A Device specific DeviceOpen method implementing a standard Network device interface
DeviceClose:TNetworkDeviceClose; A Device specific DeviceClose method implementing a standard Network device interface
DeviceRead:TNetworkDeviceRead; A Device specific DeviceRead method implementing a standard Network device interface
DeviceWrite:TNetworkDeviceWrite; A Device specific DeviceWrite method implementing a standard Network device interface
DeviceControl:TNetworkDeviceControl; A Device specific DeviceControl method implementing a standard Network device interface
BufferAllocate:TNetworkBufferAllocate; A Device specific BufferAllocate method implementing a standard Network device interface
BufferRelease:TNetworkBufferRelease; A Device specific BufferRelease method implementing a standard Network device interface
BufferReceive:TNetworkBufferReceive; A Device specific BufferReceive method implementing a standard Network device interface
BufferTransmit:TNetworkBufferTransmit; A Device specific BufferTransmit method implementing a standard Network device interface
Driver Properties
Lock:TMutexHandle; Network lock
Buffer:TNetworkBuffer; Network receive buffer
TransmitWait:TSemaphoreHandle; Transmit complete semaphore
ReceiveBuffer:TBufferHandle; Buffer for receive packets
TransmitBuffer:TBufferHandle; Buffer for transmit packets
 
ReceiveQueue:TNetworkQueue; Queue for receive packets
TransmitQueue:TNetworkQueue; Queue for transmit packets (If applicable)
Statistics Properties
ReceiveCount:LongWord;  
ReceiveErrors:LongWord;  
TransmitCount:LongWord;  
TransmitErrors:LongWord;  
BufferOverruns:LongWord;  
BufferUnavailable:LongWord;  
Internal Properties
Prev:PNetworkDevice; Previous entry in Network table
Next:PNetworkDevice; Next entry in Network table

Network event callback

TNetworkEventCallback = function(Data:Pointer; Event:LongWord):LongWord;

Network Event

PNetworkEvent = ^TNetworkEvent;

TNetworkEvent = record

Event Properties
Signature:LongWord; Signature for entry validation
EventState:LongWord; Event state (eg Registered/Unregistered)
EventFlags:LongWord; Event flags (eg NETWORK_EVENT_FLAG_NONE)
Callback:TNetworkEventCallback; The callback for network events
Data:Pointer; A pointer to callback specific data to be passed with events (Optional)
Event:LongWord; The mask of events to notify on (eg NETWORK_EVENT_SYSTEM_START etc)
Internal Properties
Prev:PNetworkEvent; Previous entry in Event table
Next:PNetworkEvent; Next entry in Event table

Packet fragment

PPacketFragment = ^TPacketFragment;

TPacketFragment = packed record

Size:Integer;  
Data:Pointer;  
Next:PPacketFragment;  

Ethernet 802.3 network

PLLCHeader = ^TLLCHeader;

TLLCHeader = packed record

Note: FRAME_TYPE_ETHERNET_8022
DSAP:Byte;  
SSAP:Byte;  
Control:Byte;  
Information:array[0..0] of Byte; Optional (Control byte can be 1 or 2 octets)

Ethernet SNAP network

PSNAPHeader = ^TSNAPHeader;

TSNAPHeader = packed record

Note: FRAME_TYPE_ETHERNET_SNAP
OUI:array[0..2] of Byte;  
ProtocolID:Word;  
Data:array[0..0] of Byte; Not part of header, included to provide a pointer to the start of data

Token ring network

PTokenRingAddress = ^TTokenRingAddress;

TTokenRingAddress = array[0..5] of Byte;

   

Token ring header

PTokenRingHeader = ^TTokenRingHeader;

TTokenRingHeader = packed record

   

Adapter params

PAdapterParams = ^TAdapterParams;

TAdapterParams = packed record

Version:Word; Driver version
FrameType:Byte; Driver class
AdapterType:Word; Driver type
Number:Byte; Driver number
Name:PChar; Driver name
Functionality:Byte; How good is this driver

Network params

PNetworkParams = ^TNetworkParams;

TNetworkParams = packed record

MajorRevision:Byte; Major revision ID of packet specs
MinorRevision:Byte; Minor revision ID of packet specs
ParamLength:Byte; Length of structure in Bytes
AddressLength:Byte; Length of a MAC address
MTU:Word; MTU, including MAC headers
MulticastAvailable:Word; buffer size for multicast addr.
RxBuffers:Word; No of back-to-back MTU rcvs) - 1
TxBuffers:Word; No of successive xmits) - 1
IntNo:Word; Interrupt No to hook for post-EOI processing, 0 = none

Adapter statistics

PAdapterStatistics = ^TAdapterStatistics;

TAdapterStatistics = record

PacketsIn:Int64;  
PacketsOut:Int64;  
BytesIn:Int64;  
BytesOut:Int64;  
ErrorsIn:Int64;  
ErrorsOut:Int64;  
PacketsLost:Int64;  

Ethernet address

PEthernetAddress = ^TEthernetAddress;

TEthernetAddress = array[0..ETHERNET_ADDRESS_SIZE - 1] of Byte;

   

Ethernet header

PEthernetHeader = ^TEthernetHeader;

TEthernetHeader = packed record

DestAddress:THardwareAddress;  
SourceAddress:THardwareAddress;  
TypeLength:Word; Length or Type (IEEE 802.3 or BlueBook/DIX Ethernet)
Data:array[0..0] of Byte; Not part of header, included to provide a pointer to the start of data

Adapter callback

TAdapterCallback = function(AAdapter:TNetworkAdapter):Boolean of object;

Adapter packet handler

TAdapterPacketHandler = function(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean of object;

Adapter monitor handler

TAdapterMonitorHandler = function(AHandle:THandle; APacket:Pointer; ASize:Integer; AStatus:Pointer):Boolean of object;

Adapter authenticator handler

TAdapterAuthenticatorHandler = function(AHandle:THandle; ACommand:Word):Boolean of object;


Class definitions



Adapter manager

TAdapterManager = class(TObject)

constructor Create(ASettings:TNetworkSettings);  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
FSettings:TNetworkSettings;  
 
FAdapters:TNetworkList; List of TNetworkAdapter objects
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
public
property Settings:TNetworkSettings read FSettings;  
 
function AddAdapter(AAdapter:TNetworkAdapter):Boolean;  
function RemoveAdapter(AAdapter:TNetworkAdapter):Boolean;  
 
function GetAdapterByType(AAdapterType:Word; ALock:Boolean; AState:LongWord):TNetworkAdapter;  
function GetAdapterByDevice(ADevice:PNetworkDevice; ALock:Boolean; AState:LongWord):TNetworkAdapter;  
function GetAdapterByAdapter(AAdapter:TNetworkAdapter; ALock:Boolean; AState:LongWord):TNetworkAdapter;  
function GetAdapterByNext(APrevious:TNetworkAdapter; ALock,AUnlock:Boolean; AState:LongWord):TNetworkAdapter;  
 
function StartAdapters:Boolean;  
function StopAdapters:Boolean;  
function ProcessStatus:Boolean;  
function ProcessAdapters:Boolean;  
 
function EnumerateAdapters(ACallback:TAdapterCallback):Boolean;  

Adapter transport

TAdapterTransport = class(TListObject)

Note: Upstream
 
constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
public
FrameType:Word;  
PacketType:Word;  
PacketName:String;  
PacketHandler:TAdapterPacketHandler;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  

Adapter binding

TAdapterBinding = class(TListObject)

Note: Upstream
 
constructor Create(ATransport:TAdapterTransport);  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
public
FrameType:Word;  
PacketType:Word;  
Transport:TAdapterTransport;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  

Adapter monitor

TAdapterMonitor = class(TListObject)

Note: Upstream
 
constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
public
MonitorHandler:TAdapterMonitorHandler;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  

Adapter authenticator

TAdapterAuthenticator = class(TListObject)

Note: Upstream
 
constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
public
AuthType:Word; EAP/RSN
AuthenticatorHandler:TAdapterAuthenticatorHandler;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  

Network list

TNetworkList = class(TLinkedObjList)

constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
public
procedure ClearList;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function ReaderConvert:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
function WriterConvert:Boolean;  

Network adapter

TNetworkAdapter = class(TListObject)

constructor Create(AManager:TAdapterManager; ADevice:PNetworkDevice; const AName:String);  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
protected
FManager:TAdapterManager;  
FDevice:PNetworkDevice;  
FName:String;  
 
FState:Integer;  
FStatus:Integer;  
FMediaType:Word; Physical Media type (Ethernet/Tokenring etc)
FAdapterType:Word;  
FLastError:Integer;  
FThread:TAdapterThread; Thread for adapter receiving
FBindings:TNetworkList; List of TAdapterBinding objects
FTransports:TNetworkList; List of TAdapterTransport objects
FMonitors:TNetworkList; List of TAdapterMonitor objects
FAuthenticators:TNetworkList; List of TAdapterAuthenticator objects
 
FStatistics:TAdapterStatistics;  
 
function GetThreadID:TThreadID;  
 
function GetTransportByHandle(AHandle:THandle; ALock:Boolean; AState:LongWord):TAdapterTransport;  
function GetTransportByType(APacketType,AFrameType:Word; ALock:Boolean; AState:LongWord):TAdapterTransport;  
function GetTransportByTransport(ATransport:TAdapterTransport; ALock:Boolean; AState:LongWord):TAdapterTransport;  
function GetTransportByNext(APrevious:TAdapterTransport; ALock,AUnlock:Boolean; AState:LongWord):TAdapterTransport;  
 
function GetBindingByHandle(AHandle:THandle; ALock:Boolean; AState:LongWord):TAdapterBinding;  
function GetBindingByType(ATransport:TAdapterTransport; APacketType,AFrameType:Word; ALock:Boolean; AState:LongWord):TAdapterBinding;  
function GetBindingByTransport(ATransport:TAdapterTransport; ALock:Boolean; AState:LongWord):TAdapterBinding;  
function GetBindingByBinding(ABinding:TAdapterBinding; ALock:Boolean; AState:LongWord):TAdapterBinding;  
function GetBindingByNext(APrevious:TAdapterBinding; ALock,AUnlock:Boolean; AState:LongWord):TAdapterBinding;  
 
function GetMonitorByHandle(AHandle:THandle; ALock:Boolean; AState:LongWord):TAdapterMonitor;  
function GetMonitorByMonitor(AMonitor:TAdapterMonitor; ALock:Boolean; AState:LongWord):TAdapterMonitor;  
function GetMonitorByNext(APrevious:TAdapterMonitor; ALock,AUnlock:Boolean; AState:LongWord):TAdapterMonitor;  
 
function GetAuthenticatorByHandle(AHandle:THandle; ALock:Boolean; AState:LongWord):TAdapterAuthenticator;  
function GetAuthenticatorByType(AAuthType:Word; ALock:Boolean; AState:LongWord):TAdapterAuthenticator;  
function GetAuthenticatorByAuthenticator(AAuthenticator:TAdapterAuthenticator; ALock:Boolean; AState:LongWord):TAdapterAuthenticator;  
function GetAuthenticatorByNext(APrevious:TAdapterAuthenticator; ALock,AUnlock:Boolean; AState:LongWord):TAdapterAuthenticator;  
 
function AddBinding(ATransport:TAdapterTransport; APacketType,AFrameType:Word):THandle; virtual;  
function RemoveBinding(AHandle:THandle; APacketType:Word):Boolean; virtual;  
public
property Manager:TAdapterManager read FManager;  
property Device:PNetworkDevice read FDevice;  
property Name:String read FName;  
 
property State:Integer read FState;  
property Status:Integer read FStatus;  
property MediaType:Word read FMediaType;  
property AdapterType:Word read FAdapterType;  
property LastError:Integer read FLastError;  
property ThreadID:TThreadID read GetThreadID;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
 
function AddTransport(APacketType,AFrameType:Word; const APacketName:String; APacketHandler:TAdapterPacketHandler):THandle; virtual;  
function RemoveTransport(AHandle:THandle; APacketType:Word):Boolean; virtual;  
 
function AddMonitor(AMonitorHandler:TAdapterMonitorHandler):THandle; virtual;  
function RemoveMonitor(AHandle:THandle):Boolean; virtual;  
 
function AddAuthenticator(AAuthType:Word; AAuthenticatorHandler:TAdapterAuthenticatorHandler):THandle; virtual;  
function RemoveAuthenticator(AHandle:THandle; AAuthType:Word):Boolean; virtual;  
 
function GetMTU(AHandle:THandle):Word; virtual;  
 
function SendPacket(AHandle:THandle; ADest:Pointer; APacket:PPacketFragment; ASize:Integer):Boolean; virtual;  
 
function ResetInterface(AHandle:THandle):Boolean; virtual;  
function TerminateDriver(AHandle:THandle):Boolean; virtual;  
 
function GetReceiveMode(AHandle:THandle):Word; virtual;  
function SetReceiveMode(AHandle:THandle; AMode:Word):Boolean; virtual;  
 
function GetAdapterParams(AHandle:THandle):TAdapterParams; virtual;  
function GetNetworkParams(AHandle:THandle):TNetworkParams; virtual;  
function GetStatistics(AHandle:THandle):TAdapterStatistics; virtual;  
 
function GetDefaultAddress(AHandle:THandle):THardwareAddress; virtual;  
function GetHardwareAddress(AHandle:THandle):THardwareAddress; virtual;  
function SetHardwareAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
function GetBroadcastAddress(AHandle:THandle):THardwareAddress; virtual;  
function GetMulticastAddresses(AHandle:THandle):TMulticastAddresses; virtual;  
 ;
function AddMulticastAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
function RemoveMulticastAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
 
function StartAdapter:Boolean; virtual;  
function StopAdapter:Boolean; virtual;  
function ProcessStatus:Boolean; virtual;  
function ProcessAdapter:Boolean; virtual;  
 
function CompareAddress(const AAddress1,AAddress2:THardwareAddress):Boolean; virtual;  
function CompareDefault(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
function CompareHardware(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
function CompareBroadcast(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  
function CompareMulticast(AHandle:THandle; const AAddress:THardwareAddress):Boolean; virtual;  

Adapter thread

TAdapterThread = class(TThread)

constructor Create(AAdapter:TNetworkAdapter);  
protected
FAdapter:TNetworkAdapter;  
 
procedure Execute; override;  
public
function SendHandle(AHandle:THandle):Boolean;  
function ReceiveHandle:THandle;  

Adapter buffer

TAdapterBuffer = class(TObject)

Note: Ring buffer for Packets.
 
constructor Create;  
destructor Destroy; override;  
private
FLock:TCriticalSectionHandle;  
protected
FSize:Integer;  
FCount:Integer;  
FNextRead:Integer;  
FNextWrite:Integer;  
 
FList:TList;  
FMemory:TMemoryStream;  
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
 
procedure SetSize(ASize:Integer);  
public
property Size:Integer read FSize write SetSize;  
 
function ReadNext:Pointer;  
function WriteNext:Pointer;  

Wired adapter

TWiredAdapter = class(TNetworkAdapter)

constructor Create(AManager:TAdapterManager; ADevice:PNetworkDevice; const AName:String);  
private
FDefaultAddress:THardwareAddress;  
FHardwareAddress:THardwareAddress;  
FBroadcastAddress:THardwareAddress;  
FMulticastAddresses:TMulticastAddresses;  
public
function AddTransport(APacketType,AFrameType:Word; const APacketName:String; APacketHandler:TAdapterPacketHandler):THandle; override;  
function RemoveTransport(AHandle:THandle; APacketType:Word):Boolean; override;  
 
function GetMTU(AHandle:THandle):Word; override;  
 
function SendPacket(AHandle:THandle; ADest:Pointer; APacket:PPacketFragment; ASize:Integer):Boolean; override;  
 
function GetDefaultAddress(AHandle:THandle):THardwareAddress; override;  
function GetHardwareAddress(AHandle:THandle):THardwareAddress; override;  
function SetHardwareAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; override;  
function GetBroadcastAddress(AHandle:THandle):THardwareAddress; override;  
function GetMulticastAddresses(AHandle:THandle):TMulticastAddresses; override;  
 
function AddMulticastAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; override;  
function RemoveMulticastAddress(AHandle:THandle; const AAddress:THardwareAddress):Boolean; override;  
 
function StartAdapter:Boolean; override;  
function StopAdapter:Boolean; override;  
function ProcessAdapter:Boolean; override;  

Network setting

TNetworkSetting = class(TListObject)

private
FName:String;  
FValue:String;  
 
FHash:LongWord;  
 
procedure SetName(const AName:String);  
public
property Name:String read FName write SetName;  
property Value:String read FValue write FValue;  
 
property Hash:LongWord read FHash;  

Network settings

TNetworkSettings = class(TObject)

constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
FLocalLock:TMutexHandle;  
 
FHostName:String;  
FDomainName:String;  
FList:TLinkedObjList;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
 
function GetHostName:String;  
procedure SetHostName(const AHostName:String);  
 
function GetDomainName:String;  
procedure SetDomainName(const ADomainName:String);  
 
function ExtractName(const AValue,AToken:String):String;  
function ExtractValue(const AValue,AToken:String):String;  
function ExtractPrefix(const AValue:String):String;  
 
function SplitName(const AName:String):String;  
function SplitPrefix(const AName:String):String;  
 
function MergePrefix(const APrefix,AName:String):String;  
 
function TranslateString(const AValue,ADefault:String):String;  
function TranslateInteger(const AValue:String; ADefault:Integer):Integer;  
function TranslateBoolean(const AValue:String; ADefault:Boolean):Boolean;  
 
function GetFromList(const AName:String):TNetworkSetting;  
 
function FindFromList(const AName:String):String;  
function FindFromEnvironment(const AName:String):String;  
public
property HostName:String read GetHostName write SetHostName;  
property DomainName:String read GetDomainName write SetDomainName;  
 
function GetString(const AName:String):String;  
function GetStringDefault(const AName,ADefault:String):String;  
 
function GetInteger(const AName:String):Integer;  
function GetIntegerDefault(const AName:String; ADefault:Integer):Integer;  
 
function GetBoolean(const AName:String):Boolean;  
function GetBooleanDefault(const AName:String; ADefault:Boolean):Boolean;  
 
function AddString(const AName,AValue:String):Boolean;  
function AddInteger(const AName:String; AValue:Integer):Boolean;  
function AddBoolean(const AName:String; AValue:Boolean):Boolean;  
 
function Remove(const AName:String):Boolean;  
 
function LoadFromFile(const AFileName:String; AFlat:Boolean):Boolean;  
function LoadFromStream(AStream:TStream; AFlat:Boolean):Boolean;  
function LoadFromStrings(AStrings:TStrings; AFlat:Boolean):Boolean;  
 
function SaveToFile(const AFileName:String; AFlat:Boolean):Boolean;  
function SaveToStream(AStream:TStream; AFlat:Boolean):Boolean;  
function SaveToStrings(AStrings:TStrings; AFlat:Boolean):Boolean;  
 
function LoadFromEnvironment:Boolean;  

Service set

TServiceSet = class(TListObject)

constructor Create;  
destructor Destroy; override;  
private
FLock:TSynchronizerHandle;  
FLocalLock:TMutexHandle;  
 
function GetName:String;  
procedure SetName(const AName:String);  
procedure SetServiceSetType(AServiceSetType:LongWord);  
procedure SetServiceSetTime(const AServiceSetTime:Int64);  
procedure SetAddress(const AAddress:THardwareAddress);  
procedure SetAdapter(AAdapter:TNetworkAdapter);  
protected
FName:String;  
FServiceSetType:LongWord; BSS/ESS/IBSS
FServiceSetTime:Int64; Flush time
FAddress:THardwareAddress; Address of service set
FAdapter:TNetworkAdapter;  
 
function AcquireLock:Boolean;  
function ReleaseLock:Boolean;  
public
property Name:String read GetName write SetName;  
property ServiceSetType:LongWord read FServiceSetType write SetServiceSetType;  
property ServiceSetTime:Int64 read FServiceSetTime write SetServiceSetTime;  
property Address:THardwareAddress read FAddress write SetAddress;  
property Adapter:TNetworkAdapter read FAdapter write SetAdapter;  
 
function ReaderLock:Boolean;  
function ReaderUnlock:Boolean;  
function ReaderConvert:Boolean;  
function WriterLock:Boolean;  
function WriterUnlock:Boolean;  
function WriterConvert:Boolean;  


Public variables



Network logging

NETWORK_DEFAULT_LOG_LEVEL:LongWord = NETWORK_LOG_LEVEL_DEBUG; Minimum level for Network messages. Only messages with level greater than or equal to this will be printed.
NETWORK_LOG_ENABLED:Boolean;


Function declarations


Initialization functions

procedure NetworkInit;
Description: To be documented
Note To be documented


function NetworkStart:LongWord;
Description: To be documented
Note None documented


function NetworkStop:LongWord;
Description: To be documented
Note None documented


function NetworkStartCompleted:Boolean;
Description: To be documented
Return Returns True if the network sub system has been started


Network functions

function NetworkDeviceOpen(Network:PNetworkDevice):LongWord;
Description: To be documented
Note None documented


function NetworkDeviceClose(Network:PNetworkDevice):LongWord;
Description: To be documented
Note None documented


function NetworkDeviceRead(Network:PNetworkDevice; Buffer:Pointer; Size:LongWord; var Length:LongWord):LongWord;
Description: To be documented
Note None documented


function NetworkDeviceWrite(Network:PNetworkDevice; Buffer:Pointer; Size:LongWord; var Length:LongWord):LongWord;
Description: To be documented
Note None documented


function NetworkDeviceControl(Network:PNetworkDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: To be documented
Note None documented


function NetworkBufferAllocate(Network:PNetworkDevice; var Entry:PNetworkEntry):LongWord;
Description: Allocate a transmit buffer from the specified network device, the returned entry will include a buffer for writing data to as well as an offfset value to allow the driver data to be written to the start of the buffer. When the data has been copied to the buffer, pass the entry to NetworkBufferTransmit.
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkBufferRelease(Network:PNetworkDevice; Entry:PNetworkEntry):LongWord;
Description: Release a receive buffer to the specified network device, the entry must have been returned from NetworkBufferReceive
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkBufferReceive(Network:PNetworkDevice; var Entry:PNetworkEntry):LongWord;
Description: Receive a completed receive buffer from the specified network device. The returned entry will contain a one or more packets of data to read from. When the data has been processed pass the returned buffer to NetworkBufferRelease.
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkBufferTransmit(Network:PNetworkDevice; Entry:PNetworkEntry):LongWord;
Description: Transmit a completed transmit buffer to the specified network device. The entry must have been allocated using NetworkBufferAllocate.
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkDeviceSetState(Network:PNetworkDevice; State:LongWord):LongWord;
Description: Set the state of the specified network and send a notification
Network The network to set the state for
State The new state to set and notify
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkDeviceSetStatus(Network:PNetworkDevice; Status:LongWord):LongWord;
Description: Set the status of the specified network and send a notification
Network The network to set the status for
Status The new status to set and notify
Return ERROR_SUCCESS if completed or another error code on failure


function NetworkDeviceCreate:PNetworkDevice;
Description: Create a new Network entry
Return Pointer to new Network entry or nil if network could not be created


function NetworkDeviceCreateEx(Size:LongWord):PNetworkDevice;
Description: Create a new Network entry
Size Size in bytes to allocate for new network (Including the network entry)
Return Pointer to new Network entry or nil if network could not be created


function NetworkDeviceDestroy(Network:PNetworkDevice):LongWord;
Description: Destroy an existing Network entry
Note None documented


function NetworkDeviceRegister(Network:PNetworkDevice):LongWord;
Description: Register a new Network in the Network table
Note None documented


function NetworkDeviceDeregister(Network:PNetworkDevice):LongWord;
Description: Deregister a Network from the Network table
Note None documented


function NetworkDeviceFind(NetworkId:LongWord):PNetworkDevice;
Description: To be documented
Note None documented


function NetworkDeviceFindByName(const Name:String):PNetworkDevice; inline;
Description: To be documented
Note None documented


function NetworkDeviceFindByDescription(const Description:String):PNetworkDevice; inline;
Description: To be documented
Note None documented


function NetworkDeviceEnumerate(Callback:TNetworkEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function NetworkDeviceNotification(Network:PNetworkDevice; Callback:TNetworkNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


function NetworkEventAllocate(Callback:TNetworkEventCallback; Data:Pointer; Event:LongWord):PNetworkEvent;
Description: Create and Register a new Event entry in the Event table
Note None documented


function NetworkEventRelease(Event:PNetworkEvent):LongWord;
Description: Deregister and Destroy a Event from the Event table
Note None documented


function NetworkEventRegister(Callback:TNetworkEventCallback; Data:Pointer; Event:LongWord):THandle;
Description: Register a callback for one or more network events
Note None documented


function NetworkEventDeregister(Handle:THandle):LongWord;
Description: Deregister a network event callback
Note None documented


function NetworkEventNotify(Event:LongWord):LongWord;
Description: To be documented
Note None documented


RTL network functions

function SysHostGetName:String;
Description: To be documented
Note None documented


function SysHostSetName(const AName:String):Boolean;
Description: To be documented
Note None documented


function SysHostGetDomain:String;
Description: To be documented
Note None documented


function SysHostSetDomain(const ADomain:String):Boolean;
Description: To be documented
Note None documented


Network helper functions

function NetworkGetCount:LongWord; inline;
Description: Get the current network count
Note None documented


function NetworkDeviceCheck(Network:PNetworkDevice):PNetworkDevice;
Description: Check if the supplied Network is in the network table
Note None documented


function NetworkDeviceTypeToString(NetworkType:LongWord):String;
Description: To be documented
Note None documented


function NetworkDeviceStateToString(NetworkState:LongWord):String;
Description: To be documented
Note None documented


function NetworkDeviceStatusToString(NetworkStatus:LongWord):String;
Description: To be documented
Note None documented


function NetworkDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Network state value into the notification code for device notifications
Note None documented


function NetworkDeviceStatusToNotification(Status:LongWord):LongWord;
Description: Convert a Network status value into the notification code for device notifications
Note None documented


function NetworkEventCheck(Event:PNetworkEvent):PNetworkEvent;
Description: Check if the supplied Event is in the event table
Note None documented


procedure NetworkLog(Level:LongWord; Network:PNetworkDevice; const AText:String);
Description: To be documented
Note None documented


procedure NetworkLogInfo(Network:PNetworkDevice; const AText:String);
Description: To be documented
Note None documented


procedure NetworkLogError(Network:PNetworkDevice; const AText:String);
Description: To be documented
Note None documented


procedure NetworkLogDebug(Network:PNetworkDevice; const AText:String);
Description: To be documented
Note None documented


function HardwareAddressToString(const AAddress:THardwareAddress):String;
Description: To be documented
Note None documented


function StringToHardwareAddress(const AAddress:String):THardwareAddress;
Description: To be documented
Note None documented


function CompareHardwareAddress(const AAddress1,AAddress2:THardwareAddress):Boolean;
Description: To be documented
Note None documented


function CompareHardwareDefault(const AAddress:THardwareAddress):Boolean;
Description: To be documented
Note None documented


function CompareHardwareBroadcast(const AAddress:THardwareAddress):Boolean;
Description: To be documented
Note None documented


function CompareHardwareMulticast(const AAddress:THardwareAddress):Boolean;
Description: To be documented
Note None documented


function AdapterTypeToString(AType:Word):String;
Description: To be documented
Note None documented


function AdapterModeToString(AMode:Word):String;
Description: To be documented
Note None documented


function AdapterConfigToString(AConfig:Word):String;
Description: To be documented
Note None documented


function AdapterStateToString(AState:Integer):String;
Description: To be documented
Note None documented


function AdapterStatusToString(AStatus:Integer):String;
Description: To be documented
Note None documented


function FrameTypeToString(AType:Word):String;
Description: To be documented
Note None documented


function MediaTypeToString(AType:Word):String;
Description: To be documented
Note None documented


function PacketTypetoString(AType:Word):String;
Description: To be documented
Note None documented


function ConfigTypeToString(AType:Word):String;
Description: To be documented
Note None documented


function ConfigCommandToString(ACommand:Word):String;
Description: To be documented
Note None documented


function AuthTypeToString(AType:Word):String;
Description: To be documented
Note None documented


function AuthCommandToString(ACommand:Word):String;
Description: To be documented
Note None documented


Return to Unit Reference