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