2 Common definition for IP4.
4 Copyright (c) 2005 - 2006, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __EFI_IP4_COMMON_H__
16 #define __EFI_IP4_COMMON_H__
18 typedef struct _IP4_INTERFACE IP4_INTERFACE
;
19 typedef struct _IP4_PROTOCOL IP4_PROTOCOL
;
20 typedef struct _IP4_SERVICE IP4_SERVICE
;
24 IP4_ETHER_PROTO
= 0x0800,
26 IP4_PROTO_ICMP
= 0x01,
27 IP4_PROTO_IGMP
= 0x02,
30 // The packet is received as link level broadcast/multicast/promiscuous.
32 IP4_LINK_BROADCAST
= 0x00000001,
33 IP4_LINK_MULTICAST
= 0x00000002,
34 IP4_LINK_PROMISC
= 0x00000004,
37 // IP4 address cast type classfication. Keep it true that any
38 // type bigger than or equal to LOCAL_BROADCAST is broadcast.
43 IP4_LOCAL_BROADCAST
, // Destination is 255.255.255.255
50 IP4_HEAD_DF_MASK
= 0x4000,
51 IP4_HEAD_MF_MASK
= 0x2000,
52 IP4_HEAD_OFFSET_MASK
= 0x1fff
55 #define IP4_ALLZERO_ADDRESS 0x00000000u
56 #define IP4_ALLONE_ADDRESS 0xFFFFFFFFu
57 #define IP4_ALLSYSTEM_ADDRESS 0xE0000001u
58 #define IP4_ALLROUTER_ADDRESS 0xE0000002u
61 /// Compose the fragment field to be used in the IP4 header.
63 #define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \
64 ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))
66 #define IP4_LAST_FRAGMENT(FragmentField) \
67 (((FragmentField) & IP4_HEAD_MF_MASK) == 0)
69 #define IP4_FIRST_FRAGMENT(FragmentField) \
70 ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
72 #define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)
75 /// Conver the Microsecond to second. IP transmit/receive time is
76 /// in the unit of microsecond. IP ticks once per second.
78 #define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
81 Return the cast type (Unicast/Boradcast) specific to an
82 interface. All the addresses are host byte ordered.
84 @param[in] IpAddr The IP address to classify in host byte order
85 @param[in] IpIf The interface that IpAddr received from
87 @return The cast type of this IP address specific to the interface.
88 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
89 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the
91 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
98 IN IP4_INTERFACE
*IpIf
102 Find the cast type of the packet related to the local host.
103 This isn't the same as link layer cast type. For example, DHCP
104 server may send local broadcast to the local unicast MAC.
106 @param[in] IpSb The IP4 service binding instance that received the
108 @param[in] Dst The destination address in the packet (host byte
110 @param[in] Src The source address in the packet (host byte order)
112 @return The cast type for the Dst, it will return on the first non-promiscuous
113 cast type to a configured interface. If the packet doesn't match any of
114 the interface, multicast address and local broadcast address are checked.
119 IN IP4_SERVICE
*IpSb
,
125 Find an interface whose configured IP address is Ip.
127 @param[in] IpSb The IP4 service binding instance
128 @param[in] Ip The Ip address (host byte order) to find
130 @return The IP4_INTERFACE point if found, otherwise NULL
135 IN IP4_SERVICE
*IpSb
,
140 Find an interface that Ip is on that connected network.
142 @param[in] IpSb The IP4 service binding instance
143 @param[in] Ip The Ip address (host byte order) to find
145 @return The IP4_INTERFACE point if found, otherwise NULL
150 IN IP4_SERVICE
*IpSb
,
155 Find an interface of the service with the same Ip/Netmask pair.
157 @param[in] IpSb Ip4 service binding instance
158 @param[in] Ip The Ip adress to find (host byte order)
159 @param[in] Netmask The network to find (host byte order)
161 @return The IP4_INTERFACE point if found, otherwise NULL
165 Ip4FindStationAddress (
166 IN IP4_SERVICE
*IpSb
,
172 Get the MAC address for a multicast IP address. Call
173 Mnp's McastIpToMac to find the MAC address in stead of
174 hard code the NIC to be Ethernet.
176 @param[in] Mnp The Mnp instance to get the MAC address.
177 @param[in] Multicast The multicast IP address to translate.
178 @param[out] Mac The buffer to hold the translated address.
180 @retval EFI_SUCCESS if the multicast IP is successfully translated to a
181 multicast MAC address.
182 @retval other Otherwise some error.
187 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
,
188 IN IP4_ADDR Multicast
,
189 OUT EFI_MAC_ADDRESS
*Mac
193 Convert the multibyte field in IP header's byter order.
194 In spite of its name, it can also be used to convert from
195 host to network byte order.
197 @param[in] Head The IP head to convert
199 @return Point to the converted IP head
208 Set the Ip4 variable data.
210 Save the list of all of the IPv4 addresses and subnet masks that are currently
211 being used to volatile variable storage.
213 @param[in] IpSb Ip4 service binding instance
215 @retval EFI_SUCCESS Successfully set variable.
216 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
217 @retval other Set variable failed.
226 Clear the variable and free the resource.
228 @param[in] IpSb Ip4 service binding instance
232 Ip4ClearVariableData (