2 Common definition for IP4.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __EFI_IP4_COMMON_H__
10 #define __EFI_IP4_COMMON_H__
12 typedef struct _IP4_INTERFACE IP4_INTERFACE
;
13 typedef struct _IP4_PROTOCOL IP4_PROTOCOL
;
14 typedef struct _IP4_SERVICE IP4_SERVICE
;
16 #define IP4_ETHER_PROTO 0x0800
19 // The packet is received as link level broadcast/multicast/promiscuous.
21 #define IP4_LINK_BROADCAST 0x00000001
22 #define IP4_LINK_MULTICAST 0x00000002
23 #define IP4_LINK_PROMISC 0x00000004
26 // IP4 address cast type classification. Keep it true that any
27 // type bigger than or equal to LOCAL_BROADCAST is broadcast.
29 #define IP4_PROMISCUOUS 1
30 #define IP4_LOCAL_HOST 2
31 #define IP4_MULTICAST 3
32 #define IP4_LOCAL_BROADCAST 4 // Destination is 255.255.255.255
33 #define IP4_SUBNET_BROADCAST 5
34 #define IP4_NET_BROADCAST 6
39 #define IP4_HEAD_DF_MASK 0x4000
40 #define IP4_HEAD_MF_MASK 0x2000
41 #define IP4_HEAD_OFFSET_MASK 0x1fff
43 #define IP4_ALLZERO_ADDRESS 0x00000000u
44 #define IP4_ALLONE_ADDRESS 0xFFFFFFFFu
45 #define IP4_ALLSYSTEM_ADDRESS 0xE0000001u
46 #define IP4_ALLROUTER_ADDRESS 0xE0000002u
49 /// Compose the fragment field to be used in the IP4 header.
51 #define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \
52 ((UINT16)(((Df) ? IP4_HEAD_DF_MASK : 0) | ((Mf) ? IP4_HEAD_MF_MASK : 0) | (((Offset) >> 3) & IP4_HEAD_OFFSET_MASK)))
54 #define IP4_LAST_FRAGMENT(FragmentField) \
55 (((FragmentField) & IP4_HEAD_MF_MASK) == 0)
57 #define IP4_FIRST_FRAGMENT(FragmentField) \
58 ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
60 #define IP4_DO_NOT_FRAGMENT(FragmentField) \
61 ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))
63 #define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)
66 /// Convert the Microsecond to second. IP transmit/receive time is
67 /// in the unit of microsecond. IP ticks once per second.
69 #define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
72 Return the cast type (Unicast/Broadcast) specific to an
73 interface. All the addresses are host byte ordered.
75 @param[in] IpAddr The IP address to classify in host byte order
76 @param[in] IpIf The interface that IpAddr received from
78 @return The cast type of this IP address specific to the interface.
79 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
80 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet broadcast to the
82 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
89 IN IP4_INTERFACE
*IpIf
93 Find the cast type of the packet related to the local host.
94 This isn't the same as link layer cast type. For example, DHCP
95 server may send local broadcast to the local unicast MAC.
97 @param[in] IpSb The IP4 service binding instance that received the
99 @param[in] Dst The destination address in the packet (host byte
101 @param[in] Src The source address in the packet (host byte order)
103 @return The cast type for the Dst, it will return on the first non-promiscuous
104 cast type to a configured interface. If the packet doesn't match any of
105 the interface, multicast address and local broadcast address are checked.
110 IN IP4_SERVICE
*IpSb
,
116 Find an interface whose configured IP address is Ip.
118 @param[in] IpSb The IP4 service binding instance
119 @param[in] Ip The Ip address (host byte order) to find
121 @return The IP4_INTERFACE point if found, otherwise NULL
126 IN IP4_SERVICE
*IpSb
,
131 Find an interface that Ip is on that connected network.
133 @param[in] IpSb The IP4 service binding instance
134 @param[in] Ip The Ip address (host byte order) to find
136 @return The IP4_INTERFACE point if found, otherwise NULL
141 IN IP4_SERVICE
*IpSb
,
146 Find an interface of the service with the same Ip/Netmask pair.
148 @param[in] IpSb Ip4 service binding instance
149 @param[in] Ip The Ip address to find (host byte order)
150 @param[in] Netmask The network to find (host byte order)
152 @return The IP4_INTERFACE point if found, otherwise NULL
156 Ip4FindStationAddress (
157 IN IP4_SERVICE
*IpSb
,
163 Get the MAC address for a multicast IP address. Call
164 Mnp's McastIpToMac to find the MAC address in stead of
165 hard code the NIC to be Ethernet.
167 @param[in] Mnp The Mnp instance to get the MAC address.
168 @param[in] Multicast The multicast IP address to translate.
169 @param[out] Mac The buffer to hold the translated address.
171 @retval EFI_SUCCESS if the multicast IP is successfully translated to a
172 multicast MAC address.
173 @retval other Otherwise some error.
178 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
,
179 IN IP4_ADDR Multicast
,
180 OUT EFI_MAC_ADDRESS
*Mac
184 Convert the multibyte field in IP header's byter order.
185 In spite of its name, it can also be used to convert from
186 host to network byte order.
188 @param[in] Head The IP head to convert
190 @return Point to the converted IP head
199 Validate that Ip/Netmask pair is OK to be used as station
200 address. Only continuous netmasks are supported. and check
201 that StationAddress is a unicast address on the network.
203 @param[in] Ip The IP address to validate.
204 @param[in] Netmask The netmask of the IP.
206 @retval TRUE The Ip/Netmask pair is valid.
207 @retval FALSE The Ip/Netmask pair is invalid.
211 Ip4StationAddressValid (