]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6Common.h
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Common.h
diff --git a/NetworkPkg/Ip6Dxe/Ip6Common.h b/NetworkPkg/Ip6Dxe/Ip6Common.h
new file mode 100644 (file)
index 0000000..c3755f4
--- /dev/null
@@ -0,0 +1,338 @@
+/** @file\r
+  Common definition and functions for IP6 driver.\r
+\r
+  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\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
+#ifndef __EFI_IP6_COMMON_H__\r
+#define __EFI_IP6_COMMON_H__\r
+\r
+#define IP6_LINK_EQUAL(Mac1, Mac2) (CompareMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)) == 0)\r
+\r
+//\r
+// Convert the Microsecond to second. IP transmit/receive time is\r
+// in the unit of microsecond. IP ticks once per second.\r
+//\r
+#define IP6_US_TO_SEC(Us)              (((Us) + 999999) / 1000000)\r
+\r
+#define IP6_ETHER_PROTO                0x86DD\r
+\r
+#define IP6_MAC_LEN                    6\r
+#define IP6_IF_ID_LEN                  8\r
+\r
+#define IP6_INTERFACE_LOCAL_SCOPE      1\r
+#define IP6_LINK_LOCAL_SCOPE           2\r
+#define IP6_SITE_LOCAL_SCOPE           5\r
+\r
+#define IP6_INFINIT_LIFETIME           0xFFFFFFFF\r
+\r
+#define IP6_HOP_LIMIT                  255\r
+//\r
+// Make it to 64 since all 54 bits are zero.\r
+//\r
+#define IP6_LINK_LOCAL_PREFIX_LENGTH   64\r
+\r
+#define IP6_TIMER_INTERVAL_IN_MS       100\r
+#define IP6_ONE_SECOND_IN_MS           1000\r
+\r
+//\r
+// The packet is received as link level broadcast/multicast/promiscuous.\r
+//\r
+#define IP6_LINK_BROADCAST             0x00000001\r
+#define IP6_LINK_MULTICAST             0x00000002\r
+#define IP6_LINK_PROMISC               0x00000004\r
+\r
+#define IP6_U_BIT                      0x02\r
+\r
+typedef enum {\r
+  Ip6Promiscuous                     = 1,\r
+  Ip6Unicast,\r
+  Ip6Multicast,\r
+  Ip6AnyCast\r
+} IP6_ADDRESS_TYPE;\r
+\r
+typedef struct _IP6_INTERFACE    IP6_INTERFACE;\r
+typedef struct _IP6_PROTOCOL     IP6_PROTOCOL;\r
+typedef struct _IP6_SERVICE      IP6_SERVICE;\r
+typedef struct _IP6_ADDRESS_INFO IP6_ADDRESS_INFO;\r
+\r
+/**\r
+  Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number\r
+  of EFI_IP6_ADDRESS_INFO is also returned. If AddressList is NULL,\r
+  only the address count is returned.\r
+\r
+  @param[in]  IpSb              The IP6 service binding instance.\r
+  @param[out] AddressCount      The number of returned addresses.\r
+  @param[out] AddressList       The pointer to the array of EFI_IP6_ADDRESS_INFO.\r
+                                This is an optional parameter.\r
+\r
+\r
+  @retval EFI_SUCCESS           The address array is successfully build\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate the memory for the address info.\r
+  @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip6BuildEfiAddressList (\r
+  IN IP6_SERVICE            *IpSb,\r
+  OUT UINT32                *AddressCount,\r
+  OUT EFI_IP6_ADDRESS_INFO  **AddressList OPTIONAL\r
+  );\r
+\r
+/**\r
+  Generate the multicast addresses identify the group of all IPv6 nodes or IPv6\r
+  routers defined in RFC4291.\r
+\r
+  All Nodes Addresses: FF01::1, FF02::1.\r
+  All Router Addresses: FF01::2, FF02::2, FF05::2.\r
+\r
+  @param[in]  Router            If TRUE, generate all routers addresses,\r
+                                else generate all node addresses.\r
+  @param[in]  Scope             interface-local(1), link-local(2), or site-local(5)\r
+  @param[out] Ip6Addr           The generated multicast address.\r
+\r
+  @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
+  @retval EFI_SUCCESS           The address is generated.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip6SetToAllNodeMulticast (\r
+  IN  BOOLEAN          Router,\r
+  IN  UINT8            Scope,\r
+  OUT EFI_IPv6_ADDRESS *Ip6Addr\r
+  );\r
+\r
+/**\r
+  This function converts MAC address to 64 bits interface ID according to RFC4291\r
+  and returns the interface ID. Currently only 48-bit MAC address is supported by\r
+  this function.\r
+\r
+  @param[in, out]  IpSb      The IP6 service binding instance.\r
+\r
+  @retval          NULL      The operation fails.\r
+  @return                    Pointer to the generated interface ID.\r
+\r
+**/\r
+UINT8 *\r
+Ip6CreateInterfaceID (\r
+  IN OUT IP6_SERVICE         *IpSb\r
+  );\r
+\r
+/**\r
+  This function creates link-local address from interface identifier. The\r
+  interface identifier is normally created from MAC address. It might be manually\r
+  configured by administrator if the link-local address created from MAC address\r
+  is a duplicate address.\r
+\r
+  @param[in, out]  IpSb      The IP6 service binding instance.\r
+\r
+  @retval          NULL      If the operation fails.\r
+  @return                    The generated Link Local address, in network order.\r
+\r
+**/\r
+EFI_IPv6_ADDRESS *\r
+Ip6CreateLinkLocalAddr (\r
+  IN OUT IP6_SERVICE         *IpSb\r
+  );\r
+\r
+/**\r
+  Compute the solicited-node multicast address for an unicast or anycast address,\r
+  by taking the low-order 24 bits of this address, and appending those bits to\r
+  the prefix FF02:0:0:0:0:1:FF00::/104.\r
+\r
+  @param  Ip6Addr               The unicast or anycast address, in network order.\r
+  @param  MulticastAddr         The generated solicited-node multicast address,\r
+                                in network order.\r
+\r
+**/\r
+VOID\r
+Ip6CreateSNMulticastAddr (\r
+  IN EFI_IPv6_ADDRESS  *Ip6Addr,\r
+  OUT EFI_IPv6_ADDRESS *MulticastAddr\r
+  );\r
+\r
+/**\r
+  Check whether the incoming Ipv6 address is a solicited-node multicast address.\r
+\r
+  @param[in]  Ip6               Ip6 address, in network order.\r
+\r
+  @retval TRUE                  Yes, solicited-node multicast address\r
+  @retval FALSE                 No\r
+\r
+**/\r
+BOOLEAN\r
+Ip6IsSNMulticastAddr (\r
+  IN EFI_IPv6_ADDRESS *Ip6\r
+  );\r
+\r
+/**\r
+  Check whether the incoming IPv6 address is one of the maintained address in\r
+  the IP6 service binding instance.\r
+\r
+  @param[in]  IpSb              Points to a IP6 service binding instance\r
+  @param[in]  Address           The IP6 address to be checked.\r
+  @param[out] Interface         If not NULL, output the IP6 interface which\r
+                                maintains the Address.\r
+  @param[out] AddressInfo       If not NULL, output the IP6 address information\r
+                                of the Address.\r
+\r
+  @retval TRUE                  Yes, it is one of the maintained addresses.\r
+  @retval FALSE                 No, it is not one of the maintained addresses.\r
+\r
+**/\r
+BOOLEAN\r
+Ip6IsOneOfSetAddress (\r
+  IN  IP6_SERVICE           *IpSb,\r
+  IN  EFI_IPv6_ADDRESS      *Address,\r
+  OUT IP6_INTERFACE         **Interface   OPTIONAL,\r
+  OUT IP6_ADDRESS_INFO      **AddressInfo OPTIONAL\r
+  );\r
+\r
+/**\r
+  Check whether the incoming MAC address is valid.\r
+\r
+  @param[in]  IpSb              Points to a IP6 service binding instance.\r
+  @param[in]  LinkAddress       The MAC address.\r
+\r
+  @retval TRUE                  Yes, it is valid.\r
+  @retval FALSE                 No, it is not valid.\r
+\r
+**/\r
+BOOLEAN\r
+Ip6IsValidLinkAddress (\r
+  IN  IP6_SERVICE      *IpSb,\r
+  IN  EFI_MAC_ADDRESS  *LinkAddress\r
+  );\r
+\r
+\r
+/**\r
+  Copy the PrefixLength bits from Src to Dest.\r
+\r
+  @param[out] Dest              A pointer to the buffer to copy to.\r
+  @param[in]  Src               A pointer to the buffer to copy from.\r
+  @param[in]  PrefixLength      The number of bits to copy.\r
+\r
+**/\r
+VOID\r
+Ip6CopyAddressByPrefix (\r
+  OUT EFI_IPv6_ADDRESS *Dest,\r
+  IN  EFI_IPv6_ADDRESS *Src,\r
+  IN  UINT8            PrefixLength\r
+  );\r
+\r
+/**\r
+  Insert a node IP6_ADDRESS_INFO to an IP6 interface.\r
+\r
+  @param[in, out]  IpIf             Points to an IP6 interface.\r
+  @param[in]       AddrInfo         Points to an IP6_ADDRESS_INFO.\r
+\r
+**/\r
+VOID\r
+Ip6AddAddr (\r
+  IN OUT IP6_INTERFACE *IpIf,\r
+  IN IP6_ADDRESS_INFO  *AddrInfo\r
+  );\r
+\r
+/**\r
+  Remove the IPv6 address from the address list node points to IP6_ADDRESS_INFO.\r
+\r
+  This function removes the matching IPv6 addresses from the address list and\r
+  adjusts the address count of the address list. If IpSb is not NULL, this function\r
+  calls Ip6LeaveGroup to see whether it should call Mnp->Groups() to remove the\r
+  its solicited-node multicast MAC address from the filter list and sends out\r
+  a Multicast Listener Done. If Prefix is NULL, all address in the address list\r
+  will be removed. If Prefix is not NULL, the address that matching the Prefix\r
+  with PrefixLength in the address list will be removed.\r
+\r
+  @param[in]       IpSb             NULL or points to IP6 service binding instance.\r
+  @param[in, out]  AddressList      address list array\r
+  @param[in, out]  AddressCount     the count of addresses in address list array\r
+  @param[in]       Prefix           NULL or an IPv6 address prefix\r
+  @param[in]       PrefixLength     the length of Prefix\r
+\r
+  @retval    EFI_SUCCESS            The operation completed successfully.\r
+  @retval    EFI_NOT_FOUND          The address matching the Prefix with PrefixLength\r
+                                    cannot be found in address list.\r
+  @retval    EFI_INVALID_PARAMETER  Any input parameter is invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip6RemoveAddr (\r
+  IN IP6_SERVICE       *IpSb          OPTIONAL,\r
+  IN OUT LIST_ENTRY    *AddressList,\r
+  IN OUT UINT32        *AddressCount,\r
+  IN EFI_IPv6_ADDRESS  *Prefix        OPTIONAL,\r
+  IN UINT8             PrefixLength\r
+  );\r
+\r
+/**\r
+  Set the Ip6 variable data.\r
+\r
+  @param[in]  IpSb              Points to an IP6 service binding instance\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources to set the variable.\r
+  @retval other                 Set variable failed.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip6SetVariableData (\r
+  IN IP6_SERVICE  *IpSb\r
+  );\r
+\r
+/**\r
+  Clear the variable and free the resource.\r
+\r
+  @param[in]  IpSb                  Ip6 service binding instance.\r
+\r
+**/\r
+VOID\r
+Ip6ClearVariableData (\r
+  IN IP6_SERVICE  *IpSb\r
+  );\r
+\r
+/**\r
+  Get the MAC address for a multicast IP address. Call\r
+  Mnp's McastIpToMac to find the MAC address instead of\r
+  hard-coding the NIC to be Ethernet.\r
+\r
+  @param[in]  Mnp                   The Mnp instance to get the MAC address.\r
+  @param[in]  Multicast             The multicast IP address to translate.\r
+  @param[out] Mac                   The buffer to hold the translated address.\r
+\r
+  @retval EFI_SUCCESS               The multicast IP is successfully\r
+                                    translated to a multicast MAC address.\r
+  @retval Other                     The address is not converted because an error occurred.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip6GetMulticastMac (\r
+  IN  EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
+  IN  EFI_IPv6_ADDRESS             *Multicast,\r
+  OUT EFI_MAC_ADDRESS              *Mac\r
+  );\r
+\r
+/**\r
+  Convert the multibyte field in IP header's byter order.\r
+  In spite of its name, it can also be used to convert from\r
+  host to network byte order.\r
+\r
+  @param[in, out]  Head                  The IP head to convert.\r
+\r
+  @return Point to the converted IP head.\r
+\r
+**/\r
+EFI_IP6_HEADER *\r
+Ip6NtohHead (\r
+  IN OUT EFI_IP6_HEADER *Head\r
+  );\r
+\r
+#endif\r