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

Udp4Dxe

Function Table

Address Name Description
Udp4TimerHandler
Udp4DpcHandler
ModuleEntryPoint
Udp4DriverBindingSupported
Udp4DriverBindingStart
Udp4DriverBindingStop
Udp4ServiceBindingCreateChild
Udp4ServiceBindingDestroyChild
Udp4CreateService
Udp4Configure
Udp4Groups
Udp4Routes
Udp4Transmit
Udp4Transmit2
Udp4ValidateTxToken
Udp4Receive
Udp4Cancel
Udp4CancelTxRx
Udp4Poll
Udp4RxProcess
Udp4MatchInstanceByFilter
Udp4DeliverRxPacket
Udp4DeliverDgram
Udp4TryDeliverToken
Udp4SendIcmpError
Udp4SendIcmpErrorFromInstance
IpIoOpen
IpIoClose
IpIoAddAddr
IpIoRemoveAddr
NetMapInit
NetMapClean
NetMapInsert
NetMapInserttTail
NetMapRemoveEntry
NetMapIterate
ZeroMem
NetBufFree
Udp4FindInstanceByConfig
Udp4MatchConfig
50ms timer that recycles timed-out Rx tokens
Check service signature = 'Udp4'
Iterate through children list
For each configured instance with Rx timeout > 50000ms:
decrement timeout by 50000 (50ms)
if timeout expires (< 50000): signal event with EFI_TIMEOUT
DPC handler - queued packet delivery
Removes token from pending Rx map
Stores context in token
Signals token event
Calls DPC protocol to queue next DPC
Initialize global references (BootServices, RuntimeServices)
Open driver binding protocol on image handle
Initialize the component name and config strings
Install multiple protocol interfaces
Initialize ephemeral port from tick count
Validate parameters
Check signature via C CR macro
Open the UDP4 service binding protocol on controller
Close the protocol (we just tested existence)
Allocate and zero UDP4 service structure (80 bytes)
Initialize the service
Install service binding protocol on controller
Get the UDP4 service from controller
Find the first child with protocol opened
Validate instance signature
Specific child destruction requested
For each child in buffer, add to service's children map
and return
No specific children - destroy all
Close IP protocol on child
Close IP protocol from IpInfo
Cleanup IpInfo
If no children remain, clean up service
Get service from This via CR macro
CR check: (UINT32 )(This - 8) == 0x34737055
Allocate instance (336 bytes = 0x1500)
Initialize instance structures
Copy the UDP4 protocol template into instance
Add an IP address via IpIoAddAddr
Install the UDP4 instance protocol on child handle
Open IP4 protocol on child handle (as child of service)
Open IP4 protocol on IpInfo child handle too
Add to service children list
Get instance from handle via instance protocol
Validate instance via CR macro
Check signature
Mark as destroying
Close IP protocols
Uninstall the instance protocol
Remove from children list
Cleanup NetMaps
Initialize the service structure
Allocate IpIo protocol (0xA0 = 160 bytes)
Initialize IpIo structures
Create timer event (16ms TPL, callback = Udp4TimerHandler)
Open IP44 child protocol for Rx
Initialize Rx callback context
Set up the IP layer Rx configuration
Open the IpIo protocol channel
Proceed - it's already configured
Creat the 50ms periodic timer
Iterate through children instances
Check delivered dgram que for timeouts
Each entry in DeliveredDgramQue has a timeout value
If timeout >= 50000: decrement by 50000 (50ms)
Get instance from This via CR macro (offset -32 from protocol start)
This is at Instance + 0x40 (offset of Udp4Protocol in UDP4_INSTANCE)
Already not configured and no new config - just return
Validate and process the config data
Check Type (broadcast/unicast/multicast) and port range
For each Type in the known list of options...
Same config - just update timeouts/tttt
Configure IP layer via IpIoConfigIp
Copy config data to instance
Assign ephemeral port if needed
Compute UDP checksum
Deconfigigure - close and clean
Clean delivered dgram que
Remove and rcycle each
Get instance from This
Check if multicast address is valid (must start with 11110 = 0xE00000000)
Delegate to IP layer
Call IP's Groups (or mcast group join/leave)
If JoinFlag: NetMapInsertt(&Instance->McastIps, McastAddr, NULL);
Delegate to IP layer via IpInfo->Ip protocol
Then call IP's Routes function
Get instance
Check if not configured: error
Copy config if provided
Delegate to the Transmit2 (internal transmit)
Validate token (fragment count, data length, etc.)
Allocate NET_BUF with fragment data
Build UDP header (8 bytes)
If remote address seecified, use it; else use instance's
Compute checksum if needed
Inser into TxTokens map and send via IpIo
Remove from map
Validate fragment data
Sum fragment lengths, check vs. DataLength
Validate source/dedestination port range
Check that dedestination port is set if no default route
Check if token already in Tx or or Rx map
If yes: return EFI_OUT_OF_RESOURCES (already queued)
Clear token's packet pointer and inser in RxTokens
Try to deliver any queued datagram immediately
Request DPC to process Rx
Iterate TxTokens map, cancel matching tokens
If token is specified and not found, return NOT_F_FOUND
If token is NULL, cancel all (and check that both maps are empty)
Request DPC
If this is an Tx token (has a packet buffer)
Cancel via IP layer
Rx token - just mark as cancelled
Simply receive any pending IP packets synchronously
Then call IP's Poll function
Validate packet - min 8 bytes for UDP header
Get UDP header from packet
Extract fields (network byte order)
Udp4Len = ByteSwap16(Udp4Header[22]); / length + header /);
Build UDP header info for matching
Deliver to matching instances
No one matched - send ICMP Unreachable
Signal all instances with pending Rx tokens
If UseDefaultAddr is set, always match (no filtering)
Check destination port
Port not set - must match station port of instance
Check dedestination IP (if set in instance)
Check source IP (if set in instance)
Source matches our address - not for us
Check source port (if set in instance)
Port filtering
Check multicast group membership
Iterate through all children
Allocate a delivered dgram structure
Create DPC event for async delivery
Inser into Instance->DeliveredDgramQue
Increment Packet's ref count
Check if there are any delivered dgrams queued
Get head of delivered dgram que
Get Rx token from NetMap
No Rx token available - dgram stays queued
Clone the packet for this token
Copy data from clone to token's fragment buffer
Set token status
Remove from RxTokens map
Signal the token event
Move the delivered dgram to delivered Rx tokens que
Try to deliver the next Rx token
If there's a pending Rx token and a queued dgram
Get the first pending Rx token
Signal it with an ICMP error from last status
Find an IpIo instance that matches the source of the bad packet
Allocate ICMP header buffer
Build ICMP Dedestination Unreachable (Type = 3, Code = 3 (Port Unreachable))
Send via IpIo
Build ICMP error from instance's context
Send via Instance->Service->IpIo
Open IP protocol, set up Rx callback, listen handler
Close IP protocol, remove from global list
Cancel pending sends
Allocate IPIO_INFO (96 bytes)
Create child Rx protocol
Create event for Rx notification
Add to IpIo's open list
Find the IpInfo from the open list
Decrement ref count
If ref count <= 0: remove from list, close child protocol, free
Free all items in the map
Return first item
Simple byte-byte copy (or using rep stosb/movsb)
If UseDefaultAddr is set, don't compare station port

Generated by HR650X BIOS Decompilation Project