]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Ip6Dxe/Ip6Common.h
1. Fix bugs for PXE-IPv6 to accommodate the situation:
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Common.h
CommitLineData
a3bcde70
HT
1/** @file\r
2 Common definition and functions for IP6 driver.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef __EFI_IP6_COMMON_H__\r
17#define __EFI_IP6_COMMON_H__\r
18\r
19#define IP6_LINK_EQUAL(Mac1, Mac2) (CompareMem ((Mac1), (Mac2), sizeof (EFI_MAC_ADDRESS)) == 0)\r
20\r
21//\r
22// Convert the Microsecond to second. IP transmit/receive time is\r
23// in the unit of microsecond. IP ticks once per second.\r
24//\r
25#define IP6_US_TO_SEC(Us) (((Us) + 999999) / 1000000)\r
26\r
27#define IP6_ETHER_PROTO 0x86DD\r
28\r
29#define IP6_MAC_LEN 6\r
30#define IP6_IF_ID_LEN 8\r
31\r
32#define IP6_INTERFACE_LOCAL_SCOPE 1\r
33#define IP6_LINK_LOCAL_SCOPE 2\r
34#define IP6_SITE_LOCAL_SCOPE 5\r
35\r
36#define IP6_INFINIT_LIFETIME 0xFFFFFFFF\r
37\r
38#define IP6_HOP_LIMIT 255\r
39//\r
40// Make it to 64 since all 54 bits are zero.\r
41//\r
42#define IP6_LINK_LOCAL_PREFIX_LENGTH 64\r
43\r
44#define IP6_TIMER_INTERVAL_IN_MS 100\r
45#define IP6_ONE_SECOND_IN_MS 1000\r
46\r
47//\r
48// The packet is received as link level broadcast/multicast/promiscuous.\r
49//\r
50#define IP6_LINK_BROADCAST 0x00000001\r
51#define IP6_LINK_MULTICAST 0x00000002\r
52#define IP6_LINK_PROMISC 0x00000004\r
53\r
54#define IP6_U_BIT 0x02\r
55\r
56typedef enum {\r
57 Ip6Promiscuous = 1,\r
58 Ip6Unicast,\r
59 Ip6Multicast,\r
60 Ip6AnyCast\r
61} IP6_ADDRESS_TYPE;\r
62\r
63typedef struct _IP6_INTERFACE IP6_INTERFACE;\r
64typedef struct _IP6_PROTOCOL IP6_PROTOCOL;\r
65typedef struct _IP6_SERVICE IP6_SERVICE;\r
66typedef struct _IP6_ADDRESS_INFO IP6_ADDRESS_INFO;\r
67\r
68/**\r
69 Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number\r
70 of EFI_IP6_ADDRESS_INFO is also returned. If AddressList is NULL,\r
71 only the address count is returned.\r
72\r
73 @param[in] IpSb The IP6 service binding instance.\r
74 @param[out] AddressCount The number of returned addresses.\r
75 @param[out] AddressList The pointer to the array of EFI_IP6_ADDRESS_INFO.\r
76 This is an optional parameter.\r
77\r
78\r
79 @retval EFI_SUCCESS The address array is successfully build\r
80 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the address info.\r
81 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
82\r
83**/\r
84EFI_STATUS\r
85Ip6BuildEfiAddressList (\r
86 IN IP6_SERVICE *IpSb,\r
87 OUT UINT32 *AddressCount,\r
88 OUT EFI_IP6_ADDRESS_INFO **AddressList OPTIONAL\r
89 );\r
90\r
91/**\r
92 Generate the multicast addresses identify the group of all IPv6 nodes or IPv6\r
93 routers defined in RFC4291.\r
94\r
95 All Nodes Addresses: FF01::1, FF02::1.\r
96 All Router Addresses: FF01::2, FF02::2, FF05::2.\r
97\r
98 @param[in] Router If TRUE, generate all routers addresses,\r
99 else generate all node addresses.\r
100 @param[in] Scope interface-local(1), link-local(2), or site-local(5)\r
101 @param[out] Ip6Addr The generated multicast address.\r
102\r
103 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
104 @retval EFI_SUCCESS The address is generated.\r
105\r
106**/\r
107EFI_STATUS\r
108Ip6SetToAllNodeMulticast (\r
109 IN BOOLEAN Router,\r
110 IN UINT8 Scope,\r
111 OUT EFI_IPv6_ADDRESS *Ip6Addr\r
112 );\r
113\r
114/**\r
115 This function converts MAC address to 64 bits interface ID according to RFC4291\r
116 and returns the interface ID. Currently only 48-bit MAC address is supported by\r
117 this function.\r
118\r
119 @param[in, out] IpSb The IP6 service binding instance.\r
120\r
121 @retval NULL The operation fails.\r
122 @return Pointer to the generated interface ID.\r
123\r
124**/\r
125UINT8 *\r
126Ip6CreateInterfaceID (\r
127 IN OUT IP6_SERVICE *IpSb\r
128 );\r
129\r
130/**\r
131 This function creates link-local address from interface identifier. The\r
132 interface identifier is normally created from MAC address. It might be manually\r
133 configured by administrator if the link-local address created from MAC address\r
134 is a duplicate address.\r
135\r
136 @param[in, out] IpSb The IP6 service binding instance.\r
137\r
138 @retval NULL If the operation fails.\r
139 @return The generated Link Local address, in network order.\r
140\r
141**/\r
142EFI_IPv6_ADDRESS *\r
143Ip6CreateLinkLocalAddr (\r
144 IN OUT IP6_SERVICE *IpSb\r
145 );\r
146\r
147/**\r
148 Compute the solicited-node multicast address for an unicast or anycast address,\r
149 by taking the low-order 24 bits of this address, and appending those bits to\r
150 the prefix FF02:0:0:0:0:1:FF00::/104.\r
151\r
152 @param Ip6Addr The unicast or anycast address, in network order.\r
153 @param MulticastAddr The generated solicited-node multicast address,\r
154 in network order.\r
155\r
156**/\r
157VOID\r
158Ip6CreateSNMulticastAddr (\r
159 IN EFI_IPv6_ADDRESS *Ip6Addr,\r
160 OUT EFI_IPv6_ADDRESS *MulticastAddr\r
161 );\r
162\r
163/**\r
164 Check whether the incoming Ipv6 address is a solicited-node multicast address.\r
165\r
166 @param[in] Ip6 Ip6 address, in network order.\r
167\r
168 @retval TRUE Yes, solicited-node multicast address\r
169 @retval FALSE No\r
170\r
171**/\r
172BOOLEAN\r
173Ip6IsSNMulticastAddr (\r
174 IN EFI_IPv6_ADDRESS *Ip6\r
175 );\r
176\r
177/**\r
178 Check whether the incoming IPv6 address is one of the maintained address in\r
179 the IP6 service binding instance.\r
180\r
181 @param[in] IpSb Points to a IP6 service binding instance\r
182 @param[in] Address The IP6 address to be checked.\r
183 @param[out] Interface If not NULL, output the IP6 interface which\r
184 maintains the Address.\r
185 @param[out] AddressInfo If not NULL, output the IP6 address information\r
186 of the Address.\r
187\r
188 @retval TRUE Yes, it is one of the maintained addresses.\r
189 @retval FALSE No, it is not one of the maintained addresses.\r
190\r
191**/\r
192BOOLEAN\r
193Ip6IsOneOfSetAddress (\r
194 IN IP6_SERVICE *IpSb,\r
195 IN EFI_IPv6_ADDRESS *Address,\r
196 OUT IP6_INTERFACE **Interface OPTIONAL,\r
197 OUT IP6_ADDRESS_INFO **AddressInfo OPTIONAL\r
198 );\r
199\r
200/**\r
201 Check whether the incoming MAC address is valid.\r
202\r
203 @param[in] IpSb Points to a IP6 service binding instance.\r
204 @param[in] LinkAddress The MAC address.\r
205\r
206 @retval TRUE Yes, it is valid.\r
207 @retval FALSE No, it is not valid.\r
208\r
209**/\r
210BOOLEAN\r
211Ip6IsValidLinkAddress (\r
212 IN IP6_SERVICE *IpSb,\r
213 IN EFI_MAC_ADDRESS *LinkAddress\r
214 );\r
215\r
216\r
217/**\r
218 Copy the PrefixLength bits from Src to Dest.\r
219\r
220 @param[out] Dest A pointer to the buffer to copy to.\r
221 @param[in] Src A pointer to the buffer to copy from.\r
222 @param[in] PrefixLength The number of bits to copy.\r
223\r
224**/\r
225VOID\r
226Ip6CopyAddressByPrefix (\r
227 OUT EFI_IPv6_ADDRESS *Dest,\r
228 IN EFI_IPv6_ADDRESS *Src,\r
229 IN UINT8 PrefixLength\r
230 );\r
231\r
232/**\r
233 Insert a node IP6_ADDRESS_INFO to an IP6 interface.\r
234\r
235 @param[in, out] IpIf Points to an IP6 interface.\r
236 @param[in] AddrInfo Points to an IP6_ADDRESS_INFO.\r
237\r
238**/\r
239VOID\r
240Ip6AddAddr (\r
241 IN OUT IP6_INTERFACE *IpIf,\r
242 IN IP6_ADDRESS_INFO *AddrInfo\r
243 );\r
244\r
245/**\r
246 Remove the IPv6 address from the address list node points to IP6_ADDRESS_INFO.\r
247\r
248 This function removes the matching IPv6 addresses from the address list and\r
249 adjusts the address count of the address list. If IpSb is not NULL, this function\r
250 calls Ip6LeaveGroup to see whether it should call Mnp->Groups() to remove the\r
251 its solicited-node multicast MAC address from the filter list and sends out\r
252 a Multicast Listener Done. If Prefix is NULL, all address in the address list\r
253 will be removed. If Prefix is not NULL, the address that matching the Prefix\r
254 with PrefixLength in the address list will be removed.\r
255\r
256 @param[in] IpSb NULL or points to IP6 service binding instance.\r
257 @param[in, out] AddressList address list array\r
258 @param[in, out] AddressCount the count of addresses in address list array\r
259 @param[in] Prefix NULL or an IPv6 address prefix\r
260 @param[in] PrefixLength the length of Prefix\r
261\r
262 @retval EFI_SUCCESS The operation completed successfully.\r
263 @retval EFI_NOT_FOUND The address matching the Prefix with PrefixLength\r
264 cannot be found in address list.\r
265 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
266\r
267**/\r
268EFI_STATUS\r
269Ip6RemoveAddr (\r
270 IN IP6_SERVICE *IpSb OPTIONAL,\r
271 IN OUT LIST_ENTRY *AddressList,\r
272 IN OUT UINT32 *AddressCount,\r
273 IN EFI_IPv6_ADDRESS *Prefix OPTIONAL,\r
274 IN UINT8 PrefixLength\r
275 );\r
276\r
277/**\r
278 Set the Ip6 variable data.\r
279\r
280 @param[in] IpSb Points to an IP6 service binding instance\r
281\r
282 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.\r
283 @retval other Set variable failed.\r
284\r
285**/\r
286EFI_STATUS\r
287Ip6SetVariableData (\r
288 IN IP6_SERVICE *IpSb\r
289 );\r
290\r
291/**\r
292 Clear the variable and free the resource.\r
293\r
294 @param[in] IpSb Ip6 service binding instance.\r
295\r
296**/\r
297VOID\r
298Ip6ClearVariableData (\r
299 IN IP6_SERVICE *IpSb\r
300 );\r
301\r
302/**\r
303 Get the MAC address for a multicast IP address. Call\r
304 Mnp's McastIpToMac to find the MAC address instead of\r
305 hard-coding the NIC to be Ethernet.\r
306\r
307 @param[in] Mnp The Mnp instance to get the MAC address.\r
308 @param[in] Multicast The multicast IP address to translate.\r
309 @param[out] Mac The buffer to hold the translated address.\r
310\r
311 @retval EFI_SUCCESS The multicast IP is successfully\r
312 translated to a multicast MAC address.\r
313 @retval Other The address is not converted because an error occurred.\r
314\r
315**/\r
316EFI_STATUS\r
317Ip6GetMulticastMac (\r
318 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,\r
319 IN EFI_IPv6_ADDRESS *Multicast,\r
320 OUT EFI_MAC_ADDRESS *Mac\r
321 );\r
322\r
323/**\r
324 Convert the multibyte field in IP header's byter order.\r
325 In spite of its name, it can also be used to convert from\r
326 host to network byte order.\r
327\r
328 @param[in, out] Head The IP head to convert.\r
329\r
330 @return Point to the converted IP head.\r
331\r
332**/\r
333EFI_IP6_HEADER *\r
334Ip6NtohHead (\r
335 IN OUT EFI_IP6_HEADER *Head\r
336 );\r
337\r
338#endif\r