]>
Commit | Line | Data |
---|---|---|
83cbd279 | 1 | /** @file\r |
3e8c18da | 2 | Common definition for IP4.\r |
d1102dba LG |
3 | \r |
4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
83cbd279 | 6 | \r |
83cbd279 | 7 | **/\r |
8 | \r | |
9 | #ifndef __EFI_IP4_COMMON_H__\r | |
10 | #define __EFI_IP4_COMMON_H__\r | |
11 | \r | |
12 | typedef struct _IP4_INTERFACE IP4_INTERFACE;\r | |
13 | typedef struct _IP4_PROTOCOL IP4_PROTOCOL;\r | |
14 | typedef struct _IP4_SERVICE IP4_SERVICE;\r | |
15 | \r | |
f6b7393c | 16 | #define IP4_ETHER_PROTO 0x0800\r |
17 | \r | |
18 | //\r | |
19 | // The packet is received as link level broadcast/multicast/promiscuous.\r | |
20 | //\r | |
21 | #define IP4_LINK_BROADCAST 0x00000001\r | |
22 | #define IP4_LINK_MULTICAST 0x00000002\r | |
23 | #define IP4_LINK_PROMISC 0x00000004\r | |
24 | \r | |
25 | //\r | |
6c585b52 | 26 | // IP4 address cast type classification. Keep it true that any\r |
f6b7393c | 27 | // type bigger than or equal to LOCAL_BROADCAST is broadcast.\r |
28 | //\r | |
29 | #define IP4_PROMISCUOUS 1\r | |
30 | #define IP4_LOCAL_HOST 2\r | |
31 | #define IP4_MULTICAST 3\r | |
32 | #define IP4_LOCAL_BROADCAST 4 // Destination is 255.255.255.255\r | |
33 | #define IP4_SUBNET_BROADCAST 5\r | |
34 | #define IP4_NET_BROADCAST 6\r | |
35 | \r | |
36 | //\r | |
37 | // IP4 header flags\r | |
38 | //\r | |
39 | #define IP4_HEAD_DF_MASK 0x4000\r | |
40 | #define IP4_HEAD_MF_MASK 0x2000\r | |
41 | #define IP4_HEAD_OFFSET_MASK 0x1fff\r | |
83cbd279 | 42 | \r |
43 | #define IP4_ALLZERO_ADDRESS 0x00000000u\r | |
44 | #define IP4_ALLONE_ADDRESS 0xFFFFFFFFu\r | |
45 | #define IP4_ALLSYSTEM_ADDRESS 0xE0000001u\r | |
46 | #define IP4_ALLROUTER_ADDRESS 0xE0000002u\r | |
47 | \r | |
96e1079f | 48 | ///\r |
49 | /// Compose the fragment field to be used in the IP4 header.\r | |
50 | ///\r | |
83cbd279 | 51 | #define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset) \\r |
12ae56cf | 52 | ((UINT16)(((Df) ? IP4_HEAD_DF_MASK : 0) | ((Mf) ? IP4_HEAD_MF_MASK : 0) | (((Offset) >> 3) & IP4_HEAD_OFFSET_MASK)))\r |
83cbd279 | 53 | \r |
54 | #define IP4_LAST_FRAGMENT(FragmentField) \\r | |
55 | (((FragmentField) & IP4_HEAD_MF_MASK) == 0)\r | |
56 | \r | |
57 | #define IP4_FIRST_FRAGMENT(FragmentField) \\r | |
58 | ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))\r | |
59 | \r | |
216f7970 | 60 | #define IP4_DO_NOT_FRAGMENT(FragmentField) \\r |
61 | ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))\r | |
62 | \r | |
83cbd279 | 63 | #define IP4_IS_BROADCAST(CastType) ((CastType) >= IP4_LOCAL_BROADCAST)\r |
64 | \r | |
96e1079f | 65 | ///\r |
6c585b52 | 66 | /// Convert the Microsecond to second. IP transmit/receive time is\r |
96e1079f | 67 | /// in the unit of microsecond. IP ticks once per second.\r |
68 | ///\r | |
83cbd279 | 69 | #define IP4_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r |
70 | \r | |
2ff29212 | 71 | /**\r |
6c585b52 | 72 | Return the cast type (Unicast/Broadcast) specific to an\r |
2ff29212 | 73 | interface. All the addresses are host byte ordered.\r |
74 | \r | |
3e8c18da | 75 | @param[in] IpAddr The IP address to classify in host byte order\r |
76 | @param[in] IpIf The interface that IpAddr received from\r | |
2ff29212 | 77 | \r |
78 | @return The cast type of this IP address specific to the interface.\r | |
79 | @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address\r | |
6c585b52 | 80 | @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet broadcast to the\r |
2ff29212 | 81 | interface\r |
82 | @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface\r | |
83 | @retval 0 Otherwise.\r | |
84 | \r | |
85 | **/\r | |
83cbd279 | 86 | INTN\r |
87 | Ip4GetNetCast (\r | |
2ff29212 | 88 | IN IP4_ADDR IpAddr,\r |
89 | IN IP4_INTERFACE *IpIf\r | |
83cbd279 | 90 | );\r |
91 | \r | |
2ff29212 | 92 | /**\r |
93 | Find the cast type of the packet related to the local host.\r | |
94 | This isn't the same as link layer cast type. For example, DHCP\r | |
95 | server may send local broadcast to the local unicast MAC.\r | |
96 | \r | |
3e8c18da | 97 | @param[in] IpSb The IP4 service binding instance that received the\r |
98 | packet\r | |
99 | @param[in] Dst The destination address in the packet (host byte\r | |
100 | order)\r | |
101 | @param[in] Src The source address in the packet (host byte order)\r | |
2ff29212 | 102 | \r |
103 | @return The cast type for the Dst, it will return on the first non-promiscuous\r | |
104 | cast type to a configured interface. If the packet doesn't match any of\r | |
105 | the interface, multicast address and local broadcast address are checked.\r | |
106 | \r | |
107 | **/\r | |
83cbd279 | 108 | INTN\r |
109 | Ip4GetHostCast (\r | |
2ff29212 | 110 | IN IP4_SERVICE *IpSb,\r |
111 | IN IP4_ADDR Dst,\r | |
112 | IN IP4_ADDR Src\r | |
83cbd279 | 113 | );\r |
114 | \r | |
2ff29212 | 115 | /**\r |
116 | Find an interface whose configured IP address is Ip.\r | |
117 | \r | |
3e8c18da | 118 | @param[in] IpSb The IP4 service binding instance\r |
119 | @param[in] Ip The Ip address (host byte order) to find\r | |
2ff29212 | 120 | \r |
121 | @return The IP4_INTERFACE point if found, otherwise NULL\r | |
122 | \r | |
123 | **/\r | |
83cbd279 | 124 | IP4_INTERFACE *\r |
125 | Ip4FindInterface (\r | |
2ff29212 | 126 | IN IP4_SERVICE *IpSb,\r |
127 | IN IP4_ADDR Ip\r | |
83cbd279 | 128 | );\r |
129 | \r | |
2ff29212 | 130 | /**\r |
131 | Find an interface that Ip is on that connected network.\r | |
132 | \r | |
3e8c18da | 133 | @param[in] IpSb The IP4 service binding instance\r |
134 | @param[in] Ip The Ip address (host byte order) to find\r | |
2ff29212 | 135 | \r |
136 | @return The IP4_INTERFACE point if found, otherwise NULL\r | |
137 | \r | |
138 | **/\r | |
83cbd279 | 139 | IP4_INTERFACE *\r |
140 | Ip4FindNet (\r | |
2ff29212 | 141 | IN IP4_SERVICE *IpSb,\r |
142 | IN IP4_ADDR Ip\r | |
83cbd279 | 143 | );\r |
144 | \r | |
2ff29212 | 145 | /**\r |
146 | Find an interface of the service with the same Ip/Netmask pair.\r | |
147 | \r | |
3e8c18da | 148 | @param[in] IpSb Ip4 service binding instance\r |
6c585b52 | 149 | @param[in] Ip The Ip address to find (host byte order)\r |
3e8c18da | 150 | @param[in] Netmask The network to find (host byte order)\r |
2ff29212 | 151 | \r |
152 | @return The IP4_INTERFACE point if found, otherwise NULL\r | |
153 | \r | |
154 | **/\r | |
83cbd279 | 155 | IP4_INTERFACE *\r |
156 | Ip4FindStationAddress (\r | |
2ff29212 | 157 | IN IP4_SERVICE *IpSb,\r |
158 | IN IP4_ADDR Ip,\r | |
159 | IN IP4_ADDR Netmask\r | |
83cbd279 | 160 | );\r |
161 | \r | |
2ff29212 | 162 | /**\r |
163 | Get the MAC address for a multicast IP address. Call\r | |
164 | Mnp's McastIpToMac to find the MAC address in stead of\r | |
165 | hard code the NIC to be Ethernet.\r | |
166 | \r | |
3e8c18da | 167 | @param[in] Mnp The Mnp instance to get the MAC address.\r |
168 | @param[in] Multicast The multicast IP address to translate.\r | |
169 | @param[out] Mac The buffer to hold the translated address.\r | |
2ff29212 | 170 | \r |
171 | @retval EFI_SUCCESS if the multicast IP is successfully translated to a\r | |
172 | multicast MAC address.\r | |
173 | @retval other Otherwise some error.\r | |
174 | \r | |
175 | **/\r | |
83cbd279 | 176 | EFI_STATUS\r |
177 | Ip4GetMulticastMac (\r | |
178 | IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r | |
179 | IN IP4_ADDR Multicast,\r | |
180 | OUT EFI_MAC_ADDRESS *Mac\r | |
181 | );\r | |
182 | \r | |
2ff29212 | 183 | /**\r |
184 | Convert the multibyte field in IP header's byter order.\r | |
185 | In spite of its name, it can also be used to convert from\r | |
186 | host to network byte order.\r | |
187 | \r | |
3e8c18da | 188 | @param[in] Head The IP head to convert\r |
2ff29212 | 189 | \r |
190 | @return Point to the converted IP head\r | |
191 | \r | |
192 | **/\r | |
83cbd279 | 193 | IP4_HEAD *\r |
194 | Ip4NtohHead (\r | |
2ff29212 | 195 | IN IP4_HEAD *Head\r |
83cbd279 | 196 | );\r |
197 | \r | |
f1222593 JW |
198 | \r |
199 | /**\r | |
200 | Validate that Ip/Netmask pair is OK to be used as station\r | |
201 | address. Only continuous netmasks are supported. and check\r | |
6c585b52 | 202 | that StationAddress is a unicast address on the network.\r |
f1222593 JW |
203 | \r |
204 | @param[in] Ip The IP address to validate.\r | |
6c585b52 | 205 | @param[in] Netmask The netmask of the IP.\r |
f1222593 JW |
206 | \r |
207 | @retval TRUE The Ip/Netmask pair is valid.\r | |
208 | @retval FALSE The Ip/Netmask pair is invalid.\r | |
209 | \r | |
210 | **/\r | |
211 | BOOLEAN\r | |
212 | Ip4StationAddressValid (\r | |
213 | IN IP4_ADDR Ip,\r | |
214 | IN IP4_ADDR Netmask\r | |
215 | );\r | |
216 | \r | |
83cbd279 | 217 | #endif\r |