Newer
Older
AMI-Aptio-BIOS-Reversed / AmiNetworkPkg / UefiNetworkStack / Ipv6 / Ip6Dxe / Ip6Dxe / Ip6Dxe.c
@Ajax Dong Ajax Dong 7 days ago 20 KB Recovering names
/*
 * Ip6Dxe - IPv6 Network Stack DXE Driver (Reconstructed Source Overview)
 *
 * Source: AmiNetworkPkg/UefiNetworkStack/Ipv6/Ip6Dxe/
 * PE:     Index 0152, Ip6Dxe.efi
 * MD5:    0288be1cadd121eaa69221de6b7f42f3
 * SHA256: c559cc7b50c059a3214ad238f60dc15176cba015c6267094e38b9be2820537d0
 *
 * Analysis notes:
 *   - 315 functions, 308 strings, 8 segments (92KB .text)
 *   - 8 source files: Ip6Driver.c, Ip6Impl.c, Ip6ConfigImpl.c,
 *     Ip6ConfigNv.c, Ip6Common.c, Ip6Output.c, Ip6Nd.c, Ip6Mld.c
 *   - No import table (all protocol binding through BS->LocateProtocol
 *     and BS->OpenProtocol)
 *   - Signatures: IP6S=0x53365049, IP6I=0x49365049, IP6P=0x50365049,
 *     IFCI=0x49434649, IP6C=0x43365049, nbuf=0x6675626E
 *
 * ============================================================
 * THIS IS A REFERENCE OVERVIEW FOR THE RECONSTRUCTED SOURCE
 * ============================================================
 */

#include "Ip6Dxe.h"

/* ================================================================== */
/* SECTION 1: Driver Entry Point & Driver Binding Protocol             */
/*                  (Ip6Driver.c)                                      */
/* ================================================================== */

/*
 * _ModuleEntryPoint (0x548)
 * Entry point called by UEFI core.
 * 1. Calls Ip6DxeInitialize to initialize globals (gST, gBS, gRT) and locate
 *    HII protocols (HII_DATABASE, HII_STRING, HII_CONFIG_ROUTING),
 *    EFI_DPC_PROTOCOL.
 * 2. Opens EFI_LOADED_IMAGE_PROTOCOL to get ImageHandle info.
 * 3. Reads NetworkStackVar UEFI variable to check if IPv6 is enabled.
 * 4. Calls InstallMultipleProtocolInterfaces to install:
 *    - EFI_IP6_PROTOCOL (GUID 18A031AB-B443-4D1A-A5C0-0C09261E9F71 at 0x1BCF8)
 *      with protocol interface table at off_1BD88
 *    - EFI_IP6_CONFIG_PROTOCOL (GUID 107A772C-D5E1-11D4-9A46-0090273FC14D at 0x1BD28)
 *      with protocol interface table at off_1BE08
 *    - Additional protocols: EFI_MANAGED_NETWORK_SERVICE_BINDING etc.
 * 5. Returns EFI_SUCCESS on success.
 */

/*
 * Ip6DxeInitialize (0x5C4) - Driver Library Constructor
 * Initializes gImageHandle, gST, gBS, gRT.
 * Locates protocols:
 *   - HII_STRING_PROTOCOL  -> gHiiString       (0x1C1B0)
 *   - HII_DATABASE_PROTOCOL -> gHiiDatabase    (0x1C1A8)
 *   - HII_CONFIG_ROUTING_PROTOCOL               (0x1C1B8)
 *   - HII package list handle                   (0x1C1C0)
 *   - HII_CONFIG_ACCESS_PROTOCOL                 (0x1C1C8)
 *   - EFI_DPC_PROTOCOL                            (0x1C1E0)
 */

/*
 * Ip6DriverBindingSupported (0x94C) - DriverBinding Supported
 * EFI_DRIVER_BINDING_PROTOCOL.Supported().
 * Checks if the controller supports the Managed Network Protocol.
 * Returns EFI_SUCCESS if MNP is available on the controller.
 */

/*
 * Ip6DriverBindingStart (0x1160) - DriverBinding Start
 * EFI_DRIVER_BINDING_PROTOCOL.Start().
 * Opens MNP child handle on the controller.
 * Calls Ip6CreateService to allocate and initialize the IP6_SERVICE instance.
 * Installs IP6 protocol on the child.
 * Initializes default routes, timers, and configuration.
 * Seeds random state for IPv6.
 */

/*
 * Ip6DriverBindingStop (0x13F0) - DriverBinding Stop
 * EFI_DRIVER_BINDING_PROTOCOL.Stop().
 * Destroys all child instances, cleans up MNP connection,
 * frees the IP6_SERVICE instance.
 */

/*
 * Ip6CreateService (0xC80)
 * Allocates and initializes the IP6_SERVICE struct (4192 bytes).
 * Signature 'IP6S' at +0.
 * Sets:
 *   - NotifyFunction = Ip6ServiceCreateChild (+0x08, timer tick handler)
 *   - DestroyChild   = Ip6ServiceDestroyChild (+0x10)
 *   - Timer events for periodic processing
 *   - ND parameters (reachable time, retrans timer, etc.)
 *   - Neighbor cache (128 entries at +0x88)
 *   - Route table, prefix list
 * Opens MNP, configures it, creates receive buffer ring.
 */

/*
 * Ip6DestroyService (0x9C4)
 * Inverse of Ip6CreateService. Stops all timers, closes MNP,
 * destroys all child instances, frees all resources.
 * Sets state to destroyed.
 */

/*
 * Ip6ServiceCreateChild (0x1694)
 * EFI_IP6_SERVICE_BINDING_PROTOCOL.CreateChild().
 * Allocates a new IP6_INSTANCE (360 bytes), passes it to Ip6CommonInitInstance
 * for initialization, opens MNP for this child.
 */

/*
 * Ip6ServiceDestroyChild (0x1818)
 * EFI_IP6_SERVICE_BINDING_PROTOCOL.DestroyChild().
 * Cleans up and frees the child instance.
 */

/* ================================================================== */
/* SECTION 2: EFI_IP6_PROTOCOL Implementation                          */
/*                  (Ip6Impl.c)                                        */
/* ================================================================== */

/*
 * Address range: ~0x324C - 0x4724 (Ip6Impl.c functions)
 *
 * Ip6GetModeData (0x324C)
 * EFI_IP6_PROTOCOL.GetModeData().
 * Returns current IPv6 state including:
 *   - IsStarted (bool)
 *   - MaxPacketSize
 *   - StationAddress (copied from instance)
 *   - AddressList, GroupTable, RouteTable, NeighborCache
 * Allocates and fills these tables dynamically.
 *
 * Ip6Configure (0x3950)
 * EFI_IP6_PROTOCOL.Configure().
 * If ConfigData is NULL: resets instance (cleans up).
 * Otherwise validates the config (station address, prefix length),
 * applies it to the interface, and registers address info.
 *
 * Ip6Groups (0x3AE4)
 * EFI_IP6_PROTOCOL.Groups().
 * Join/leave multicast groups. Calls into MLD functions.
 *
 * Ip6Routes (0x3BD0)
 * EFI_IP6_PROTOCOL.Routes().
 * Add/remove route table entries.
 *
 * Ip6Neighbors (0x3D20)
 * EFI_IP6_PROTOCOL.Neighbors().
 * Add/update/delete neighbor cache entries.
 *
 * Ip6Transmit (0x3F4C)
 * EFI_IP6_PROTOCOL.Transmit().
 * Builds IPv6 header, processes extension headers,
 * fragments if needed, and sends via MNP.
 *
 * Ip6Receive (0x439C)
 * EFI_IP6_PROTOCOL.Receive().
 * Registers a receive completion token.
 *
 * Ip6Cancel (0x44C4)
 * EFI_IP6_PROTOCOL.Cancel().
 * Cancels pending transmit/receive tokens.
 *
 * Ip6Poll (0x4684)
 * EFI_IP6_PROTOCOL.Poll().
 * Polls MNP for incoming packets.
 *
 * Ip6OpenState (0x4724) - internal
 * Opens config state.
 */

/* ================================================================== */
/* SECTION 3: EFI_IP6_CONFIG_PROTOCOL Implementation                   */
/*                  (Ip6ConfigImpl.c)                                  */
/* ================================================================== */

/*
 * Address range: ~0x7988 - 0x9D20 (Ip6ConfigImpl.c functions)
 *
 * Ip6ConfigSetData (0x7988)
 * EFI_IP6_CONFIG_PROTOCOL.SetData().
 * Processes configuration data items:
 *   - Manual address, gateway, DNS, etc.
 * Updates the IP6_SERVICE configuration state.
 *
 * Ip6ConfigStart (0x7C24)
 * Opens MNP child for configuration,
 * registers DHCPv6 event notification or initiates
 * stateless address autoconfiguration (SLAAC) based on config.
 *
 * Ip6ConfigGetData (0x8770)
 * EFI_IP6_CONFIG_PROTOCOL.GetData().
 * Retrieves current configuration data items.
 * Walks neighbor cache, prefix list, address list, route table
 * to populate the requested data type.
 *
 * Ip6ConfigRegisterNotify (0x8DD8)
 * EFI_IP6_CONFIG_PROTOCOL.RegisterNotify().
 *
 * Ip6ConfigUnregisterNotify (0x9078)
 * EFI_IP6_CONFIG_PROTOCOL.UnregisterNotify().
 *
 * Ip6ConfigFindDataItem (0x92B8) - internal
 * Finds a data item by data type index.
 *
 * Ip6ConfigGetConfigData (0x94B4) - internal
 * Collects config data from neighbors, addresses, etc.
 *
 * Ip6ConfigSetConfigData (0x958C) - internal
 * Applies configuration changes.
 *
 * Ip6ConfigGetInfo (0x97AC) - internal
 * Retrieves interface info.
 *
 * Ip6ConfigInit (0x9CA0) - internal
 * Initializes the config data items with default values.
 */

/* ================================================================== */
/* SECTION 4: HII Configuration (Ip6ConfigNv.c)                        */
/*                  (Ip6ConfigNv.c)                                    */
/* ================================================================== */

/*
 * Address range: ~0xE7E0 - 0x10484 (Ip6ConfigNv.c functions)
 *
 * These functions implement the EFI_HII_CONFIG_ACCESS_PROTOCOL:
 *   - ExtractConfig, RouteConfig, Callback
 *
 * Ip6ConfigNvCallback (0xFCC0) - main HII callback
 * EFI_HII_CONFIG_ACCESS_PROTOCOL.Callback().
 * Processes user interactions with the IPv6 configuration form:
 *   - Question ID 264: Save interface ID
 *   - Question ID 257: Parse and validate Interface ID string
 *   - Question ID 258: Validate Gateway addresses
 *   - Question ID 259: Validate Gateway addresses
 *   - Question ID 260: Validate DNS addresses
 *   - Question ID 261: Save config
 *   - Question ID 262: Commit config
 *   - Question ID 263: Refresh/reset config
 *
 * Ip6ConfigNvExtractConfig (0xEF84)
 * EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig().
 * Converts NV data to HII configuration format.
 *
 * Ip6ConfigNvRouteConfig (0xF814)
 * EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig().
 * Routes configuration data from HII back to NV storage.
 *
 * Ip6ConfigNvCommitConfig (0xFA8C) - internal
 * Commits the current NV data to the actual IP6 config.
 *
 * Ip6ConfigNvUpdateForm (0xF540) - internal
 * Updates the HII form based on current config.
 *
 * Ip6ConfigNvCreatePopUp (0x13AF0) - internal
 * Creates a pop-up dialog for error/info messages.
 */

/* ================================================================== */
/* SECTION 5: Common Utility Functions (Ip6Common.c)                    */
/*                  (Ip6Common.c)                                      */
/* ================================================================== */

/*
 * Address range: ~0x2C04 - 0x38A4 (Ip6Common.c functions)
 *                ~0xD1A4 - 0xDA30 (Ip6Common.c functions)
 *
 * Ip6CommonGetAddressInfoList (0x2C04) - internal
 * Gets the address info list from the service instance.
 *
 * Ip6CommonCreateAddressInfo (0xD1A4) - internal
 * Creates and registers a new address info entry.
 *
 * Ip6CommonFindAddressInfo (0xD318) - internal
 * Finds a specific address info entry by address.
 *
 * Ip6CommonAddAddressInfo (0xD3C4) - internal
 * Adds an address-info mapping.
 *
 * Ip6CommonRemoveAddressInfo (0xD500) - internal
 * Removes an address info entry.
 *
 * Ip6CommonAddNeighbor (0xD5E8) - internal
 * Adds a neighbor cache entry.
 *
 * Ip6CommonFindNeighbor (0xD7B0) - internal
 * Finds a neighbor cache entry.
 *
 * Ip6CommonPrefixMatch (0x34F8) - internal
 * Checks if an address matches a prefix.
 *
 * Ip6CommonInitInstance (0x3568) - internal
 * Initializes an IP6 instance structure.
 *
 * Ip6CommonConfigureInstance (0x3648) - internal
 * Configures the instance with specified parameters.
 *
 * Ip6CommonCleanupInstance (0x37F4) - internal
 * Cleans up and resets an instance.
 */

/* ================================================================== */
/* SECTION 6: IPv6 Output (Ip6Output.c)                                */
/*                  (Ip6Output.c)                                      */
/* ================================================================== */

/*
 * Address range: ~0x1A28 - 0x2B54 (Ip6Output.c functions)
 *
 * Ip6Output (0x1FB8) - main output function
 * Builds an IPv6 output packet from an NET_BUF.
 * Wraps the data with IPv6 header, extension headers.
 * Fragments if packet exceeds link MTU.
 * Calls into route lookup (Ip6OutputRouteLookup, next-header handling) and transmits.
 *
 * Ip6OutputFragment (0x1B40) - internal
 * Fragments an IPv6 packet into multiple fragments.
 *
 * Ip6OutputIpHeader (0x1D80) - internal
 * Builds the IPv6 header in the output packet.
 *
 * Ip6OutputExtHeader (0x1E9C) - internal
 * Processes extension headers (Hop-by-Hop, Routing, Fragment, etc.)
 *
 * Ip6OutputValidateParam (0x280C)
 * Validates output parameters.
 *
 * Ip6OutputRouteLookup (0xDAC8) - internal
 * Route table lookup for next-hop determination.
 */

/* ================================================================== */
/* SECTION 7: Neighbor Discovery (Ip6Nd.c)                             */
/*                  (Ip6Nd.c)                                          */
/* ================================================================== */

/*
 * Address range: ~0x47B0 - 0x6DE4 (Ip6Nd.c functions)
 *
 * Implements Neighbor Discovery Protocol (RFC 4861).
 *
 * Ip6NdStart (0x47B0) - internal
 * Initializes ND module for an instance (reachable timer, etc.)
 *
 * Ip6NdStop (0x48F4) - internal
 * Stops ND module for an instance.
 *
 * Ip6NdBeginWork (0x4A20) - internal
 * Begins ND work - processes ND messages.
 *
 * Ip6NdTimerCallback (0x4B90) - ND timer callback (internal)
 *
 * Ip6NdRetransmitHandler (0x4C78) - ND retransmission handler (internal)
 *
 * Ip6NdPeriodicProcess (0x4F28)
 * ND periodic processing (timer tick).
 *
 * Ip6NdEventHandler (0x5040)
 * ND event handler - route/address discovery notifications.
 *
 * Ip6NdTimeoutHandler (0x50FC)
 * ND timeout handler for neighbor/prefix state management.
 *
 * Ip6NdSendSolicitation (0x5260)
 * ND sending solicitation.
 *
 * Ip6NdProcessAdvertisement (0x5488)
 * ND processing received advertisement.
 *
 * Ip6NdProcessRouterAdvertisement (0x5B10)
 * ND processing router advertisement.
 *
 * Ip6NdBuildNeighborSolicitation (0x5DB8)
 * ND building and sending neighbor solicitation.
 *
 * Ip6NdBuildNeighborAdvertisement (0x6120)
 * ND building neighbor advertisement response.
 *
 * Ip6NdProcessRedirect (0x6438)
 * ND processing redirect messages.
 *
 * Ip6NdGenerateLinkLocalAddress (0x6A90)
 * ND generating link-local address.
 */

/* ================================================================== */
/* SECTION 8: Multicast Listener Discovery (Ip6Mld.c)                  */
/*                  (Ip6Mld.c)                                         */
/* ================================================================== */

/*
 * Address range: ~0xACAC - 0xBA98 (Ip6Mld.c functions)
 *
 * Implements MLDv2 (RFC 3810) / MLDv1 (RFC 2710).
 *
 * Ip6MldInit (0xACAC)
 * MLD initialization for an interface.
 *
 * Ip6MldJoinGroup (0xAD6C)
 * MLD group join operation.
 *
 * Ip6MldLeaveGroup (0xAE0C)
 * MLD group leave operation.
 *
 * Ip6MldProcessQuery (0xB01C)
 * MLD query processing.
 *
 * Ip6MldProcessReport (0xB2EC)
 * MLD report processing.
 *
 * Ip6MldBuildReport (0xB5B4)
 * MLD building and sending reports.
 *
 * Ip6MldProcessDone (0xBB0C) - also Ip6Mld?
 * Another MLD handler.
 */

/* ================================================================== */
/* SECTION 9: Timer and Event Handlers                                 */
/*              (distributed across source files)                      */
/* ================================================================== */

/*
 * TimerTicking (0xAB40) - Ip6Driver.c internal
 * Periodic timer callback (every 500ms based on timer config).
 * Drives ND and MLD state machines.
 * Called from the timer event created in Ip6CreateService.
 *
 * Ip6ReceivePacketCallback (0x6EC0)
 * Receive buffer processing callback.
 * Called when MNP signals received data.
 * Dispatches to ND and MLD protocol handlers.
 *
 * Ip6QueueDpc (0x7EB0)
 * DPC queuing routine (deferred procedure call).
 * Queues work for deferred execution.
 *
 * Ip6DpcPacketDemux (0x8068)
 * DPC handler - processes received IP6 packets.
 * Demultiplexes by NextHeader (TCP=6, UDP=17, ICMPv6=58, etc.)
 *
 * Ip6ConfigNotification (0x977C)
 * Config notification callback (wake-up from DHCPv6/etc.)
 *
 * Ip6MnpReceiveCallback (0x9774)
 * MNP receive completion callback.
 */

/* ================================================================== */
/* SECTION 10: Library Support Functions                               */
/* ================================================================== */

/*
 * Address range: ~0x10504 - 0x105CC (Debug/assert)
 * These provide DEBUG/ASSERT support similar to UEFI DebugLib.
 * Many xrefs from assert expressions throughout the driver.
 *
 * DebugPrint (0x10504) - variadic
 * Assert (0x1058C)
 *
 * Library functions linked from MdePkg and MdeModulePkg:
 * - NetBuffer.c  (0x1A618) - NET_BUF management
 * - DxeNetLib.c  (0x1A3C0) - Network library utilities
 * - HiiLib.c     (0x1A128) - HII library
 * - DxeDpcLib.c  (0x1A9C0) - DPC library
 * - UefiLib/DriverModel.c
 * - UefiBootServicesTableLib
 * - UefiRuntimeServicesTableLib
 */

/* ================================================================== */
/* FUNCTION-CALL RELATIONSHIPS (Call Graph Summary)                    */
/* ================================================================== */
/*                                                                     */
/* Driver entry:                                                       */
/*   _ModuleEntryPoint (0x548)                                         */
/*     -> Ip6DxeInitialize (init gST/gBS/gRT and HII/DPC protocols)   */
/*     -> InstallMultipleProtocolInterfaces (installs 3 protocols)     */
/*     -> Ip6InstallDriverBinding (read variable, register DriverBinding) */
/*                                                                     */
/* Driver Binding Protocol:                                            */
/*   Ip6DriverBindingSupported -> ControllerSupported                  */
/*   Ip6DriverBindingStart -> DriverStart                               */
/*     -> Ip6CreateService -> Ip6CreateService (4192 bytes)             */
/*     -> Ip6QueueDpc -> MNP open + config                              */
/*     -> Ip6ConfigInit -> Config init                                  */
/*     -> Ip6CreateTimer -> Timer create                                */
/*     -> Ip6SetupRoutes -> Route/address setup                         */
/*     -> Ip6RegisterEvents -> Event registration                       */
/*   Ip6DriverBindingStop -> DriverStop                                 */
/*     -> Ip6DestroyService -> Ip6DestroyService                        */
/*                                                                     */
/* IP6 Protocol (per-child):                                           */
/*   Ip6GetModeData -> Ip6GetModeData                                   */
/*     -> Ip6CommonGetAddressInfoList -> GetAddressInfoList             */
/*     -> Ip6NdStart -> Ip6NdStart                                      */
/*     -> Ip6NdStop -> Ip6NdStop                                        */
/*   Ip6Configure -> Ip6Configure                                       */
/*     -> Ip6CommonPrefixMatch -> PrefixMatch                           */
/*     -> Ip6CommonCleanupInstance -> CleanupInstance                   */
/*     -> Ip6CommonConfigureInstance -> ConfigureInstance               */
/*     -> Ip6CommonCreateAddressInfo -> CreateAddressInfo               */
/*   Ip6Transmit -> Ip6Transmit                                         */
/*     -> Ip6Output -> Ip6Output (packet building)                     */
/*   Ip6Receive -> Ip6Receive                                           */
/*   Ip6Cancel -> Ip6Cancel                                             */
/*   Ip6Poll -> Ip6Poll                                                 */
/*                                                                     */
/* IP6 Config Protocol:                                                */
/*   Ip6ConfigSetData -> SetData                                        */
/*     -> Ip6ConfigGetData -> GetData (also called from GetData)       */
/*     -> Ip6ConfigSetConfigData -> SetConfigData                      */
/*   Ip6ConfigRegisterNotify -> RegisterNotify                         */
/*   Ip6ConfigUnregisterNotify -> UnregisterNotify                     */
/*   Ip6MnpReceiveCallback -> ConfigCallback (MNP recv callback)       */
/*   Ip6ConfigNotification -> ConfigNotification (event notify)        */
/*                                                                     */
/* Timer/Event loop (running in background):                           */
/*   TimerTicking -> Timer tick (500ms periodic)                       */
/*     -> Ip6ServiceCreateChild -> Check for new TCP child protocol     */
/*     -> Ip6ReceivePacketCallback -> Receive data processing          */
/*   Ip6ReceivePacketCallback -> ProcessRecvData                       */
/*     -> Ip6DpcPacketDemux -> DPC handler for demux                   */
/*                                                                     */
/* Output path:                                                        */
/*   Ip6Output -> Ip6Output (transmit packet)                           */
/*     -> Ip6OutputFragment -> Fragmentation                            */
/*     -> Ip6OutputIpHeader -> Build IPv6 header                        */
/*     -> Ip6OutputExtHeader -> Build extension headers                */
/*     -> Ip6OutputRouteLookup -> Route lookup                          */
/*     -> Next header handling                                          */
/*     -> MNP Transmit                                                 */
/*                                                                     */
/* ================================================================== */