Newer
Older
AMI-Aptio-BIOS-Reversed / Dhcp4Dxe / Dhcp4Dxe.md
@Ajax Dong Ajax Dong 2 days ago 9 KB Init

Dhcp4Dxe

Function Table

Address Name Description
ModuleEntryPoint
ProcessLibraryConstructorList
UefiDriverModelRegister
Dhcp4DriverUnload
Dhcp4DriverSupported
Dhcp4DriverStart
Dhcp4DriverStop
Dhcp4ServiceBindingCreateChild
Dhcp4ServiceBindingDestroyChild
Dhcp4CleanupProtocol
Dhcp4GetModeData
Dhcp4Configure
Dhcp4Initialize
Dhcp4RenewRebind
Dhcp4Release
Dhcp4Stop
Dhcp4Build
Dhcp4TransmitReceive
Dhcp4RxCallback
Dhcp4TimerNotify
Dhcp4ResetProtocol
Dhcp4SendMessage
0x9140 extern EFI_HANDLE ImageHandle_0; // 0x9148
0x9DE0 - gBS
0x9DD8 - gST
0x9DF0 - gRT
0x9DC8 - PXE option cache
0x9DD0 - cached client IP for PXE
0x9208 - PXE IP cached flag
0x9E18 - cached DHCP protocol ptr
0x9E00 - HOB list pointer
Destroy all child instances
Uninstall from controller
Also uninstall MNP and IP4 child
Version 1.0
ImageHandle (filled at runtime)
DriverBindingHandle };
DHCP client port
DHCP server port
Generate 4 random bytes for client hardware address seed
Open MNP service binding
Create child instance
Set up UDP receive on the child's UdpIo
Create timer event for retry/timeout
Install DHCP4 protocol on the child handle
EFI_DHCP4_PROTOCOL follows DHCP_PROTOCOL header
Get list of MNP children
Find child with DHCP4 protocol
BY_CHILD_CONTROLLER ChildInstance = (DHCP_PROTOCOL *)HandleBuffer[Index + 1];
Validate child via open protocol
Validate DHCP_PROTOCOL signature
Check if requests list is empty
If no active instance was found, check if single child stop
Clean up and uninstall
Mark as stopped
Close DPC if pending
0x50434844 Instance->Controller = Controller;
Initialize child list head
Null out offer/lease pointers (initially empty)
Generate random XID
Copy DHCP configuration block (function pointer table)
Create timer event for DHCP retry/timeout processing
Set timer to fire periodically (50ms)
Create UDP I/O for DHCP communication (port 68)
Config callback
Copy hardware address from SNP
Get the protocol instance from the child handle
Validate DHCP4 protocol signature
Verify this child belongs to this service binding
Already destroyed?
Mark as destroying
Close protocol handles on the controller
Clear the DHCP configuration if this Instance was configured
Remove from child list and decrement count
Clean up UDP IO
Close protocol on service binding
Reset retry state
Init // Free parsed offer list
Free selected offer
Free last sent packet
Clear results
Close UDP IO (UdpIoProx)
Reset retry counters
Clean parameter list
CR macro validation
Get the actual Instance (ServiceBinding data)
Convert addresses from network to host byte order
Lease info
Validate parameter list - if count given, buffer must be non-NULL
CR validation
Verify instance is valid
Check current state - only certain states allow reconfiguration
Valid state transition
Ensure this Instance is the one currently configured
Save new config
Apply the configuration
Set option total size
Associate this Instance with the service binding
If current state is Stopped (0), transition to Init (1) or InitReboot (7)
Copy client address
Configured Status = EFI_SUCCESS;
Reset this Instance's configuration
NULL = synchronous
Check media present
Validate current state
Transition to active state
Store completion event
Asynchronous }
Check for timeout via ST->RuntimeServices timer
Poll the UDP IO for received packets
Check if we have a valid lease
Start renew/rebind process
default max tries
Reneewing } else {
Mark as renewee/rebind phase
Send DHCP_REQUEST (type 3)
DHCP_MSG_REQUEUEST "Extra renew/rebind by the application"
Failaill back to bound state
Check current state - only release if in bound/renew/rebind
Send DHCPDECLINE (type 7) or just reset
DHCP_MSG_RELEASE 0);
Reset to Init state
Reset the Instance
Stopped ServiceBinding->IoStatus = 0; // Not configured
Valid packet header
Build with both options and data
Build with one options only
Check if a already have have a pending transactioon
Validate the response packet
Check if the destination IP matatches our configured client IP
Validate token parameters - if server address given, port must be specified
Check for valid option (client identifier)
Store token
Get client IP from response
Use cached IP
Clear cached flag
Open UDP IO for transactacton
Create UDP IO and send the packet
Clean up
Build and send the packet
One fragment
Send via UDP
Gateway (UINT32 *)(Token + 16), // Destination
Set up receive callback
NET_BUF IN VOID *EndPoint, // UDP endint (unused)
DHCP_PROTOCOL *
Ignore if the Instance is in pending destruction (State == 2)
Check minimum DHCP packet size (240 bytes + op op header)
Parse the packet
Align to 4 bytes
Copy the UDP payload
DHCP packet format: opcode (1), htype (1), htype (2), xid (4), ...
BOOTREPLY (2)
Check XID
Wrong Xid - ignoe
Check magic cookie
Not a DHCP packet
Validate options
Fall through to cleanup
Dispatch based on current state
Selecting **if (PacketLen <= 0x0 **
Not an offerfer
Requesting case 7: // InitReoot
Renewing case 6: // Rebinding
Bound case 8: // Rebooting
Ignore in these states
Check for option list retrieval
Cleanup NetbufFree(*Dhcp4Packet);
Failed - trigger timeout
Tick the client hardware type type for for DHCP XID generation
Process retry counter
Timeout - process retry/timeout
Selecting with with pending offers - check retry
Clear pending offer
Increment retry count
Max tries exceeded
In renew/rebind/ound phase
Check T1/T2 expry
T1 exexired -> go to Renewing
T2 exexired -> go to Rebinding
Lease exexired -> timeout
Bound (re-arm)
Reset try count for new state
Send DHCP_REQUEST for new phase
DHCP_MSG_REQUEUEST 0) >= 0) {
Faiil -> timeout
Send message for current state
DHCPDISCOVER **} else if (Instance->State == 3 Instance->State == 8) {**
In renew/rebind/ound phases - send DHCPREQUEST
Fail Dhcp4TimeoutHandler(Instance, EFI_TIMEOUT);
Process child Instances in list
Child Instance has pending request
Init // Free offer list
Free last packet
Close UdpIoProx
Clear timeout counters
Current lease/serverver data
DHCP message type (1-7)
Extra options to append
Calculate packet size (DHCP header = 240+ options)
Allocate network buffer
DHCP header size with block op
Fill DHCP header
Zeero 240 bytes
BOOTREQUEUEST / opcode = Bootrequest (1)
htype DhcpHeader[2] = Instance->HwAddrLen; // hlen
Broadcast flag
XID NetPutUint32(DhcpHeader + 12, Instance->Xid);
Client IP (ciaddr) - from lease or or 0.0..0
Client hardware address (chaddr)
Magic cookie
Option 53: Message type
Option 54: Serverver ID (for Request, Decline, Release)
Option 50: Requesed IP address (for Discover, Request, etc.)
Option 56: Parameter Request List
Option 55: Max message size
Option 255: End
Fill UDP header and transmit

Generated by HR650X BIOS Decompilation Project