]> git.proxmox.com Git - mirror_edk2.git/commitdiff
InOsEmuPkg: Update code to support BerkeleyPacketFilter, and add a template for Linux...
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 15 Jun 2011 18:51:30 +0000 (18:51 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 15 Jun 2011 18:51:30 +0000 (18:51 +0000)
BerkelyPacketFilter seems to work. Some one else will need to use the BerkeleyPacketFilter as a template and implement the LinuxPacketFilter. I don't think it will be that hard, as they are simular.

Signed-off-by: andrewfish
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11828 6f19259b-4bc3-4df7-8a09-765794883524

InOsEmuPkg/InOsEmuPkg.dec
InOsEmuPkg/Include/Protocol/EmuSnp.h
InOsEmuPkg/Unix/Sec/BerkeleyPacketFilter.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/BlockIo.c
InOsEmuPkg/Unix/Sec/Gasket.h
InOsEmuPkg/Unix/Sec/LinuxPacketFilter.c [new file with mode: 0644]
InOsEmuPkg/Unix/Sec/SecMain.c
InOsEmuPkg/Unix/Sec/SecMain.h
InOsEmuPkg/Unix/Sec/SecMain.inf
InOsEmuPkg/Unix/Sec/X64/Gasket.S
InOsEmuPkg/Unix/UnixX64.dsc

index 7b1bb38c3698cc505947ac08db2722052b38507d..33510406cc699c54d4c500bbd59c7fe07e097dd0 100644 (file)
   ## Magic page to implement PEI Services Table Pointer Lib\r
   gInOsEmuPkgTokenSpaceGuid.PcdPeiServicesTablePage|0x1000000000|UINT64|0x0000101b\r
 \r
+  ## Size of the packet filter\r
+  gInOsEmuPkgTokenSpaceGuid.PcdNetworkPacketFilterSize|524288|UINT32|0x0000101c\r
+\r
+  \r
+\r
 [PcdsFixedAtBuild, PcdsPatchableInModule] \r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006\r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009\r
index 2659c508621af7d7bcf47172db83597123e13c42..fc8e24cfde8b19e54b6d4ce97446a001f8344204 100644 (file)
@@ -18,6 +18,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef __EMU_SNP_H__\r
 #define __EMU_SNP_H__\r
 \r
+#include <Protocol/SimpleNetwork.h>\r
+\r
 #define EMU_SNP_PROTOCOL_GUID \\r
  { 0xFD5FBE54, 0x8C35, 0xB345, { 0x8A, 0x0F, 0x7A, 0xC8, 0xA5, 0xFD, 0x05, 0x21 } }\r
 \r
@@ -25,13 +27,12 @@ typedef struct _EMU_SNP_PROTOCOL  EMU_SNP_PROTOCOL;
 \r
 \r
 /**\r
-  Changes the state of a network interface from "stopped" to "started".\r
+  Register storage for SNP Mode.\r
 \r
   @param  This Protocol instance pointer.\r
   @param  Mode SimpleNetworkProtocol Mode structure passed into driver.\r
 \r
   @retval EFI_SUCCESS           The network interface was started.\r
-  @retval EFI_ALREADY_STARTED   The network interface is already mapped.\r
   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
 \r
 **/\r
@@ -109,8 +110,8 @@ typedef
 EFI_STATUS\r
 (EFIAPI *EMU_SNP_INITIALIZE)(\r
   IN EMU_SNP_PROTOCOL                    *This,\r
-  IN UINTN                                          ExtraRxBufferSize  OPTIONAL,\r
-  IN UINTN                                          ExtraTxBufferSize  OPTIONAL\r
+  IN UINTN                               ExtraRxBufferSize  OPTIONAL,\r
+  IN UINTN                               ExtraTxBufferSize  OPTIONAL\r
   );\r
 \r
 /**\r
@@ -133,7 +134,7 @@ typedef
 EFI_STATUS\r
 (EFIAPI *EMU_SNP_RESET)(\r
   IN EMU_SNP_PROTOCOL   *This,\r
-  IN BOOLEAN                       ExtendedVerification\r
+  IN BOOLEAN            ExtendedVerification\r
   );\r
 \r
 /**\r
@@ -183,11 +184,11 @@ typedef
 EFI_STATUS\r
 (EFIAPI *EMU_SNP_RECEIVE_FILTERS)(\r
   IN EMU_SNP_PROTOCOL                             *This,\r
-  IN UINT32                                                  Enable,\r
-  IN UINT32                                                  Disable,\r
-  IN BOOLEAN                                                 ResetMCastFilter,\r
-  IN UINTN                                                   MCastFilterCnt     OPTIONAL,\r
-  IN EFI_MAC_ADDRESS                                         *MCastFilter OPTIONAL\r
+  IN UINT32                                       Enable,\r
+  IN UINT32                                       Disable,\r
+  IN BOOLEAN                                      ResetMCastFilter,\r
+  IN UINTN                                        MCastFilterCnt     OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                              *MCastFilter OPTIONAL\r
   );\r
 \r
 /**\r
@@ -209,8 +210,8 @@ typedef
 EFI_STATUS\r
 (EFIAPI *EMU_SNP_STATION_ADDRESS)(\r
   IN EMU_SNP_PROTOCOL            *This,\r
-  IN BOOLEAN                                Reset,\r
-  IN EFI_MAC_ADDRESS                        *New OPTIONAL\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *New OPTIONAL\r
   );\r
 \r
 /**\r
diff --git a/InOsEmuPkg/Unix/Sec/BerkeleyPacketFilter.c b/InOsEmuPkg/Unix/Sec/BerkeleyPacketFilter.c
new file mode 100644 (file)
index 0000000..519d394
--- /dev/null
@@ -0,0 +1,1111 @@
+/**@file\r
+ Berkeley Packet Filter implementation of the EMU_SNP_PROTOCOL that allows the \r
+ emulator to get on real networks.\r
+\r
+ Tested on Mac OS X. \r
+\r
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portitions copyright (c) 2011, Apple Inc. All rights reserved.\r
+\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+#include "SecMain.h"\r
+\r
+#ifdef __APPLE__\r
+\r
+\r
+#include <Library/NetLib.h>\r
+\r
+\r
+#define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+\r
+  EMU_IO_THUNK_PROTOCOL       *Thunk;\r
+  EMU_SNP_PROTOCOL            EmuSnp;\r
+  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
+\r
+  int                         BpfFd;\r
+  char                        *InterfaceName;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  u_int                       ReadBufferSize;\r
+  VOID                        *ReadBuffer;\r
+\r
+  //\r
+  // Two walking pointers to manage the multiple packets that can be returned\r
+  // in a single read.\r
+  //\r
+  VOID                        *CurrentReadPointer;\r
+  VOID                        *EndReadPointer;\r
+\r
+       UINT32                                                                      ReceivedPackets;\r
+       UINT32                                                                      DroppedPackets;\r
+\r
+} EMU_SNP_PRIVATE;\r
+\r
+#define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)\r
+\r
+\r
+//\r
+// Strange, but there doesn't appear to be any structure for the Ethernet header in edk2...\r
+//\r
+\r
+typedef struct {\r
+  UINT8   DstAddr[NET_ETHER_ADDR_LEN];\r
+  UINT8   SrcAddr[NET_ETHER_ADDR_LEN];\r
+  UINT16  Type;\r
+} ETHERNET_HEADER;\r
+\r
+/**\r
+  Register storage for SNP Mode.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Mode SimpleNetworkProtocol Mode structure passed into driver.\r
+\r
+  @retval EFI_SUCCESS           The network interface was started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpCreateMapping (\r
+  IN     EMU_SNP_PROTOCOL         *This,\r
+  IN     EFI_SIMPLE_NETWORK_MODE  *Mode\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Private->Mode = Mode;\r
+  \r
+  //\r
+  // Set the broadcast address.\r
+  //\r
+  SetMem (&Mode->BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);\r
+\r
+  CopyMem (&Mode->CurrentAddress, &Private->MacAddress, sizeof (EFI_MAC_ADDRESS));\r
+  CopyMem (&Mode->PermanentAddress, &Private->MacAddress, sizeof (EFI_MAC_ADDRESS));\r
+\r
+  //\r
+  // Since the fake SNP is based on a real NIC, to avoid conflict with the host NIC\r
+  // network stack, we use a different MAC address.\r
+  // So just change the last byte of the MAC address for the real NIC.\r
+  //\r
+  Mode->CurrentAddress.Addr[NET_ETHER_ADDR_LEN - 1]++;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+static struct bpf_insn mFilterInstructionTemplate[] = {\r
+  // Load 4 bytes from the destination MAC address.\r
+  BPF_STMT (BPF_LD + BPF_W + BPF_ABS, OFFSET_OF (ETHERNET_HEADER, DstAddr[0])),\r
+\r
+  // Compare to first 4 bytes of fake MAC address.\r
+  BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, 0x12345678, 0, 3 ),\r
+\r
+  // Load remaining 2 bytes from the destination MAC address.\r
+  BPF_STMT (BPF_LD + BPF_H + BPF_ABS, OFFSET_OF( ETHERNET_HEADER, DstAddr[4])),\r
+\r
+  // Compare to remaining 2 bytes of fake MAC address.\r
+  BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, 0x9ABC, 5, 0 ),\r
+\r
+  // Load 4 bytes from the destination MAC address.\r
+  BPF_STMT (BPF_LD + BPF_W + BPF_ABS, OFFSET_OF (ETHERNET_HEADER, DstAddr[0])),\r
+\r
+  // Compare to first 4 bytes of broadcast MAC address.\r
+  BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, 0xFFFFFFFF, 0, 2),\r
+\r
+  // Load remaining 2 bytes from the destination MAC address.\r
+  BPF_STMT (BPF_LD + BPF_H + BPF_ABS, OFFSET_OF( ETHERNET_HEADER, DstAddr[4])),\r
+\r
+  // Compare to remaining 2 bytes of broadcast MAC address.\r
+  BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, 0xFFFF, 1, 0),\r
+\r
+  // Reject packet.\r
+  BPF_STMT (BPF_RET + BPF_K, 0),\r
+\r
+  // Receive entire packet.\r
+  BPF_STMT (BPF_RET + BPF_K, -1)\r
+};\r
+\r
+\r
+EFI_STATUS\r
+OpenBpfFileDescriptor (\r
+  IN EMU_SNP_PRIVATE  *Private,\r
+  OUT int             *Fd\r
+  )\r
+{\r
+  char  BfpDeviceName[256];\r
+  int   Index;\r
+\r
+  //\r
+  // Open a Berkeley Packet Filter device.  This must be done as root, so this is probably\r
+  // the place which is most likely to fail...\r
+  //\r
+  for (Index = 0; TRUE; Index++ ) {\r
+    snprintf (BfpDeviceName, sizeof (BfpDeviceName), "/dev/bpf%d", Index);\r
+\r
+    *Fd = open (BfpDeviceName, O_RDWR, 0);\r
+    if ( *Fd >= 0 ) {\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    if (errno == EACCES) {\r
+      printf (\r
+        "SNP: Permissions on '%s' are incorrect.  Fix with 'sudo chmod 666 %s'.\n",\r
+        BfpDeviceName, \r
+        BfpDeviceName \r
+        );\r
+    }\r
+    \r
+    if (errno != EBUSY) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_OUT_OF_RESOURCES;\r
+}\r
+\r
+\r
+/**\r
+  Changes the state of a network interface from "stopped" to "started".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was started.\r
+  @retval EFI_ALREADY_STARTED   The network interface is already in the started state.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStart (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  EMU_SNP_PRIVATE    *Private;\r
+  struct ifreq       BoundIf;\r
+  struct bpf_program BpfProgram;\r
+  struct bpf_insn    *FilterProgram;\r
+       u_int                                                    Value;\r
+       u_int                                            ReadBufferSize;\r
+  UINT16             Temp16;\r
+  UINT32             Temp32;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  switch (Private->Mode->State) {\r
+    case EfiSimpleNetworkStopped:\r
+      break;\r
+\r
+    case EfiSimpleNetworkStarted:\r
+    case EfiSimpleNetworkInitialized:\r
+      return EFI_ALREADY_STARTED;\r
+      break;\r
+\r
+    default:\r
+      return EFI_DEVICE_ERROR;\r
+      break;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  if (Private->BpfFd == 0) {\r
+    Status = OpenBpfFileDescriptor (Private, &Private->BpfFd);\r
+    if (EFI_ERROR (Status)) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    //\r
+               // Get the read buffer size.\r
+               //\r
+               if (ioctl (Private->BpfFd, BIOCGBLEN, &ReadBufferSize) < 0) {\r
+                       goto DeviceErrorExit;\r
+               }\r
+               \r
+               //\r
+               // Default value from BIOCGBLEN is usually too small, so use a much larger size, if necessary.\r
+               //\r
+               if (ReadBufferSize < FixedPcdGet32 (PcdNetworkPacketFilterSize)) {\r
+                       ReadBufferSize = FixedPcdGet32 (PcdNetworkPacketFilterSize);\r
+                       if (ioctl (Private->BpfFd, BIOCSBLEN, &ReadBufferSize) < 0) {\r
+                               goto DeviceErrorExit;\r
+                       }\r
+               }\r
+               \r
+               //\r
+    // Associate our interface with this BPF file descriptor.\r
+    //\r
+    AsciiStrCpy (BoundIf.ifr_name, Private->InterfaceName);\r
+    if (ioctl (Private->BpfFd, BIOCSETIF, &BoundIf) < 0) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    //\r
+               // Enable immediate mode.\r
+    //\r
+    Value = 1;\r
+    if (ioctl (Private->BpfFd, BIOCIMMEDIATE, &Value) < 0) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    //\r
+    // Enable non-blocking I/O.\r
+    //\r
+    if (fcntl (Private->BpfFd, F_GETFL, 0) == -1) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    Value |= O_NONBLOCK;\r
+\r
+    if (fcntl (Private->BpfFd, F_SETFL, Value) == -1) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    //\r
+    // Disable "header complete" flag.  This means the supplied source MAC address is\r
+    // what goes on the wire.\r
+    //\r
+    Value = 1;\r
+    if (ioctl (Private->BpfFd, BIOCSHDRCMPLT, &Value) < 0) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    //\r
+    // Allocate read buffer.\r
+    //\r
+               Private->ReadBufferSize = ReadBufferSize;\r
+               Private->ReadBuffer = malloc (Private->ReadBufferSize);\r
+    if (Private->ReadBuffer == NULL) {\r
+      goto ErrorExit;\r
+    }\r
+\r
+    Private->CurrentReadPointer = Private->EndReadPointer = Private->ReadBuffer;\r
+\r
+    //\r
+               // Install our packet filter: successful reads should only produce broadcast or unicast\r
+    // packets directed to our fake MAC address.\r
+    //\r
+    FilterProgram = malloc (sizeof (mFilterInstructionTemplate)) ;\r
+    if ( FilterProgram == NULL ) {\r
+      goto ErrorExit;\r
+    }\r
+    \r
+    CopyMem (FilterProgram, &mFilterInstructionTemplate, sizeof (mFilterInstructionTemplate));\r
+\r
+    //\r
+    // Insert out fake MAC address into the filter.  The data has to be host endian.\r
+    //\r
+    CopyMem (&Temp32, &Private->Mode->CurrentAddress.Addr[0], sizeof (UINT32));\r
+    FilterProgram[1].k = NTOHL (Temp32);\r
+    CopyMem (&Temp16, &Private->Mode->CurrentAddress.Addr[4], sizeof (UINT16));\r
+    FilterProgram[3].k = NTOHS (Temp16);\r
+\r
+    BpfProgram.bf_len = sizeof (mFilterInstructionTemplate) / sizeof (struct bpf_insn);\r
+    BpfProgram.bf_insns = FilterProgram;\r
+\r
+    if (ioctl (Private->BpfFd, BIOCSETF, &BpfProgram) < 0) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+    free (FilterProgram);\r
+\r
+    //\r
+    // Enable promiscuous mode.\r
+    //\r
+    if (ioctl (Private->BpfFd, BIOCPROMISC, 0) < 0) {\r
+      goto DeviceErrorExit;\r
+    }\r
+\r
+\r
+    Private->Mode->State = EfiSimpleNetworkStarted;      \r
+  }\r
+\r
+  return Status;\r
+\r
+DeviceErrorExit:\r
+  Status = EFI_DEVICE_ERROR;\r
+ErrorExit:\r
+  if (Private->ReadBuffer != NULL) {\r
+    free (Private->ReadBuffer);\r
+    Private->ReadBuffer = NULL;\r
+  }\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Changes the state of a network interface from "started" to "stopped".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was stopped.\r
+  @retval EFI_ALREADY_STARTED   The network interface is already in the stopped state.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStop (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  switch ( Private->Mode->State ) {\r
+    case EfiSimpleNetworkStarted:\r
+      break;\r
+\r
+    case EfiSimpleNetworkStopped:\r
+      return EFI_NOT_STARTED;\r
+      break;\r
+\r
+    default:\r
+      return EFI_DEVICE_ERROR;\r
+      break;\r
+  }\r
+\r
+  if (Private->BpfFd != 0) {\r
+    close (Private->BpfFd);\r
+    Private->BpfFd = 0;\r
+  }\r
+\r
+  if (Private->ReadBuffer != NULL) {\r
+    free (Private->ReadBuffer );\r
+    Private->CurrentReadPointer = Private->EndReadPointer = Private->ReadBuffer = NULL;\r
+  }\r
+\r
+  Private->Mode->State = EfiSimpleNetworkStopped;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Resets a network adapter and allocates the transmit and receive buffers \r
+  required by the network interface; optionally, also requests allocation \r
+  of additional transmit and receive buffers.\r
+\r
+  @param  This              The protocol instance pointer.\r
+  @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+  @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+\r
+  @retval EFI_SUCCESS           The network interface was initialized.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_OUT_OF_RESOURCES  There was not enough memory for the transmit and\r
+                                receive buffers.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpInitialize (\r
+  IN EMU_SNP_PROTOCOL                    *This,\r
+  IN UINTN                               ExtraRxBufferSize  OPTIONAL,\r
+  IN UINTN                               ExtraTxBufferSize  OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  switch ( Private->Mode->State ) {\r
+    case EfiSimpleNetworkStarted:\r
+      break;\r
+\r
+    case EfiSimpleNetworkStopped:\r
+      return EFI_NOT_STARTED;\r
+      break;\r
+\r
+    default:\r
+      return EFI_DEVICE_ERROR;\r
+      break;\r
+  }\r
+\r
+  Private->Mode->MCastFilterCount = 0;\r
+  Private->Mode->ReceiveFilterSetting = 0;\r
+  ZeroMem (Private->Mode->MCastFilter, sizeof (Private->Mode->MCastFilter));\r
+\r
+  Private->Mode->State = EfiSimpleNetworkInitialized;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Resets a network adapter and re-initializes it with the parameters that were \r
+  provided in the previous call to Initialize().  \r
+\r
+  @param  This                 The protocol instance pointer.\r
+  @param  ExtendedVerification Indicates that the driver may perform a more\r
+                               exhaustive verification operation of the device\r
+                               during reset.\r
+\r
+  @retval EFI_SUCCESS           The network interface was reset.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReset (\r
+  IN EMU_SNP_PROTOCOL   *This,\r
+  IN BOOLEAN            ExtendedVerification\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  switch ( Private->Mode->State ) {\r
+    case EfiSimpleNetworkInitialized:\r
+      break;\r
+\r
+    case EfiSimpleNetworkStopped:\r
+      return EFI_NOT_STARTED;\r
+      break;\r
+\r
+    default:\r
+      return EFI_DEVICE_ERROR;\r
+      break;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Resets a network adapter and leaves it in a state that is safe for \r
+  another driver to initialize.\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was shutdown.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpShutdown (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  switch ( Private->Mode->State ) {\r
+    case EfiSimpleNetworkInitialized:\r
+      break;\r
+\r
+    case EfiSimpleNetworkStopped:\r
+      return EFI_NOT_STARTED;\r
+      break;\r
+\r
+    default:\r
+      return EFI_DEVICE_ERROR;\r
+      break;\r
+  }\r
+\r
+  Private->Mode->State = EfiSimpleNetworkStarted;\r
+\r
+  Private->Mode->ReceiveFilterSetting = 0;\r
+  Private->Mode->MCastFilterCount = 0;\r
+  ZeroMem (Private->Mode->MCastFilter, sizeof (Private->Mode->MCastFilter));\r
+\r
+  if (Private->BpfFd != 0) {\r
+    close (Private->BpfFd);\r
+    Private->BpfFd = 0;\r
+  }\r
+\r
+  if (Private->ReadBuffer != NULL) {\r
+    free (Private->ReadBuffer);\r
+    Private->CurrentReadPointer = Private->EndReadPointer = Private->ReadBuffer = NULL;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Manages the multicast receive filters of a network interface.\r
+\r
+  @param  This             The protocol instance pointer.\r
+  @param  Enable           A bit mask of receive filters to enable on the network interface.\r
+  @param  Disable          A bit mask of receive filters to disable on the network interface.\r
+  @param  ResetMCastFilter Set to TRUE to reset the contents of the multicast receive\r
+                           filters on the network interface to their default values.\r
+  @param  McastFilterCnt   Number of multicast HW MAC addresses in the new\r
+                           MCastFilter list. This value must be less than or equal to\r
+                           the MCastFilterCnt field of EMU_SNP_MODE. This\r
+                           field is optional if ResetMCastFilter is TRUE.\r
+  @param  MCastFilter      A pointer to a list of new multicast receive filter HW MAC\r
+                           addresses. This list will replace any existing multicast\r
+                           HW MAC address list. This field is optional if\r
+                           ResetMCastFilter is TRUE.\r
+\r
+  @retval EFI_SUCCESS           The multicast receive filter list was updated.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReceiveFilters (\r
+  IN EMU_SNP_PROTOCOL                             *This,\r
+  IN UINT32                                       Enable,\r
+  IN UINT32                                       Disable,\r
+  IN BOOLEAN                                      ResetMCastFilter,\r
+  IN UINTN                                        MCastFilterCnt     OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                              *MCastFilter OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  // For now, just succeed...\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Modifies or resets the current station address, if supported.\r
+\r
+  @param  This  The protocol instance pointer.\r
+  @param  Reset Flag used to reset the station address to the network interfaces\r
+                permanent address.\r
+  @param  New   The new station address to be used for the network interface.\r
+\r
+  @retval EFI_SUCCESS           The network interfaces station address was updated.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStationAddress (\r
+  IN EMU_SNP_PROTOCOL            *This,\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *New OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Resets or collects the statistics on a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Reset           Set to TRUE to reset the statistics for the network interface.\r
+  @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On\r
+                          output the size, in bytes, of the resulting table of\r
+                          statistics.\r
+  @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
+                          contains the statistics.\r
+\r
+  @retval EFI_SUCCESS           The statistics were collected from the network interface.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStatistics (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              Reset,\r
+  IN OUT UINTN                            *StatisticsSize   OPTIONAL,\r
+  OUT EFI_NETWORK_STATISTICS              *StatisticsTable  OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Converts a multicast IP address to a multicast HW MAC address.\r
+\r
+  @param  This The protocol instance pointer.\r
+  @param  IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
+               to FALSE if the multicast IP address is IPv4 [RFC 791].\r
+  @param  IP   The multicast IP address that is to be converted to a multicast\r
+               HW MAC address.\r
+  @param  MAC  The multicast HW MAC address that is to be generated from IP.\r
+\r
+  @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast\r
+                                HW MAC address.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpMCastIpToMac (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              IPv6,\r
+  IN EFI_IP_ADDRESS                       *IP,\r
+  OUT EFI_MAC_ADDRESS                     *MAC\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Performs read and write operations on the NVRAM device attached to a \r
+  network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  ReadWrite  TRUE for read operations, FALSE for write operations.\r
+  @param  Offset     Byte offset in the NVRAM device at which to start the read or\r
+                     write operation. This must be a multiple of NvRamAccessSize and\r
+                     less than NvRamSize.\r
+  @param  BufferSize The number of bytes to read or write from the NVRAM device.\r
+                     This must also be a multiple of NvramAccessSize.\r
+  @param  Buffer     A pointer to the data buffer.\r
+\r
+  @retval EFI_SUCCESS           The NVRAM access was performed.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpNvData (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              ReadWrite,\r
+  IN UINTN                                Offset,\r
+  IN UINTN                                BufferSize,\r
+  IN OUT VOID                             *Buffer\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Reads the current interrupt status and recycled transmit buffer status from \r
+  a network interface.\r
+\r
+  @param  This            The protocol instance pointer.\r
+  @param  InterruptStatus A pointer to the bit mask of the currently active interrupts\r
+                          If this is NULL, the interrupt status will not be read from\r
+                          the device. If this is not NULL, the interrupt status will\r
+                          be read from the device. When the  interrupt status is read,\r
+                          it will also be cleared. Clearing the transmit  interrupt\r
+                          does not empty the recycled transmit buffer array.\r
+  @param  TxBuf           Recycled transmit buffer address. The network interface will\r
+                          not transmit if its internal recycled transmit buffer array\r
+                          is full. Reading the transmit buffer does not clear the\r
+                          transmit interrupt. If this is NULL, then the transmit buffer\r
+                          status will not be read. If there are no transmit buffers to\r
+                          recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
+\r
+  @retval EFI_SUCCESS           The status of the network interface was retrieved.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpGetStatus (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINT32                              *InterruptStatus OPTIONAL,\r
+  OUT VOID                                **TxBuf OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (TxBuf != NULL) {\r
+    *((UINT8 **)TxBuf) =  (UINT8 *)1;\r
+  }\r
+\r
+  if ( InterruptStatus != NULL ) {\r
+    *InterruptStatus = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Places a packet in the transmit queue of a network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header to be filled in by\r
+                     the Transmit() function. If HeaderSize is non-zero, then it\r
+                     must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
+                     and Protocol parameters must not be NULL.\r
+  @param  BufferSize The size, in bytes, of the entire packet (media header and\r
+                     data) to be transmitted through the network interface.\r
+  @param  Buffer     A pointer to the packet (media header followed by data) to be\r
+                     transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
+                     then the media header in Buffer must already be filled in by the\r
+                     caller. If HeaderSize is non-zero, then the media header will be\r
+                     filled in by the Transmit() function.\r
+  @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter\r
+                     is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
+                     This->Mode->CurrentAddress is used for the source HW MAC address.\r
+  @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this\r
+                     parameter is ignored.\r
+  @param  Protocol   The type of header to build. If HeaderSize is zero, then this\r
+                     parameter is ignored. See RFC 1700, section "Ether Types", for\r
+                     examples.\r
+\r
+  @retval EFI_SUCCESS           The packet was placed on the transmit queue.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_NOT_READY         The network interface is too busy to accept this transmit request.                      \r
+  @retval EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpTransmit (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN UINTN                                HeaderSize,\r
+  IN UINTN                                BufferSize,\r
+  IN VOID                                 *Buffer,\r
+  IN EFI_MAC_ADDRESS                      *SrcAddr  OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                      *DestAddr OPTIONAL,\r
+  IN UINT16                               *Protocol OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+  ETHERNET_HEADER    *EnetHeader;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Private->Mode->State < EfiSimpleNetworkStarted) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  if ( HeaderSize != 0 ) {\r
+    if ((DestAddr == NULL) || (Protocol == NULL) || (HeaderSize != Private->Mode->MediaHeaderSize)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (SrcAddr == NULL) {\r
+      SrcAddr = &Private->Mode->CurrentAddress;\r
+    }\r
+\r
+    EnetHeader = (ETHERNET_HEADER *) Buffer;\r
+\r
+    CopyMem (EnetHeader->DstAddr, DestAddr, NET_ETHER_ADDR_LEN);\r
+    CopyMem (EnetHeader->SrcAddr, SrcAddr, NET_ETHER_ADDR_LEN);\r
+\r
+    EnetHeader->Type = HTONS(*Protocol);\r
+  }\r
+\r
+  if (write  (Private->BpfFd, Buffer, BufferSize) < 0) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Receives a packet from a network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header received on the network\r
+                     interface. If this parameter is NULL, then the media header size\r
+                     will not be returned.\r
+  @param  BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
+                     bytes, of the packet that was received on the network interface.\r
+  @param  Buffer     A pointer to the data buffer to receive both the media header and\r
+                     the data.\r
+  @param  SrcAddr    The source HW MAC address. If this parameter is NULL, the\r
+                     HW MAC source address will not be extracted from the media\r
+                     header.\r
+  @param  DestAddr   The destination HW MAC address. If this parameter is NULL,\r
+                     the HW MAC destination address will not be extracted from the\r
+                     media header.\r
+  @param  Protocol   The media header type. If this parameter is NULL, then the\r
+                     protocol will not be extracted from the media header. See\r
+                     RFC 1700 section "Ether Types" for examples.\r
+\r
+  @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has\r
+                                 been updated to the number of bytes received.\r
+  @retval  EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit\r
+                                 request.\r
+  @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval  EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval  EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReceive (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINTN                               *HeaderSize OPTIONAL,\r
+  IN OUT UINTN                            *BufferSize,\r
+  OUT VOID                                *Buffer,\r
+  OUT EFI_MAC_ADDRESS                     *SrcAddr    OPTIONAL,\r
+  OUT EFI_MAC_ADDRESS                     *DestAddr   OPTIONAL,\r
+  OUT UINT16                              *Protocol   OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+  struct bpf_hdr     *BpfHeader;\r
+       struct bpf_stat    BpfStats;\r
+  ETHERNET_HEADER    *EnetHeader;\r
+  ssize_t            Result;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Private->Mode->State < EfiSimpleNetworkStarted) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+       ZeroMem (&BpfStats, sizeof( BpfStats));\r
+       \r
+       if (ioctl (Private->BpfFd, BIOCGSTATS, &BpfStats) == 0) {\r
+               Private->ReceivedPackets += BpfStats.bs_recv;\r
+               if (BpfStats.bs_drop > Private->DroppedPackets) {\r
+                       printf (\r
+                         "SNP: STATS: RCVD = %d DROPPED = %d.  Probably need to increase BPF PcdNetworkPacketFilterSize?\n",\r
+                               BpfStats.bs_recv, \r
+                               BpfStats.bs_drop - Private->DroppedPackets\r
+                               );\r
+                       Private->DroppedPackets = BpfStats.bs_drop;\r
+               }\r
+       }\r
+\r
+  //\r
+  // Do we have any remaining packets from the previous read?\r
+  //\r
+  if (Private->CurrentReadPointer >= Private->EndReadPointer) {\r
+    Result = read (Private->BpfFd, Private->ReadBuffer, Private->ReadBufferSize);\r
+    if (Result < 0) {\r
+      // EAGAIN means that there's no I/O outstanding against this file descriptor.\r
+      return (errno == EAGAIN) ? EFI_NOT_READY : EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    if (Result == 0) {\r
+      return EFI_NOT_READY;\r
+    }\r
+\r
+    Private->CurrentReadPointer = Private->ReadBuffer;\r
+    Private->EndReadPointer = Private->CurrentReadPointer + Result;\r
+  }\r
+\r
+  BpfHeader = Private->CurrentReadPointer;\r
+  EnetHeader = Private->CurrentReadPointer + BpfHeader->bh_hdrlen;\r
+\r
+  if (BpfHeader->bh_caplen > *BufferSize) {\r
+    *BufferSize = BpfHeader->bh_caplen;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  CopyMem (Buffer, EnetHeader, BpfHeader->bh_caplen);\r
+  *BufferSize = BpfHeader->bh_caplen;\r
+\r
+  if (HeaderSize != NULL) {\r
+    *HeaderSize = sizeof (ETHERNET_HEADER);\r
+  }\r
+\r
+  if (DestAddr != NULL) {\r
+    ZeroMem (DestAddr, sizeof (EFI_MAC_ADDRESS));\r
+    CopyMem (DestAddr, EnetHeader->DstAddr, NET_ETHER_ADDR_LEN);\r
+  }\r
+\r
+  if (SrcAddr != NULL) {\r
+    ZeroMem (SrcAddr, sizeof (EFI_MAC_ADDRESS));\r
+    CopyMem (SrcAddr, EnetHeader->SrcAddr, NET_ETHER_ADDR_LEN);\r
+  }\r
+\r
+  if (Protocol != NULL) {\r
+    *Protocol = NTOHS (EnetHeader->Type);\r
+  }\r
+\r
+  Private->CurrentReadPointer += BPF_WORDALIGN (BpfHeader->bh_hdrlen + BpfHeader->bh_caplen);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EMU_SNP_PROTOCOL gEmuSnpProtocol = {\r
+  GasketSnpCreateMapping,\r
+  GasketSnpStart,\r
+  GasketSnpStop,\r
+  GasketSnpInitialize,\r
+  GasketSnpReset,\r
+  GasketSnpShutdown,\r
+  GasketSnpReceiveFilters,\r
+  GasketSnpStationAddress,\r
+  GasketSnpStatistics,\r
+  GasketSnpMCastIpToMac,\r
+  GasketSnpNvData,\r
+  GasketSnpGetStatus,\r
+  GasketSnpTransmit,\r
+  GasketSnpReceive\r
+};\r
+\r
+EFI_STATUS\r
+GetInterfaceMacAddr (\r
+  EMU_SNP_PRIVATE    *Private\r
+  )\r
+{\r
+       EFI_STATUS                                Status;\r
+  struct ifaddrs      *IfAddrs;\r
+  struct ifaddrs      *If;\r
+  struct sockaddr_dl  *IfSdl;\r
+\r
+  if (getifaddrs (&IfAddrs) != 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Convert the interface name to ASCII so we can find it.\r
+  //\r
+  Private->InterfaceName = malloc (StrSize (Private->Thunk->ConfigString));\r
+  if (Private->InterfaceName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  UnicodeStrToAsciiStr (Private->Thunk->ConfigString, Private->InterfaceName);\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  If = IfAddrs;\r
+  while (If != NULL) {\r
+    IfSdl = (struct sockaddr_dl *)If->ifa_addr;\r
+\r
+    if (IfSdl->sdl_family == AF_LINK) {\r
+      if (!AsciiStrCmp( Private->InterfaceName, If->ifa_name)) {\r
+        CopyMem (&Private->MacAddress, LLADDR (IfSdl), NET_ETHER_ADDR_LEN);\r
+\r
+        Status = EFI_SUCCESS;\r
+        break;\r
+      }\r
+    }\r
+\r
+    If = If->ifa_next;\r
+  }\r
+\r
+Exit:\r
+  freeifaddrs (IfAddrs);\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EmuSnpThunkOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE  *Private;\r
+  \r
+  if (This->Private != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+  \r
+  if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  Private = malloc (sizeof (EMU_SNP_PRIVATE));\r
+  if (Private == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  \r
+  Private->Signature = EMU_SNP_PRIVATE_SIGNATURE;\r
+  Private->Thunk     = This;\r
+  CopyMem (&Private->EmuSnp, &gEmuSnpProtocol, sizeof (gEmuSnpProtocol));\r
+  GetInterfaceMacAddr (Private);\r
+  \r
+  This->Interface = &Private->EmuSnp;\r
+  This->Private   = Private;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EmuSnpThunkClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE  *Private;\r
+\r
+  if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  Private = This->Private;\r
+  free (Private);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {\r
+  &gEmuSnpProtocolGuid,\r
+  NULL,\r
+  NULL,\r
+  0,\r
+  GasketSnpThunkOpen,\r
+  GasketSnpThunkClose,\r
+  NULL\r
+};\r
+\r
+#endif\r
index b764a6366031f4cfe8a99c0b90975d24518def13..61069e3987d1afda88bc43620e991abbca803ab4 100644 (file)
@@ -11,8 +11,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-//#include <fcntl.h>\r
-//#include <unistd.h>\r
 #include "SecMain.h"\r
 \r
 #define EMU_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('E', 'M', 'b', 'k')\r
index 5cc42dd575aceac21b017c10f7450f80264812d9..2234bbe8c691935583f43c8cf59e487afce8e0fd 100644 (file)
@@ -485,7 +485,139 @@ EFIAPI
 GasketBlockIoThunkClose (\r
   IN  EMU_IO_THUNK_PROTOCOL   *This\r
   );\r
-  \r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpThunkOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpThunkClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpCreateMapping (\r
+  IN     EMU_SNP_PROTOCOL         *This,\r
+  IN     EFI_SIMPLE_NETWORK_MODE  *Media\r
+  );\r
\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpStart (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpStop (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpInitialize (\r
+  IN EMU_SNP_PROTOCOL                    *This,\r
+  IN UINTN                               ExtraRxBufferSize  OPTIONAL,\r
+  IN UINTN                               ExtraTxBufferSize  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpReset (\r
+  IN EMU_SNP_PROTOCOL   *This,\r
+  IN BOOLEAN            ExtendedVerification\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpShutdown (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpReceiveFilters (\r
+  IN EMU_SNP_PROTOCOL                             *This,\r
+  IN UINT32                                       Enable,\r
+  IN UINT32                                       Disable,\r
+  IN BOOLEAN                                      ResetMCastFilter,\r
+  IN UINTN                                        MCastFilterCnt     OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                              *MCastFilter OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpStationAddress (\r
+  IN EMU_SNP_PROTOCOL            *This,\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *New OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpStatistics (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              Reset,\r
+  IN OUT UINTN                            *StatisticsSize   OPTIONAL,\r
+  OUT EFI_NETWORK_STATISTICS              *StatisticsTable  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpMCastIpToMac (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              IPv6,\r
+  IN EFI_IP_ADDRESS                       *IP,\r
+  OUT EFI_MAC_ADDRESS                     *MAC\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpNvData (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              ReadWrite,\r
+  IN UINTN                                Offset,\r
+  IN UINTN                                BufferSize,\r
+  IN OUT VOID                             *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpGetStatus (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINT32                              *InterruptStatus OPTIONAL,\r
+  OUT VOID                                **TxBuf OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpTransmit (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN UINTN                                HeaderSize,\r
+  IN UINTN                                BufferSize,\r
+  IN VOID                                 *Buffer,\r
+  IN EFI_MAC_ADDRESS                      *SrcAddr  OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                      *DestAddr OPTIONAL,\r
+  IN UINT16                               *Protocol OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GasketSnpReceive (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINTN                               *HeaderSize OPTIONAL,\r
+  IN OUT UINTN                            *BufferSize,\r
+  OUT VOID                                *Buffer,\r
+  OUT EFI_MAC_ADDRESS                     *SrcAddr    OPTIONAL,\r
+  OUT EFI_MAC_ADDRESS                     *DestAddr   OPTIONAL,\r
+  OUT UINT16                              *Protocol   OPTIONAL\r
+  );\r
+\r
\r
 #endif\r
 \r
 \r
diff --git a/InOsEmuPkg/Unix/Sec/LinuxPacketFilter.c b/InOsEmuPkg/Unix/Sec/LinuxPacketFilter.c
new file mode 100644 (file)
index 0000000..20a08c9
--- /dev/null
@@ -0,0 +1,604 @@
+/**@file\r
+ Linux Packet Filter implementation of the EMU_SNP_PROTOCOL that allows the \r
+ emulator to get on real networks.\r
+\r
+ Currently only the Berkeley Packet Filter is fully implemented and this file\r
+ is just a template that needs to get filled in. \r
+\r
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Portitions copyright (c) 2011, Apple Inc. All rights reserved.\r
+\r
+This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+\r
+#include "SecMain.h"\r
+\r
+#ifndef __APPLE__\r
+\r
+#define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+\r
+  EMU_IO_THUNK_PROTOCOL       *Thunk;\r
+\r
+\r
+  EMU_SNP_PROTOCOL            EmuSnp;\r
+  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
+\r
+} EMU_SNP_PRIVATE;\r
+\r
+#define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)\r
+\r
+/**\r
+  Register storage for SNP Mode.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Mode SimpleNetworkProtocol Mode structure passed into driver.\r
+\r
+  @retval EFI_SUCCESS           The network interface was started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpCreateMapping (\r
+  IN     EMU_SNP_PROTOCOL         *This,\r
+  IN     EFI_SIMPLE_NETWORK_MODE  *Mode\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Private->Mode = Mode;\r
+    \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Changes the state of a network interface from "stopped" to "started".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was started.\r
+  @retval EFI_ALREADY_STARTED   The network interface is already in the started state.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStart (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Changes the state of a network interface from "started" to "stopped".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was stopped.\r
+  @retval EFI_ALREADY_STARTED   The network interface is already in the stopped state.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStop (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Resets a network adapter and allocates the transmit and receive buffers \r
+  required by the network interface; optionally, also requests allocation \r
+  of additional transmit and receive buffers.\r
+\r
+  @param  This              The protocol instance pointer.\r
+  @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+  @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+\r
+  @retval EFI_SUCCESS           The network interface was initialized.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_OUT_OF_RESOURCES  There was not enough memory for the transmit and\r
+                                receive buffers.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpInitialize (\r
+  IN EMU_SNP_PROTOCOL                    *This,\r
+  IN UINTN                               ExtraRxBufferSize  OPTIONAL,\r
+  IN UINTN                               ExtraTxBufferSize  OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Resets a network adapter and re-initializes it with the parameters that were \r
+  provided in the previous call to Initialize().  \r
+\r
+  @param  This                 The protocol instance pointer.\r
+  @param  ExtendedVerification Indicates that the driver may perform a more\r
+                               exhaustive verification operation of the device\r
+                               during reset.\r
+\r
+  @retval EFI_SUCCESS           The network interface was reset.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReset (\r
+  IN EMU_SNP_PROTOCOL   *This,\r
+  IN BOOLEAN            ExtendedVerification\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Resets a network adapter and leaves it in a state that is safe for \r
+  another driver to initialize.\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The network interface was shutdown.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpShutdown (\r
+  IN EMU_SNP_PROTOCOL  *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Manages the multicast receive filters of a network interface.\r
+\r
+  @param  This             The protocol instance pointer.\r
+  @param  Enable           A bit mask of receive filters to enable on the network interface.\r
+  @param  Disable          A bit mask of receive filters to disable on the network interface.\r
+  @param  ResetMCastFilter Set to TRUE to reset the contents of the multicast receive\r
+                           filters on the network interface to their default values.\r
+  @param  McastFilterCnt   Number of multicast HW MAC addresses in the new\r
+                           MCastFilter list. This value must be less than or equal to\r
+                           the MCastFilterCnt field of EMU_SNP_MODE. This\r
+                           field is optional if ResetMCastFilter is TRUE.\r
+  @param  MCastFilter      A pointer to a list of new multicast receive filter HW MAC\r
+                           addresses. This list will replace any existing multicast\r
+                           HW MAC address list. This field is optional if\r
+                           ResetMCastFilter is TRUE.\r
+\r
+  @retval EFI_SUCCESS           The multicast receive filter list was updated.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReceiveFilters (\r
+  IN EMU_SNP_PROTOCOL                             *This,\r
+  IN UINT32                                       Enable,\r
+  IN UINT32                                       Disable,\r
+  IN BOOLEAN                                      ResetMCastFilter,\r
+  IN UINTN                                        MCastFilterCnt     OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                              *MCastFilter OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Modifies or resets the current station address, if supported.\r
+\r
+  @param  This  The protocol instance pointer.\r
+  @param  Reset Flag used to reset the station address to the network interfaces\r
+                permanent address.\r
+  @param  New   The new station address to be used for the network interface.\r
+\r
+  @retval EFI_SUCCESS           The network interfaces station address was updated.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStationAddress (\r
+  IN EMU_SNP_PROTOCOL            *This,\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *New OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Resets or collects the statistics on a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Reset           Set to TRUE to reset the statistics for the network interface.\r
+  @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On\r
+                          output the size, in bytes, of the resulting table of\r
+                          statistics.\r
+  @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
+                          contains the statistics.\r
+\r
+  @retval EFI_SUCCESS           The statistics were collected from the network interface.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpStatistics (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              Reset,\r
+  IN OUT UINTN                            *StatisticsSize   OPTIONAL,\r
+  OUT EFI_NETWORK_STATISTICS              *StatisticsTable  OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Converts a multicast IP address to a multicast HW MAC address.\r
+\r
+  @param  This The protocol instance pointer.\r
+  @param  IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
+               to FALSE if the multicast IP address is IPv4 [RFC 791].\r
+  @param  IP   The multicast IP address that is to be converted to a multicast\r
+               HW MAC address.\r
+  @param  MAC  The multicast HW MAC address that is to be generated from IP.\r
+\r
+  @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast\r
+                                HW MAC address.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpMCastIpToMac (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              IPv6,\r
+  IN EFI_IP_ADDRESS                       *IP,\r
+  OUT EFI_MAC_ADDRESS                     *MAC\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Performs read and write operations on the NVRAM device attached to a \r
+  network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  ReadWrite  TRUE for read operations, FALSE for write operations.\r
+  @param  Offset     Byte offset in the NVRAM device at which to start the read or\r
+                     write operation. This must be a multiple of NvRamAccessSize and\r
+                     less than NvRamSize.\r
+  @param  BufferSize The number of bytes to read or write from the NVRAM device.\r
+                     This must also be a multiple of NvramAccessSize.\r
+  @param  Buffer     A pointer to the data buffer.\r
+\r
+  @retval EFI_SUCCESS           The NVRAM access was performed.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpNvData (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN BOOLEAN                              ReadWrite,\r
+  IN UINTN                                Offset,\r
+  IN UINTN                                BufferSize,\r
+  IN OUT VOID                             *Buffer\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Reads the current interrupt status and recycled transmit buffer status from \r
+  a network interface.\r
+\r
+  @param  This            The protocol instance pointer.\r
+  @param  InterruptStatus A pointer to the bit mask of the currently active interrupts\r
+                          If this is NULL, the interrupt status will not be read from\r
+                          the device. If this is not NULL, the interrupt status will\r
+                          be read from the device. When the  interrupt status is read,\r
+                          it will also be cleared. Clearing the transmit  interrupt\r
+                          does not empty the recycled transmit buffer array.\r
+  @param  TxBuf           Recycled transmit buffer address. The network interface will\r
+                          not transmit if its internal recycled transmit buffer array\r
+                          is full. Reading the transmit buffer does not clear the\r
+                          transmit interrupt. If this is NULL, then the transmit buffer\r
+                          status will not be read. If there are no transmit buffers to\r
+                          recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
+\r
+  @retval EFI_SUCCESS           The status of the network interface was retrieved.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpGetStatus (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINT32                              *InterruptStatus OPTIONAL,\r
+  OUT VOID                                **TxBuf OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Places a packet in the transmit queue of a network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header to be filled in by\r
+                     the Transmit() function. If HeaderSize is non-zero, then it\r
+                     must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
+                     and Protocol parameters must not be NULL.\r
+  @param  BufferSize The size, in bytes, of the entire packet (media header and\r
+                     data) to be transmitted through the network interface.\r
+  @param  Buffer     A pointer to the packet (media header followed by data) to be\r
+                     transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
+                     then the media header in Buffer must already be filled in by the\r
+                     caller. If HeaderSize is non-zero, then the media header will be\r
+                     filled in by the Transmit() function.\r
+  @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter\r
+                     is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
+                     This->Mode->CurrentAddress is used for the source HW MAC address.\r
+  @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this\r
+                     parameter is ignored.\r
+  @param  Protocol   The type of header to build. If HeaderSize is zero, then this\r
+                     parameter is ignored. See RFC 1700, section "Ether Types", for\r
+                     examples.\r
+\r
+  @retval EFI_SUCCESS           The packet was placed on the transmit queue.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_NOT_READY         The network interface is too busy to accept this transmit request.                      \r
+  @retval EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpTransmit (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  IN UINTN                                HeaderSize,\r
+  IN UINTN                                BufferSize,\r
+  IN VOID                                 *Buffer,\r
+  IN EFI_MAC_ADDRESS                      *SrcAddr  OPTIONAL,\r
+  IN EFI_MAC_ADDRESS                      *DestAddr OPTIONAL,\r
+  IN UINT16                               *Protocol OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Receives a packet from a network interface.\r
+\r
+  @param  This       The protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header received on the network\r
+                     interface. If this parameter is NULL, then the media header size\r
+                     will not be returned.\r
+  @param  BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
+                     bytes, of the packet that was received on the network interface.\r
+  @param  Buffer     A pointer to the data buffer to receive both the media header and\r
+                     the data.\r
+  @param  SrcAddr    The source HW MAC address. If this parameter is NULL, the\r
+                     HW MAC source address will not be extracted from the media\r
+                     header.\r
+  @param  DestAddr   The destination HW MAC address. If this parameter is NULL,\r
+                     the HW MAC destination address will not be extracted from the\r
+                     media header.\r
+  @param  Protocol   The media header type. If this parameter is NULL, then the\r
+                     protocol will not be extracted from the media header. See\r
+                     RFC 1700 section "Ether Types" for examples.\r
+\r
+  @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has\r
+                                 been updated to the number of bytes received.\r
+  @retval  EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit\r
+                                 request.\r
+  @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval  EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
+  @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval  EFI_UNSUPPORTED       This function is not supported by the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EmuSnpReceive (\r
+  IN EMU_SNP_PROTOCOL                     *This,\r
+  OUT UINTN                               *HeaderSize OPTIONAL,\r
+  IN OUT UINTN                            *BufferSize,\r
+  OUT VOID                                *Buffer,\r
+  OUT EFI_MAC_ADDRESS                     *SrcAddr    OPTIONAL,\r
+  OUT EFI_MAC_ADDRESS                     *DestAddr   OPTIONAL,\r
+  OUT UINT16                              *Protocol   OPTIONAL\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE    *Private;\r
+\r
+  Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+EMU_SNP_PROTOCOL gEmuSnpProtocol = {\r
+  GasketSnpCreateMapping,\r
+  GasketSnpStart,\r
+  GasketSnpStop,\r
+  GasketSnpInitialize,\r
+  GasketSnpReset,\r
+  GasketSnpShutdown,\r
+  GasketSnpReceiveFilters,\r
+  GasketSnpStationAddress,\r
+  GasketSnpStatistics,\r
+  GasketSnpMCastIpToMac,\r
+  GasketSnpNvData,\r
+  GasketSnpGetStatus,\r
+  GasketSnpTransmit,\r
+  GasketSnpReceive\r
+};\r
+\r
+EFI_STATUS\r
+EmuSnpThunkOpen (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE  *Private;\r
+  \r
+  if (This->Private != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+  \r
+  if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  Private = malloc (sizeof (EMU_SNP_PRIVATE));\r
+  if (Private == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  \r
+  Private->Signature = EMU_SNP_PRIVATE_SIGNATURE;\r
+  Private->Thunk     = This;\r
+  CopyMem (&Private->EmuSnp, &gEmuSnpProtocol, sizeof (gEmuSnpProtocol));\r
+  \r
+  This->Interface = &Private->EmuSnp;\r
+  This->Private   = Private;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EmuSnpThunkClose (\r
+  IN  EMU_IO_THUNK_PROTOCOL   *This\r
+  )\r
+{\r
+  EMU_SNP_PRIVATE  *Private;\r
+\r
+  if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  Private = This->Private;\r
+  free (Private);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {\r
+  &gEmuSnpProtocolGuid,\r
+  NULL,\r
+  NULL,\r
+  0,\r
+  GasketSnpThunkOpen,\r
+  GasketSnpThunkClose,\r
+  NULL\r
+};\r
+\r
+#endif\r
index 5dcb44523e32359cc1c7c3965205e8921931deb1..a3143c1a8e8149f0805f53c7da426d681dfb7dc6 100644 (file)
@@ -117,8 +117,7 @@ main (
   AddThunkProtocol (&gX11ThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuGop), TRUE); 
   AddThunkProtocol (&gPosixFileSystemThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuFileSystem), TRUE); 
   AddThunkProtocol (&gBlockIoThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuVirtualDisk), TRUE); 
-  
-
+  AddThunkProtocol (&gSnpThunkIo, (CHAR16 *)PcdGetPtr (PcdEmuNetworkInterface), TRUE); 
 
   //
   // Emulator other Thunks
index cbe98de648d58c826bf380d8a432332953e29eba..2ca1e6351c2952066c2db91aa19f14a1ee90ceb7 100644 (file)
@@ -16,41 +16,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _SEC_MAIN_H__\r
 #define _SEC_MAIN_H__\r
 \r
-#include <PiPei.h>\r
-#include <Uefi.h>\r
-\r
-#include <Library/PeCoffLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/ReportStatusCodeLib.h>\r
-\r
-#include <Library/ThunkPpiList.h>\r
-#include <Library/ThunkProtocolList.h>\r
-#include <Library/PeiServicesLib.h>\r
-#include <Library/PeCoffGetEntryPointLib.h>\r
-#include <Library/EmuMagicPageLib.h>\r
-\r
-#include <Ppi/EmuThunk.h>\r
-#include <Ppi/StatusCode.h>\r
-\r
-#include <Protocol/SimplePointer.h>\r
-#include <Protocol/SimpleTextIn.h>\r
-#include <Protocol/SimpleTextInEx.h>\r
-#include <Protocol/UgaDraw.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-\r
-#include <Protocol/EmuThunk.h>\r
-#include <Protocol/EmuIoThunk.h>\r
-#include <Protocol/EmuGraphicsWindow.h>\r
-#include <Protocol/EmuThread.h>\r
-#include <Protocol/EmuBlockIo.h>\r
-\r
-#include <Guid/FileInfo.h>\r
-#include <Guid/FileSystemInfo.h>\r
-#include <Guid/FileSystemVolumeLabelInfo.h>\r
+//\r
+// Name mangle to prevent build errors. I.e conflicts between EFI and OS\r
+//\r
+#define NTOHL   _UNIX_EFI_NAME_MANGLE_NTOHL_\r
+#define HTONL   _UNIX_EFI_NAME_MANGLE_HTONL_\r
+#define NTOHS   _UNIX_EFI_NAME_MANGLE_NTOHS_\r
+#define HTONS   _UNIX_EFI_NAME_MANGLE_HTOHS_\r
+#define B0      _UNIX_EFI_NAME_MANGLE_B0_\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -104,6 +77,51 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <utime.h>\r
 \r
+#undef NTOHL\r
+#undef HTONL\r
+#undef NTOHS\r
+#undef HTONS\r
+#undef B0\r
+\r
+\r
+#include <PiPei.h>\r
+#include <Uefi.h>\r
+\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+\r
+#include <Library/ThunkPpiList.h>\r
+#include <Library/ThunkProtocolList.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/EmuMagicPageLib.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Ppi/StatusCode.h>\r
+\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/SimpleTextInEx.h>\r
+#include <Protocol/UgaDraw.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <Protocol/EmuThunk.h>\r
+#include <Protocol/EmuIoThunk.h>\r
+#include <Protocol/EmuGraphicsWindow.h>\r
+#include <Protocol/EmuThread.h>\r
+#include <Protocol/EmuBlockIo.h>\r
+#include <Protocol/EmuSnp.h>\r
+\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+\r
+\r
 #include "Gasket.h"\r
 \r
 \r
@@ -330,5 +348,6 @@ extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;
 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;\r
 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;\r
 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;\r
+extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo;\r
 \r
 #endif\r
index da4714e2a6179fd02d12fac5c929b40d41087f76..a0976efe860e008ce7159e772e763d70044756be 100644 (file)
@@ -36,7 +36,9 @@
   Pthreads.c\r
   PosixFileSystem.c\r
   BlockIo.c\r
-\r
+  LinuxPacketFilter.c \r
+  BerkeleyPacketFilter.c \r
+  \r
 [Sources.X64]\r
   X64/Gasket.S        # convert between Emu x86_64 ABI and EFI X64 ABI\r
   X64/SwitchStack.S\r
@@ -70,6 +72,7 @@
   gEmuGraphicsWindowProtocolGuid\r
   gEmuThreadThunkProtocolGuid\r
   gEmuBlockIoProtocolGuid\r
+  gEmuSnpProtocolGuid\r
   gEfiSimpleFileSystemProtocolGuid\r
 \r
 [Guids]\r
@@ -90,6 +93,7 @@
   gInOsEmuPkgTokenSpaceGuid.PcdEmuFileSystem\r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuSerialPort\r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuNetworkInterface\r
+  gInOsEmuPkgTokenSpaceGuid.PcdNetworkPacketFilterSize\r
 \r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoveryBase\r
   gInOsEmuPkgTokenSpaceGuid.PcdEmuFlashFvRecoverySize\r
index 093b05ca07725ab2eee8de0276db96774b90a4b5..a51807ab47998a9c20b275b6a6e51465ecdb2a71 100644 (file)
@@ -870,7 +870,7 @@ ASM_PFX(GasketPosixFileOpen):
   movq    %rdx, %rsi     
   movq    %r8,  %rdx
   movq    %r9,  %rcx
-  movq    0x30(%rbp), %r8 
+  movq    48(%rbp), %r8 
  
   call    ASM_PFX(PosixFileOpen)
 
@@ -1120,8 +1120,8 @@ ASM_PFX(GasketEmuBlockIoReadBlocks):
   movq    %rdx, %rsi     
   movq    %r8,  %rdx
   movq    %r9,  %rcx
-  movq    0x30(%rbp), %r8   
-  movq    0x38(%rbp), %r9   
+  movq    48(%rbp), %r8   
+  movq    56(%rbp), %r9   
 
   call    ASM_PFX(EmuBlockIoReadBlocks)
 
@@ -1143,8 +1143,8 @@ ASM_PFX(GasketEmuBlockIoWriteBlocks):
   movq    %rdx, %rsi     
   movq    %r8,  %rdx
   movq    %r9,  %rcx
-  movq    0x30(%rbp), %r8   
-  movq    0x38(%rbp), %r9   
+  movq    48(%rbp), %r8   
+  movq    56(%rbp), %r9   
 
   call    ASM_PFX(EmuBlockIoWriteBlocks)
 
@@ -1229,3 +1229,336 @@ ASM_PFX(GasketBlockIoThunkClose):
 
 
 
+ASM_GLOBAL ASM_PFX(GasketSnpCreateMapping)
+ASM_PFX(GasketSnpCreateMapping):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(EmuSnpCreateMapping)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpStart)
+ASM_PFX(GasketSnpStart):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(EmuSnpStart)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpStop)
+ASM_PFX(GasketSnpStop):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(EmuSnpStop)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpInitialize)
+ASM_PFX(GasketSnpInitialize):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(EmuSnpInitialize)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpReset)
+ASM_PFX(GasketSnpReset):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+
+  call    ASM_PFX(EmuSnpReset)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpShutdown)
+ASM_PFX(GasketSnpShutdown):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(EmuSnpShutdown)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpReceiveFilters)
+ASM_PFX(GasketSnpReceiveFilters):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+  movq    48(%rbp), %r8   
+  movq    56(%rbp), %r9   
+
+  call    ASM_PFX(EmuSnpReceiveFilters)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpStationAddress)
+ASM_PFX(GasketSnpStationAddress):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(EmuSnpStationAddress)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpStatistics)
+ASM_PFX(GasketSnpStatistics):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(EmuSnpStatistics)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpMCastIpToMac)
+ASM_PFX(GasketSnpMCastIpToMac):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+
+  call    ASM_PFX(EmuSnpMCastIpToMac)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpNvData)
+ASM_PFX(GasketSnpNvData):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+  movq    48(%rbp), %r8   
+
+  call    ASM_PFX(EmuSnpNvData)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpGetStatus)
+ASM_PFX(GasketSnpGetStatus):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+
+  call    ASM_PFX(EmuSnpGetStatus)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpTransmit)
+ASM_PFX(GasketSnpTransmit):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+       subq    $16, %rsp       // Allocate space for args on the stack 
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+  movq    48(%rbp), %r8   
+  movq    56(%rbp), %r9   
+  movq    64(%rbp), %rax
+  movq    %rax,     (%rsp)
+
+  call    ASM_PFX(EmuSnpTransmit)
+       addq    $16, %rsp
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpReceive)
+ASM_PFX(GasketSnpReceive):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+       subq    $16, %rsp       // Allocate space for args on the stack
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+  movq    %rdx, %rsi     
+  movq    %r8,  %rdx
+  movq    %r9,  %rcx
+  movq    48(%rbp), %r8   
+  movq    56(%rbp), %r9   
+  movq    64(%rbp), %rax
+  movq    %rax,     (%rsp)
+
+  call    ASM_PFX(EmuSnpReceive)
+       addq    $16, %rsp
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpThunkOpen)
+ASM_PFX(GasketSnpThunkOpen):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(EmuSnpThunkOpen)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
+ASM_GLOBAL ASM_PFX(GasketSnpThunkClose)
+ASM_PFX(GasketSnpThunkClose):
+  pushq   %rbp            // stack frame is for the debugger
+  movq    %rsp, %rbp
+
+  pushq   %rsi          // %rsi & %rdi are volatile in Unix and callee-save in EFI ABI
+  pushq   %rdi
+
+  movq    %rcx, %rdi    // Swizzle args 
+
+  call    ASM_PFX(EmuSnpThunkClose)
+
+  popq    %rdi          // restore state
+  popq    %rsi
+  popq    %rbp
+  ret
+
+
index af3e25973b616047937a546257c8e333edf428c0..10bb0cf2f6e717f216a8b5fe20e6d782b5eaa36e 100644 (file)
   PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
   DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
-\r
-####  DevicePathTextLib|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf\r
   PeiServicesTablePointerLib|InOsEmuPkg/Library/PeiServicesTablePointerLibMagicPage/PeiServicesTablePointerLibMagicPage.inf\r
 \r
 [LibraryClasses.common.SEC]\r
   \r
   MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
   IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf\r
-  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf \r
+ # {\r
+ #   <LibraryClasses>  \r
+ #     NULL|InOsEmuPkg/Library/DevicePathTextLib/DevicePathTextLib.inf\r
+ # }\r
+  \r
   MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
   MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
   MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r