]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.h
index 59e5c11786dc956bb76a234cde6a3998c1f69de7..e0fffc9d0da20eeb5dcdb31a62cc3dfd7bb3dc63 100644 (file)
-/** @file
-
-Copyright (c) 2005 - 2006, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution.  The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-
-Module Name:
-
-  Ip4Common.h
-
-Abstract:
-
-  Common definition for IP4.
-
-
-**/
-
-#ifndef __EFI_IP4_COMMON_H__
-#define __EFI_IP4_COMMON_H__
-
-typedef struct _IP4_INTERFACE  IP4_INTERFACE;
-typedef struct _IP4_PROTOCOL   IP4_PROTOCOL;
-typedef struct _IP4_SERVICE    IP4_SERVICE;
-
-
-enum {
-  IP4_ETHER_PROTO      = 0x0800,
-
-  IP4_PROTO_ICMP       = 0x01,
-  IP4_PROTO_IGMP       = 0x02,
-
-  //
-  // The packet is received as link level broadcast/multicast/promiscuous.
-  //
-  IP4_LINK_BROADCAST   = 0x00000001,
-  IP4_LINK_MULTICAST   = 0x00000002,
-  IP4_LINK_PROMISC     = 0x00000004,
-
-  //
-  // IP4 address cast type classfication. Keep it true that any
-  // type bigger than or equal to LOCAL_BROADCAST is broadcast.
-  //
-  IP4_PROMISCUOUS      = 1,
-  IP4_LOCAL_HOST,
-  IP4_MULTICAST,
-  IP4_LOCAL_BROADCAST,  // Destination is 255.255.255.255
-  IP4_SUBNET_BROADCAST,
-  IP4_NET_BROADCAST,
-
-  //
-  // IP4 header flags
-  //
-  IP4_HEAD_DF_MASK     = 0x4000,
-  IP4_HEAD_MF_MASK     = 0x2000,
-  IP4_HEAD_OFFSET_MASK = 0x1fff,
-};
-
-#define IP4_ALLZERO_ADDRESS   0x00000000u
-#define IP4_ALLONE_ADDRESS    0xFFFFFFFFu
-#define IP4_ALLSYSTEM_ADDRESS 0xE0000001u
-#define IP4_ALLROUTER_ADDRESS 0xE0000002u
-
-//
-// Compose the fragment field to be used in the IP4 header.
-//
-#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \
-    ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))
-
-#define IP4_LAST_FRAGMENT(FragmentField)  \
-          (((FragmentField) & IP4_HEAD_MF_MASK) == 0)
-
-#define IP4_FIRST_FRAGMENT(FragmentField) \
-          ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
-
-#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)
-
-//
-// Conver the Microsecond to second. IP transmit/receive time is
-// in the unit of microsecond. IP ticks once per second.
-//
-#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
-
-INTN
-Ip4GetNetCast (
-  IN  IP4_ADDR            IpAddr,
-  IN  IP4_INTERFACE       *IpIf
-  );
-
-INTN
-Ip4GetHostCast (
-  IN  IP4_SERVICE         *IpSb,
-  IN  IP4_ADDR            Dst,
-  IN  IP4_ADDR            Src
-  );
-
-IP4_INTERFACE *
-Ip4FindInterface (
-  IN IP4_SERVICE          *IpService,
-  IN IP4_ADDR             Addr
-  );
-
-IP4_INTERFACE *
-Ip4FindNet (
-  IN IP4_SERVICE          *IpService,
-  IN IP4_ADDR             Addr
-  );
-
-IP4_INTERFACE *
-Ip4FindStationAddress (
-  IN IP4_SERVICE          *IpSb,
-  IN IP4_ADDR             Ip,
-  IN IP4_ADDR             Netmask
-  );
-
-EFI_STATUS
-Ip4GetMulticastMac (
-  IN  EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
-  IN  IP4_ADDR                     Multicast,
-  OUT EFI_MAC_ADDRESS              *Mac
-  );
-
-IP4_HEAD *
-Ip4NtohHead (
-  IN IP4_HEAD               *Head
-  );
-
-EFI_STATUS
-Ip4SetVariableData (
-  IN IP4_SERVICE            *IpSb
-  );
-
-VOID
-Ip4ClearVariableData (
-  IN IP4_SERVICE            *IpSb
-  );
-
-#endif
+/** @file\r
+  Common definition for IP4.\r
+\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\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_IP4_COMMON_H__\r
+#define __EFI_IP4_COMMON_H__\r
+\r
+typedef struct _IP4_INTERFACE  IP4_INTERFACE;\r
+typedef struct _IP4_PROTOCOL   IP4_PROTOCOL;\r
+typedef struct _IP4_SERVICE    IP4_SERVICE;\r
+\r
+#define IP4_ETHER_PROTO       0x0800\r
+\r
+//\r
+// The packet is received as link level broadcast/multicast/promiscuous.\r
+//\r
+#define IP4_LINK_BROADCAST    0x00000001\r
+#define IP4_LINK_MULTICAST    0x00000002\r
+#define IP4_LINK_PROMISC      0x00000004\r
+\r
+//\r
+// IP4 address cast type classfication. Keep it true that any\r
+// type bigger than or equal to LOCAL_BROADCAST is broadcast.\r
+//\r
+#define IP4_PROMISCUOUS       1\r
+#define IP4_LOCAL_HOST        2\r
+#define IP4_MULTICAST         3\r
+#define IP4_LOCAL_BROADCAST   4  // Destination is 255.255.255.255\r
+#define IP4_SUBNET_BROADCAST  5\r
+#define IP4_NET_BROADCAST     6\r
+\r
+//\r
+// IP4 header flags\r
+//\r
+#define IP4_HEAD_DF_MASK      0x4000\r
+#define IP4_HEAD_MF_MASK      0x2000\r
+#define IP4_HEAD_OFFSET_MASK  0x1fff\r
+\r
+#define IP4_ALLZERO_ADDRESS   0x00000000u\r
+#define IP4_ALLONE_ADDRESS    0xFFFFFFFFu\r
+#define IP4_ALLSYSTEM_ADDRESS 0xE0000001u\r
+#define IP4_ALLROUTER_ADDRESS 0xE0000002u\r
+\r
+///\r
+/// Compose the fragment field to be used in the IP4 header.\r
+///\r
+#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \\r
+    ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))\r
+\r
+#define IP4_LAST_FRAGMENT(FragmentField)  \\r
+          (((FragmentField) & IP4_HEAD_MF_MASK) == 0)\r
+\r
+#define IP4_FIRST_FRAGMENT(FragmentField) \\r
+          ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))\r
+\r
+#define IP4_DO_NOT_FRAGMENT(FragmentField) \\r
+          ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))\r
+\r
+#define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)\r
+\r
+///\r
+/// Conver the Microsecond to second. IP transmit/receive time is\r
+/// in the unit of microsecond. IP ticks once per second.\r
+///\r
+#define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r
+\r
+/**\r
+  Return the cast type (Unicast/Boradcast) specific to an\r
+  interface. All the addresses are host byte ordered.\r
+\r
+  @param[in]  IpAddr                The IP address to classify in host byte order\r
+  @param[in]  IpIf                  The interface that IpAddr received from\r
+\r
+  @return The cast type of this IP address specific to the interface.\r
+  @retval IP4_LOCAL_HOST        The IpAddr equals to the interface's address\r
+  @retval IP4_SUBNET_BROADCAST  The IpAddr is a directed subnet boradcast to  the\r
+                                interface\r
+  @retval IP4_NET_BROADCAST     The IpAddr is a network broadcast to the interface\r
+  @retval 0                     Otherwise.\r
+\r
+**/\r
+INTN\r
+Ip4GetNetCast (\r
+  IN  IP4_ADDR          IpAddr,\r
+  IN  IP4_INTERFACE     *IpIf\r
+  );\r
+\r
+/**\r
+  Find the cast type of the packet related to the local host.\r
+  This isn't the same as link layer cast type. For example, DHCP\r
+  server may send local broadcast to the local unicast MAC.\r
+\r
+  @param[in]  IpSb                  The IP4 service binding instance that received the\r
+                                    packet\r
+  @param[in]  Dst                   The destination address in the packet (host byte\r
+                                    order)\r
+  @param[in]  Src                   The source address in the packet (host byte order)\r
+\r
+  @return The cast type for the Dst, it will return on the first non-promiscuous\r
+          cast type to a configured interface. If the packet doesn't match any of\r
+          the interface, multicast address and local broadcast address are checked.\r
+\r
+**/\r
+INTN\r
+Ip4GetHostCast (\r
+  IN  IP4_SERVICE       *IpSb,\r
+  IN  IP4_ADDR          Dst,\r
+  IN  IP4_ADDR          Src\r
+  );\r
+\r
+/**\r
+  Find an interface whose configured IP address is Ip.\r
+\r
+  @param[in]  IpSb                  The IP4 service binding instance\r
+  @param[in]  Ip                    The Ip address (host byte order) to find\r
+\r
+  @return The IP4_INTERFACE point if found, otherwise NULL\r
+\r
+**/\r
+IP4_INTERFACE *\r
+Ip4FindInterface (\r
+  IN IP4_SERVICE        *IpSb,\r
+  IN IP4_ADDR           Ip\r
+  );\r
+\r
+/**\r
+  Find an interface that Ip is on that connected network.\r
+\r
+  @param[in]  IpSb                  The IP4 service binding instance\r
+  @param[in]  Ip                    The Ip address (host byte order) to find\r
+\r
+  @return The IP4_INTERFACE point if found, otherwise NULL\r
+\r
+**/\r
+IP4_INTERFACE *\r
+Ip4FindNet (\r
+  IN IP4_SERVICE        *IpSb,\r
+  IN IP4_ADDR           Ip\r
+  );\r
+\r
+/**\r
+  Find an interface of the service with the same Ip/Netmask pair.\r
+\r
+  @param[in]  IpSb                  Ip4 service binding instance\r
+  @param[in]  Ip                    The Ip adress to find (host byte order)\r
+  @param[in]  Netmask               The network to find (host byte order)\r
+\r
+  @return The IP4_INTERFACE point if found, otherwise NULL\r
+\r
+**/\r
+IP4_INTERFACE *\r
+Ip4FindStationAddress (\r
+  IN IP4_SERVICE        *IpSb,\r
+  IN IP4_ADDR           Ip,\r
+  IN IP4_ADDR           Netmask\r
+  );\r
+\r
+/**\r
+  Get the MAC address for a multicast IP address. Call\r
+  Mnp's McastIpToMac to find the MAC address in stead of\r
+  hard code 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 if the multicast IP is successfully translated to a\r
+                      multicast MAC address.\r
+  @retval other       Otherwise some error.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip4GetMulticastMac (\r
+  IN  EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
+  IN  IP4_ADDR                     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]  Head                  The IP head to convert\r
+\r
+  @return Point to the converted IP head\r
+\r
+**/\r
+IP4_HEAD *\r
+Ip4NtohHead (\r
+  IN IP4_HEAD           *Head\r
+  );\r
+\r
+\r
+/**\r
+  Validate that Ip/Netmask pair is OK to be used as station\r
+  address. Only continuous netmasks are supported. and check\r
+  that StationAddress is a unicast address on the newtwork.\r
+\r
+  @param[in]  Ip                 The IP address to validate.\r
+  @param[in]  Netmask            The netmaks of the IP.\r
+\r
+  @retval TRUE                   The Ip/Netmask pair is valid.\r
+  @retval FALSE                  The Ip/Netmask pair is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+Ip4StationAddressValid (\r
+  IN IP4_ADDR               Ip,\r
+  IN IP4_ADDR               Netmask\r
+  );\r
+\r
+#endif\r