2 Common definition for IP4.
4 Copyright (c) 2005 - 2009, 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
;
22 #define IP4_ETHER_PROTO 0x0800
25 // The packet is received as link level broadcast/multicast/promiscuous.
27 #define IP4_LINK_BROADCAST 0x00000001
28 #define IP4_LINK_MULTICAST 0x00000002
29 #define IP4_LINK_PROMISC 0x00000004
32 // IP4 address cast type classfication. Keep it true that any
33 // type bigger than or equal to LOCAL_BROADCAST is broadcast.
35 #define IP4_PROMISCUOUS 1
36 #define IP4_LOCAL_HOST 2
37 #define IP4_MULTICAST 3
38 #define IP4_LOCAL_BROADCAST 4 // Destination is 255.255.255.255
39 #define IP4_SUBNET_BROADCAST 5
40 #define IP4_NET_BROADCAST 6
45 #define IP4_HEAD_DF_MASK 0x4000
46 #define IP4_HEAD_MF_MASK 0x2000
47 #define IP4_HEAD_OFFSET_MASK 0x1fff
49 #define IP4_ALLZERO_ADDRESS 0x00000000u
50 #define IP4_ALLONE_ADDRESS 0xFFFFFFFFu
51 #define IP4_ALLSYSTEM_ADDRESS 0xE0000001u
52 #define IP4_ALLROUTER_ADDRESS 0xE0000002u
55 /// Compose the fragment field to be used in the IP4 header.
57 #define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \
58 ((UINT16)(((Df) ? 0x4000 : 0) | ((Mf) ? 0x2000 : 0) | (((Offset) >> 3) & 0x1fff)))
60 #define IP4_LAST_FRAGMENT(FragmentField) \
61 (((FragmentField) & IP4_HEAD_MF_MASK) == 0)
63 #define IP4_FIRST_FRAGMENT(FragmentField) \
64 ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
66 #define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)
69 /// Conver the Microsecond to second. IP transmit/receive time is
70 /// in the unit of microsecond. IP ticks once per second.
72 #define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)
75 Return the cast type (Unicast/Boradcast) specific to an
76 interface. All the addresses are host byte ordered.
78 @param[in] IpAddr The IP address to classify in host byte order
79 @param[in] IpIf The interface that IpAddr received from
81 @return The cast type of this IP address specific to the interface.
82 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
83 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the
85 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
92 IN IP4_INTERFACE
*IpIf
96 Find the cast type of the packet related to the local host.
97 This isn't the same as link layer cast type. For example, DHCP
98 server may send local broadcast to the local unicast MAC.
100 @param[in] IpSb The IP4 service binding instance that received the
102 @param[in] Dst The destination address in the packet (host byte
104 @param[in] Src The source address in the packet (host byte order)
106 @return The cast type for the Dst, it will return on the first non-promiscuous
107 cast type to a configured interface. If the packet doesn't match any of
108 the interface, multicast address and local broadcast address are checked.
113 IN IP4_SERVICE
*IpSb
,
119 Find an interface whose configured IP address is Ip.
121 @param[in] IpSb The IP4 service binding instance
122 @param[in] Ip The Ip address (host byte order) to find
124 @return The IP4_INTERFACE point if found, otherwise NULL
129 IN IP4_SERVICE
*IpSb
,
134 Find an interface that Ip is on that connected network.
136 @param[in] IpSb The IP4 service binding instance
137 @param[in] Ip The Ip address (host byte order) to find
139 @return The IP4_INTERFACE point if found, otherwise NULL
144 IN IP4_SERVICE
*IpSb
,
149 Find an interface of the service with the same Ip/Netmask pair.
151 @param[in] IpSb Ip4 service binding instance
152 @param[in] Ip The Ip adress to find (host byte order)
153 @param[in] Netmask The network to find (host byte order)
155 @return The IP4_INTERFACE point if found, otherwise NULL
159 Ip4FindStationAddress (
160 IN IP4_SERVICE
*IpSb
,
166 Get the MAC address for a multicast IP address. Call
167 Mnp's McastIpToMac to find the MAC address in stead of
168 hard code the NIC to be Ethernet.
170 @param[in] Mnp The Mnp instance to get the MAC address.
171 @param[in] Multicast The multicast IP address to translate.
172 @param[out] Mac The buffer to hold the translated address.
174 @retval EFI_SUCCESS if the multicast IP is successfully translated to a
175 multicast MAC address.
176 @retval other Otherwise some error.
181 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
,
182 IN IP4_ADDR Multicast
,
183 OUT EFI_MAC_ADDRESS
*Mac
187 Convert the multibyte field in IP header's byter order.
188 In spite of its name, it can also be used to convert from
189 host to network byte order.
191 @param[in] Head The IP head to convert
193 @return Point to the converted IP head
202 Set the Ip4 variable data.
204 Save the list of all of the IPv4 addresses and subnet masks that are currently
205 being used to volatile variable storage.
207 @param[in] IpSb Ip4 service binding instance
209 @retval EFI_SUCCESS Successfully set variable.
210 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
211 @retval other Set variable failed.
220 Clear the variable and free the resource.
222 @param[in] IpSb Ip4 service binding instance
226 Ip4ClearVariableData (