# SnpDxe

## Function Table

| Address | Name | Description |
|---------|------|-------------|
|  | **SnpFreePool** |  |
|  | **SnpStrLen** |  |
|  | **SnpAsciiStrLen** |  |
|  | **SnpStrnLenS** |  |
|  | **SnpAsciiStrnLenS** |  |
|  | **SnpUtoA** |  |
|  | **SnpIsListValid** |  |
|  | **SnpInsertTailList** |  |
|  | **SnpIsNull** |  |
|  | **SnpIsListEmpty** |  |
|  | **SnpRemoveEntryList** |  |
|  | **SnpDebugPrint** |  |
|  | **SnpDebugAssert** |  |
|  | **SnpCompareGuidPartial** |  |
|  | **SnpIsProtocolGuidMatch** |  |
|  | **SnpCreateLegacyBootEvent** |  |
|  | **SnpReadUnaligned64** |  |
|  | **SnpComponentNameParseLanguage** |  |
|  | **SnpComponentNameAddLanguage** |  |
|  | **SnpPrintLib** |  |
|  | **SnpPrintLibInternal** |  |
|  | **SnpPrintLibNoFormat** |  |
|  | **SnpSPrint** |  |
|  | **SnpRegisterCallback** |  |
|  | **SnpUnregisterCallback** |  |
|  | **SnpDestroyChild** |  |
|  | **SnpAcpiCheck** |  |
|  | **SnpAcpiIoReadWrite** |  |
|  | **SnpAcpiReadWrite** |  |
|  | **SnpAcpiMap** |  |
|  | **SnpAcpiUnmap** |  |
|  | **SnpAcpiFlush** |  |
|  | **SnpIssueHwUndiCommand** |  |
|  | **SnpTimerNotifyFunction** |  |
|  | **_ModuleEntryPoint** |  |
|  | **SnpDxeEntryPoint** |  |
|  | **SnpNotifyNetworkInterfaceIdentifier** |  |
|  | **SnpTriggerPxeShutdown** |  |
|  | **SnpCreateChild** |  |
|  | **SnpSupported** |  |
|  | **SnpStart** |  |
|  | **SnpDriverBindingStop** |  |
|  | **SnpComponentNameGetDriverName** |  |
|  | **SnpGetControllerName** |  |
|  | **SnpComponentNameGetControllerName** |  |
|  | **SnpStartEntry** |  |
|  | **SnpStartEntryState** |  |
|  | **SnpStopEntry** |  |
|  | **SnpStop** |  |
|  | **SnpPxeInit** |  |
|  | **SnpInitialize** |  |
|  | **SnpResetInternal** |  |
|  | **SnpReset** |  |
|  | **SnpShutdownInternal** |  |
|  | **SnpShutdownEntry** |  |
|  | **SnpReceiveFiltersEnable** |  |
|  | **SnpReceiveFiltersDisable** |  |
|  | **SnpReceiveFiltersSet** |  |
|  | **SnpReceiveFilters** |  |
|  | **SnpStationAddressGet** |  |
|  | **SnpStationAddressSet** |  |
|  | **SnpStationAddress** |  |
|  | **SnpStatisticsInternal** |  |
|  | **SnpGetStatusInternal** |  |
|  | **SnpGetStatus** |  |
|  | **SnpFillHeader** |  |
|  | **SnpTransmitInternal** |  |
|  | **SnpTransmit** |  |
|  | **SnpReceiveInternal** |  |
|  | **SnpReceive** |  |
|  | **SnpMcastIpToMacInternal** |  |
|  | **SnpMcastIpToMac** |  |
|  | **SnpNvdataInternal** |  |
|  | **SnpNvdata** |  |
| Global | **variable definitions** |  |
| EFI_HANDLE | **gImageHandle = NULL;** |  |
| Internal | **Memory Operations (replacement for BaseMemoryLib)** |  |
| Zero | **out 8 bytes at a time for alignment** |  |
| Library | **Wrappers (self-contained, with debug assertions)** |  |
| String | **Operations** |  |
| Linked | **List Operations** |  |
| Debug | **and Assert Functions** |  |
| Print | **assertion information** |  |
| SnpDebugPrint | **(** |  |
| Deadlock | **to indicate fatal error** |  |
| while | **(TRUE) {** |  |
| HOB | **and System Table Operations** |  |
| Find | **HOB list via system table configuration table** |  |
| HobList | **= NULL;** |  |
| Component | **Name Support** |  |
| Simple | **direct language comparison** |  |
| if | **(Language == NULL || SupportedLanguages == NULL) {** |  |
| Stub | **- languages are predefined** |  |
| Print | **Library** |  |
| Simplified | **print implementation that supports basic format specifiers.** |  |
| The | **full implementation would handle %s, %d, %x, %r, %a, etc.** |  |
| if | **(gSystemTable != NULL && gSystemTable->ConOut != NULL) {** |  |
| Print | **status code as hex** |  |
| BufPtr | **+= SnpUtoA ((UINTN)Status, Buffer);** |  |
| Simplified | **SPrint - just copy format string for now** |  |
| if | **(Buffer != NULL && Format != NULL && BufferSize > 0) {** |  |
| Callback | **Management** |  |
| Check | **if callback already exists** |  |
| Entry | **= (CALLBACK_ENTRY *)Snp->CallbackList.ForwardLink;** |  |
| Allocate | **and add new callback entry** |  |
| Entry | **= (CALLBACK_ENTRY *)SnpAllocatePool (sizeof (CALLBACK_ENTRY));** |  |
| Find | **and remove callback entry** |  |
| Fire | **all registered callbacks** |  |
| CALLBACK_ENTRY | ***Entry;** |  |
| ACPI | **I/O Callbacks** |  |
| Lock | **acquire/release using EFI TPL** |  |
| if | **(Acquire) {** |  |
| Determine | **the access size** |  |
| switch | **((UINT8)AddressSize) {** |  |
| Perform | **I/O read or write via the ACPI IO protocol** |  |
| if | **(Snp->AcpiIo != NULL) {** |  |
| Map | **direction** |  |
| switch | **(Direction) {** |  |
| Write | **break;** |  |
| Default | **to ReadWrite** |  |
| Find | **a free entry in the map list** |  |
| for | **(Index = 0; Index < SNP_MAP_LIST_MAX; Index++) {** |  |
| Store | **the mapping** |  |
| Use | **ACPI IO protocol to map for DMA** |  |
| Find | **the entry and unmap** |  |
| Copy | **data between buffers for coherency** |  |
| if | **(HostAddress != 0 && Length > 0) {** |  |
| Flush | **the data cache** |  |
| UNDI | **Command Helper** |  |
| Timer | **Callback** |  |
| Set | **up CDB for GET_STATUS** |  |
| Clear | **the DB buffer** |  |
| SnpZeroMem | **(Snp->DbAddr, 8);** |  |
| Execute | **the UNDI GET_STATUS command** |  |
| Check | **interrupt status** |  |
| if | **(Snp->Cdb.OpStatus == 0) {** |  |
| Copy | **the status from DB buffer** |  |
| SnpCopyMem | **(&InterruptStatus, Snp->DbAddr, sizeof (InterruptStatus));** |  |
| Signal | **the event to indicate data is available** |  |
| Save | **global pointers** |  |
| gImageHandle | **= ImageHandle;** |  |
| Get | **image protection cookie** |  |
| SnpGetImageProtectionCookie | **(ImageHandle);** |  |
| Install | **the driver binding protocol and component name protocol** |  |
| Status | **= gBootServices->InstallMultipleProtocolInterfaces (** |  |
| Global | **driver binding protocol instance** |  |
| EFI_DRIVER_BINDING_PROTOCOL | **gSnpDriverBinding = {** |  |
| Version | **NULL,     // ImageHandle (filled at runtime)** |  |
| ControllerHandle | **(filled at runtime)** |  |
| Global | **component name 2 protocol instance** |  |
| EFI_COMPONENT_NAME2_PROTOCOL | **gComponentName2 = {** |  |
| Read | **"NetworkStackVar" from UEFI Runtime Services** |  |
| Status | **= gRuntimeServices->GetVariable (** |  |
| Write | **CMOS registers for network control** |  |
| CMOS | **port 0x5F, 0x5E, 0x5D - network stack control** |  |
| __outbyte | **(0x72, 0x5F);** |  |
| Network | **stack is enabled - install driver binding** |  |
| Network | **stack is disabled** |  |
| return | **EFI_NOT_FOUND;** |  |
| Find | **all handles that have the SNP protocol installed** |  |
| Reinstall | **the protocol to notify drivers** |  |
| First | **notify that interface identifier changed** |  |
| SnpNotifyNetworkInterfaceIdentifier | **(NULL, NULL);** |  |
| Then | **trigger legacy boot shutdown** |  |
| SnpCreateLegacyBootEvent | **();** |  |
| For | **the SNP driver, child creation is handled within SnpStart** |  |
| This | **function is a stub for completeness** |  |
| return | **EFI_UNSUPPORTED;** |  |
| Try | **to open the ACPI IO protocol** |  |
| Status | **= gBootServices->OpenProtocol (** |  |
| Get | **the network interface identifier** |  |
| Validate | **the !PXE structure** |  |
| Pxe | **= (EFI_PXE_BASE_CODE_PROTOCOL *)PxeDb;** |  |
| Check | **!PXE structure at IdPtr** |  |
| if | **(((UINTN)PxeDb->IdPtr & 0xF) != 0) {** |  |
| Close | **the protocols we opened for validation** |  |
| Open | **ACPI IO protocol** |  |
| Allocate | **SNP_DRIVER structure** |  |
| Status | **= gBootServices->AllocatePool (** |  |
| Zero | **the structure** |  |
| SnpZeroMem | **(Snp, sizeof (SNP_DRIVER));** |  |
| Save | **ACPI IO pointer** |  |
| Set | **up the SNP protocol function table** |  |
| Set | **up Mode fields** |  |
| Typical | **Ethernet header size** |  |
| Typical | **Ethernet MTU** |  |
| Set | **Upcall function to issue HW UNDI commands** |  |
| Register | **for network interface identifier changes** |  |
| Status | **= gBootServices->CreateEvent (** |  |
| Install | **SNP protocol on the controller** |  |
| Status | **= gBootServices->InstallProtocolInterface (** |  |
| Open | **SNP protocol to get the driver instance** |  |
| Destroy | **child callbacks** |  |
| SnpDestroyChild | **(ControllerHandle);** |  |
| Uninstall | **SNP protocol** |  |
| Status | **= gBootServices->UninstallProtocolInterface (** |  |
| Close | **timer events** |  |
| if | **(Snp->TimerEvent != NULL) {** |  |
| Close | **protocols** |  |
| Shutdown | **and stop the UNDI** |  |
| SnpShutdownInternal | **(Snp);** |  |
| Free | **ACPI IO buffer** |  |
| Free | **the driver instance** |  |
| Build | **"SNP (MAC=" prefix** |  |
| Offset | **= SnpUtoA ((UINTN)NameBuffer, 0xA0, L"SNP (MAC=");** |  |
| Append | **MAC address bytes in hex format** |  |
| for | **(Index = 0; Index < Snp->HwAddressSize; Index++) {** |  |
| Replace | **trailing '-' with ')'** |  |
| Store | **the name for retrieval (simplified)** |  |
| return | **EFI_SUCCESS;** |  |
| Open | **the SNP protocol on the controller** |  |
| Set | **up the CDB** |  |
| If | **PxeInit was previously called, set up the ACPI I/O function table** |  |
| if | **(Snp->PxeInitCalled) {** |  |
| Register | **the ACPI I/O callbacks** |  |
| Execute | **the UNDI START command** |  |
| Update | **state to STARTED** |  |
| Call | **the start entry** |  |
| EFI_STATUS | **Status;** |  |
| Clear | **the map list** |  |
| Set | **up the CDB for STOP** |  |
| Execute | **the UNDI STOP command** |  |
| Update | **state to STOPPED** |  |
| Allocate | **shared memory buffer if needed** |  |
| if | **(MemSize != 0) {** |  |
| Fill | **CPB** |  |
| Cpb | **= (SNP_CPB_INITIALIZE *)Snp->CpbAddr;** |  |
| Execute | **the UNDI INITIALIZE command** |  |
| Free | **the allocated buffer on failure** |  |
| if | **(Snp->CpbAddr != NULL) {** |  |
| Update | **MediaPresent based on link status** |  |
| if | **(RxFilter == 0) {** |  |
| Update | **state to INITIALIZED** |  |
| Check | **state** |  |
| if | **(Snp->UndiState == SNP_STATE_STOPPED) {** |  |
| Create | **timer event for polling received frames** |  |
| Clear | **receive filter setting and multicast filter count** |  |
| Clear | **multicast filter buffer** |  |
| SnpZeroMem | **(Snp->MCastFilter, sizeof (Snp->MCastFilter));** |  |
| Copy | **permanent MAC address to current address** |  |
| SnpCopyMem | **(Snp->CurrentAddress, Snp->PermAddress, Snp->HwAddressSize);** |  |
| Set | **total memory size** |  |
| Initialize | **with no filter first** |  |
| if | **(Snp->MediaPresentSupported) {** |  |
| RxFilter | **= 1 (basic filter)** |  |
| Start | **the timer for periodic polling** |  |
| Status | **= gBootServices->SetTimer (** |  |
| 500ms | **interval** |  |
| If | **media present supported, get initial status** |  |
| Set | **up the CDB for RESET** |  |
| Execute | **the UNDI RESET command** |  |
| Set | **up the CDB for SHUTDOWN** |  |
| Execute | **the UNDI SHUTDOWN command** |  |
| Free | **the ACPI memory buffer** |  |
| if | **(Snp->CpbAddr != NULL && Snp->AcpiIo != NULL) {** |  |
| Shutdown | **the UNDI** |  |
| Clear | **multicast filter count and receive filter setting** |  |
| Clear | **multicast addresses** |  |
| Copy | **permanent address back to current address** |  |
| Close | **timer event** |  |
| Set | **up the CDB for RECEIVE_FILTERS with enable flags** |  |
| Map | **filter bits to UNDI flags:** |  |
| BIT0 | **= UNICAST** |  |
| BIT1 | **= MULTICAST** |  |
| BIT2 | **= BROADCAST** |  |
| BIT3 | **= PROMISCUOUS** |  |
| BIT4 | **= PROMISCUOUS_MULTICAST** |  |
| SnpDebugPrint | **(0x4000, "\nsnp->undi.receive_filters()  ");** |  |
| Execute | **the UNDI RECEIVE_FILTERS command** |  |
| Set | **up the CDB for RECEIVE_FILTERS with disable flags** |  |
| Update | **software state** |  |
| Read | **back current filter settings from HW** |  |
| SNP_CDB | ***Cdb;** |  |
| Issue | **a RECEIVE_FILTERS command to read settings** |  |
| Execute | **the UNDI command** |  |
| Copy | **the multicast filter data back from the hardware** |  |
| if | **(Cdb->StatCount > 0) {** |  |
| Validate | **filter flags against supported mask** |  |
| if | **((~Snp->ReceiveFilterMask & Enable) != 0 || (~Snp->ReceiveFilterMask & Disable) != 0) {** |  |
| if | **(Enable == 0 && Disable == 0 && !ResetMCastFilter && MCastFilterCnt == 0) {** |  |
| Require | **multicast filter data when enabling multicast** |  |
| if | **((Enable & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0 && MCastFilterCnt == 0) {** |  |
| Enable | **filters** |  |
| if | **(Enable != 0 || MCastFilterCnt > 0) {** |  |
| if | **(Disable != 0 || ResetMCastFilter) {** |  |
| Read | **back and update filter settings** |  |
| return | **SnpReceiveFiltersSet (Snp);** |  |
| Set | **up CDB to read station address** |  |
| Execute | **the UNDI STATION_ADDR command** |  |
| Set | **up CDB to write station address** |  |
| Write | **operation** |  |
| Now | **read back the address to verify** |  |
| Restore | **permanent address to current address** |  |
| SnpCopyMem | **(Snp->CurrentAddress, New, Snp->HwAddressSize);** |  |
| Reset | **statistics** |  |
| Execute | **the UNDI STATISTICS command** |  |
| if | **(StatisticsTable != NULL) {** |  |
| Translate | **UNDI statistics to EFI_NETWORK_STATISTICS format** |  |
| Count | **= 0;** |  |
| Update | **remaining supported entries** |  |
| for | **(UINTN Index = Count + 1; Index < 0x40; Index++) {** |  |
| 520 | **bytes = full statistics block** |  |
| Update | **MediaPresent based on link state** |  |
| if | **((Cdb->StatFlags & SNP_STATUS_LINK_UP_BIT) != 0) {** |  |
| if | **(GetTxBuf && Cdb->StatCount > 0) {** |  |
| Recycle | **TX buffers (max SNP_TX_BUFFER_MAX)** |  |
| UINT32 | **Count;** |  |
| If | **TxBuf is requested and no recycled buffers are pending** |  |
| do | **a hardware GET_STATUS to check for TX completions** |  |
| BOOLEAN | **CheckTxBuf;** |  |
| Status | **= EFI_DEVICE_ERROR;** |  |
| Set | **source and destination addresses in the data block** |  |
| if | **(SrcAddr != NULL) {** |  |
| Cdb | **= &Snp->Cdb;** |  |
| Special | **fill header flags** |  |
| Execute | **the UNDI FILL_HEADER command** |  |
| Execute | **the UNDI TRANSMIT command** |  |
| If | **HeaderSize > 0, fill the header first** |  |
| if | **(HeaderSize > 0) {** |  |
| return | **SnpTransmitInternal (Snp, Buffer, BufferSize);** |  |
| Cpb | **= (VOID *)(UINTN)Snp->CpbAddr;** |  |
| Execute | **the UNDI RECEIVE command** |  |
| Update | **MediaPresent flag** |  |
| if | **(Snp->MediaPresentSupported && !Snp->MediaPresent) {** |  |
| if | **(ReceivedSize < *BufferSize) {** |  |
| Execute | **the UNDI MCAST_IP_TO_MAC command** |  |
| if | **(Snp == NULL || Buffer == NULL || BufferSize == 0) {** |  |
| Execute | **the UNDI NVDATA command** |  |
| if | **(Buffer == NULL || BufferSize == 0) {** |  |
| if | **(Offset + BufferSize > SNP_NVDATA_SIZE) {** |  |

---
*Generated by HR650X BIOS Decompilation Project*