#ifndef __ARP_DXE_H__
#define __ARP_DXE_H__
#include "../uefi_headers/Uefi.h"
/* ================================================================
* ArpDxe -- ARP (Address Resolution Protocol) UEFI Driver
* Source: AmiNetworkPkg/UefiNetworkStack/Common/ArpDxe/
* Files: ArpDriver.c, ArpImpl.c, ArpMain.c
* ================================================================
*
* Implements:
* - EFI_ARP_SERVICE_BINDING_PROTOCOL
* - EFI_ARP_PROTOCOL
* - ARP cache management (add/find/delete/flush)
* - ARP frame Tx/Rx (request/reply)
* - Timer-based cache aging
*/
/* ------------------------------------------------------------------ */
/* Signatures */
/* ------------------------------------------------------------------ */
#define ARP_SERVICE_SIGNATURE 0x53505241 /* 'ARPS' */
#define ARP_INSTANCE_SIGNATURE 0x49505241 /* 'ARPI' */
/* ------------------------------------------------------------------ */
/* ARP Service */
/* ------------------------------------------------------------------ */
typedef struct _ARP_SERVICE ARP_SERVICE;
struct _ARP_SERVICE {
UINT32 Signature; /* 0x00: ARPS */
EFI_SERVICE_BINDING_CREATE_CHILD ArpCreateChild;
EFI_SERVICE_BINDING_DESTROY_CHILD ArpDestroyChild;
EFI_HANDLE ServiceHandle; /* 0x18 */
EFI_HANDLE ControllerHandle; /* 0x20 */
EFI_HANDLE ImageHandle; /* 0x28 */
VOID *MnpProtocol; /* 0x30: Managed Network Protocol */
EFI_HANDLE MnpChildHandle; /* 0x38 */
UINT32 ArpFrameType; /* 0x40: e.g. 0x0800 */
UINT32 ArpTimeoutValue; /* 0x44 */
UINT32 ArpRetryCount; /* 0x48 */
UINT32 ArpCacheTimeout; /* 0x4C */
BOOLEAN Enable; /* 0x50 */
EFI_EVENT TimerEvent; /* 0x58 */
UINT8 RxToken[8]; /* 0x68 */
EFI_EVENT RxEvent; /* 0x80 */
LIST_ENTRY ChildrenList; /* 0x300: head of ARP_INSTANCE list */
LIST_ENTRY PendingCacheList; /* 0x310: unresolved cache entries */
LIST_ENTRY DeniedCacheList; /* 0x320: denied cache entries */
LIST_ENTRY UsedCacheList; /* 0x330: used cache entries */
UINT64 InstanceCount; /* 0x340 */
};
/* ------------------------------------------------------------------ */
/* ARP Instance */
/* ------------------------------------------------------------------ */
typedef struct _ARP_INSTANCE ARP_INSTANCE;
struct _ARP_INSTANCE {
UINT32 Signature; /* 0x00: ARPI */
ARP_SERVICE *ArpService; /* 0x08: back-pointer */
EFI_HANDLE Handle; /* 0x10 */
EFI_ARP_PROTOCOL ArpProto; /* 0x18: 7 function pointers (56 bytes) */
LIST_ENTRY UserRequestList; /* 0x50: pending user requests */
VOID *StationAddress; /* 0x60: allocated address buffer */
UINT16 StationAddressType; /* 0x68: e.g. 0x0800 for IPv4 */
UINT8 StationAddressLength; /* 0x6A: e.g. 4 for IPv4 */
UINT8 Pad; /* 0x6B: padding */
UINT32 SwAddressTimeout; /* 0x6C: timeout for address resolution */
UINT32 SwRetryCount; /* 0x70 */
UINT32 SwRetryTimeout; /* 0x74 */
UINT8 Configured; /* 0x78: flag */
UINT8 DestroyPending; /* 0x79: flag */
};
/* ------------------------------------------------------------------ */
/* ARP Cache Entry */
/* ------------------------------------------------------------------ */
typedef struct _ARP_CACHE_ENTRY ARP_CACHE_ENTRY;
struct _ARP_CACHE_ENTRY {
LIST_ENTRY Link; /* 0x00 */
UINT32 RetryCount; /* 0x10 */
UINT32 ResolvedCount; /* 0x14 */
UINT32 DefaultTimeout; /* 0x18 */
UINT32 RetryTimeout; /* 0x1C */
UINT32 NextRetryTimeout; /* 0x20 */
LIST_ENTRY UserRequestList; /* 0x28: queued requests */
UINT8 HardwareAddress[12]; /* 0x40: resolved MAC (variable) */
UINT8 HwAddrLength; /* 0x4C */
/* Address pairs (hw + protocol) follow */
/* 6*2 entries; each: type(2)+len(1)+pad(1)+addr_ptr(8) = 12 bytes */
UINT64 AddressPairData[12]; /* 0x50: two 12-byte address descriptors */
};
/* ------------------------------------------------------------------ */
/* NET_MAP (from DxeNetLib) */
/* ------------------------------------------------------------------ */
typedef struct _NET_MAP_ITEM NET_MAP_ITEM;
struct _NET_MAP_ITEM {
LIST_ENTRY Link; /* 0x00 */
VOID *Key; /* 0x10: cache entry pointer */
VOID *Value; /* 0x18: list owner pointer */
};
typedef struct {
LIST_ENTRY Used; /* 0x00 */
LIST_ENTRY Recycled; /* 0x10 */
UINT32 Count; /* 0x20 */
} NET_MAP;
/* ------------------------------------------------------------------ */
/* Request Context (for ArpRequest) */
/* ------------------------------------------------------------------ */
typedef struct {
LIST_ENTRY Link; /* 0x00 */
ARP_INSTANCE *Instance; /* 0x10 */
EFI_EVENT CompletionEvent; /* 0x18 */
VOID *TargetHwAddr; /* 0x20: destination for resolved MAC */
} ARP_REQUEST_CONTEXT;
/* ------------------------------------------------------------------ */
/* EFI_ARP_PROTOCOL (function pointer table, 0x4EC0) */
/* ------------------------------------------------------------------ */
typedef struct {
EFI_ARP_CONFIGURE ArpConfigure;
EFI_ARP_ADD ArpAdd;
EFI_ARP_FIND ArpFind;
EFI_ARP_DELETE ArpDelete;
EFI_ARP_FLUSH ArpFlush;
EFI_ARP_REQUEST ArpRequest;
EFI_ARP_CANCEL ArpCancel;
} ARP_PROTOCOL_TABLE;
/* ------------------------------------------------------------------ */
/* GUIDs */
/* ------------------------------------------------------------------ */
extern EFI_GUID gEfiArpServiceBindingProtocolGuid; /* 0x4D60 */
extern EFI_GUID gEfiArpProtocolGuid; /* 0x4D80 / 0x4E10 */
extern EFI_GUID gEfiManagedNetworkProtocolGuid; /* 0x4DB0 */
extern EFI_GUID gEfiManagedNetworkServiceBindingProtocolGuid; /* 0x4DA0 */
extern EFI_GUID gEfiComponentName2ProtocolGuid; /* 0x4DD0 */
extern EFI_GUID gEfiComponentNameProtocolGuid; /* 0x4DE0 */
extern EFI_GUID gEfiDevicePathProtocolGuid; /* 0x4E00 */
extern EFI_GUID gEfiDpcProtocolGuid; /* 0x4D70 */
/* ------------------------------------------------------------------ */
/* Globals */
/* ------------------------------------------------------------------ */
extern EFI_HANDLE gImageHandle; /* 0x4F08 */
extern EFI_SYSTEM_TABLE *gSystemTable; /* 0x4EF8 */
extern EFI_BOOT_SERVICES *gBootServices; /* 0x4F00 */
extern EFI_RUNTIME_SERVICES *gRuntimeServices; /* 0x4F10 */
extern VOID *gDebugPrint; /* 0x4F18 */
extern VOID *gDpcQueue; /* 0x4F30 */
extern VOID *gMnpProtocol; /* referenced */
//
// Module AutoGen bootstrap context and helpers (entry-point flow)
//
extern VOID *ArpAutoGenContext;
EFI_STATUS
EFIAPI
ArpAutoGenConstructor(
EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
ArpInitHook(
VOID *Context
);
EFI_STATUS
EFIAPI
ArpAutoGenDestructor(
VOID *Context
);
EFI_STATUS
EFIAPI
ArpAutoGenUnload(
VOID *Context,
INTN Phase
);
EFI_STATUS
EFIAPI
ArpAutoGenDebugAssert(
CHAR8 *FileName,
UINTN LineNumber,
CHAR8 *Expression
);
VOID
EFIAPI
ArpAutoGenDebugBreak(
VOID
);
/* ------------------------------------------------------------------ */
/* Function Prototypes -- ArpDriver.c */
/* ------------------------------------------------------------------ */
EFI_STATUS
_ModuleEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
ArpDriverInit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
ArpDriverBindingStart (
IN EFI_HANDLE ImageHandle
);
VOID
ArpUnload (
IN EFI_HANDLE ImageHandle
);
EFI_STATUS
ArpServiceCreateChild (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ParentHandle,
IN ARP_SERVICE *ArpService
);
EFI_STATUS
ArpServiceDestroyChild (
IN ARP_SERVICE *ArpService
);
EFI_STATUS
ArpServiceBindingCreateChild (
IN ARP_SERVICE *Service,
IN EFI_HANDLE *ChildHandle
);
EFI_STATUS
ArpServiceBindingDestroyChild (
IN ARP_SERVICE *Service,
IN EFI_HANDLE ChildHandle
);
EFI_STATUS
ArpSBCreateChild (
IN ARP_SERVICE *ArpService,
OUT EFI_HANDLE *ChildHandle
);
EFI_STATUS
ArpSBDestroyChild (
IN ARP_SERVICE *ArpService,
IN EFI_HANDLE ChildHandle
);
/* ------------------------------------------------------------------ */
/* Function Prototypes -- ArpImpl.c */
/* ------------------------------------------------------------------ */
VOID
ArpOnFrameRcvd (
IN ARP_SERVICE *ArpService
);
VOID
ArpOnFrameSent (
IN VOID *Context
);
VOID
ArpTimer (
IN EFI_EVENT Event,
IN VOID *Context
);
BOOLEAN
ArpCompareAddress (
IN VOID *AddressOne,
IN VOID *AddressTwo
);
ARP_CACHE_ENTRY *
ArpFindCacheEntry (
IN LIST_ENTRY *CacheList,
IN LIST_ENTRY *StartPos,
IN UINT8 MatchFlags,
IN VOID *ProtocolAddress,
IN VOID *HardwareAddress
);
ARP_CACHE_ENTRY *
ArpFindCacheEntryEx (
IN ARP_SERVICE *ArpService,
IN VOID *ProtocolAddress,
IN VOID *HardwareAddress
);
ARP_CACHE_ENTRY *
ArpCreateCacheEntry (
IN ARP_INSTANCE *Instance OPTIONAL
);
UINT64
ArpFlushCacheEntry (
IN ARP_CACHE_ENTRY *CacheEntry,
IN ARP_INSTANCE *Instance OPTIONAL,
IN EFI_EVENT UserEvent OPTIONAL
);
BOOLEAN
ArpUpdateCacheEntry (
IN ARP_CACHE_ENTRY *CacheEntry,
IN VOID *HardwareAddress,
IN VOID *ProtocolAddress OPTIONAL
);
EFI_STATUS
ArpConfigureInstance (
IN ARP_INSTANCE *Instance,
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
);
EFI_STATUS
ArpSendFrame (
IN ARP_INSTANCE *Instance,
IN ARP_CACHE_ENTRY *CacheEntry,
IN UINT16 OpCode
);
UINT64
ArpPurgeCacheEntries (
IN LIST_ENTRY *CacheList,
IN UINT8 MatchType,
IN UINT16 ProtocolType,
IN VOID *ProtocolAddress,
IN BOOLEAN ForcePurge
);
UINT64
ArpPurgeInstance (
IN ARP_INSTANCE *Instance,
IN UINT8 MatchType,
IN VOID *ProtocolAddress,
IN BOOLEAN ForcePurge
);
UINT64
ArpCancelInstance (
IN ARP_INSTANCE *Instance,
IN VOID *ProtocolAddress OPTIONAL,
IN EFI_EVENT CompletionEvent OPTIONAL
);
EFI_STATUS
ArpFindCacheEntryEx2 (
IN ARP_INSTANCE *Instance,
IN BOOLEAN BySwAddress,
IN VOID *ProtocolAddress,
OUT UINT32 *EntryCount OPTIONAL,
OUT UINT32 *EntryLength OPTIONAL,
OUT EFI_ARP_FIND_DATA **EntryBuffer OPTIONAL,
IN BOOLEAN Refresh
);
/* ------------------------------------------------------------------ */
/* Function Prototypes -- ArpMain.c (EFI_ARP_PROTOCOL) */
/* ------------------------------------------------------------------ */
EFI_STATUS
ArpConfigure (
IN EFI_ARP_PROTOCOL *This,
IN EFI_ARP_CONFIG_DATA *ConfigData OPTIONAL
);
EFI_STATUS
ArpAdd (
IN EFI_ARP_PROTOCOL *This,
IN BOOLEAN PermanentEntry,
IN EFI_ARP_FIND_DATA *Entry OPTIONAL
);
EFI_STATUS
ArpFind (
IN EFI_ARP_PROTOCOL *This,
IN BOOLEAN BySwAddress,
IN VOID *SwAddress OPTIONAL,
OUT UINT32 *EntryCount OPTIONAL,
OUT UINT32 *EntryLength OPTIONAL,
OUT EFI_ARP_FIND_DATA **EntryBuffer OPTIONAL,
IN BOOLEAN Refresh
);
EFI_STATUS
ArpDelete (
IN EFI_ARP_PROTOCOL *This,
IN BOOLEAN BySwAddress,
IN VOID *SwAddress OPTIONAL
);
EFI_STATUS
ArpFlush (
IN EFI_ARP_PROTOCOL *This
);
EFI_STATUS
ArpRequest (
IN EFI_ARP_PROTOCOL *This,
IN VOID *TargetSwAddress OPTIONAL,
IN EFI_EVENT ResolvedEvent OPTIONAL,
OUT VOID *TargetHwAddress,
IN UINT32 ResolvedEvent OPTIONAL
);
EFI_STATUS
ArpCancel (
IN EFI_ARP_PROTOCOL *This,
IN VOID *TargetSwAddress OPTIONAL,
IN EFI_EVENT ResolvedEvent OPTIONAL
);
#endif /* __ARP_DXE_H__ */