]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Ip4 internal functions and type defintions.\r | |
3 | \r | |
4 | Copyright (c) 2005 - 2009, Intel Corporation.<BR> \r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef __EFI_IP4_IMPL_H__\r | |
16 | #define __EFI_IP4_IMPL_H__\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | \r | |
20 | #include <Protocol/IpSec.h>\r | |
21 | #include <Protocol/Ip4.h>\r | |
22 | #include <Protocol/Ip4Config.h>\r | |
23 | #include <Protocol/Arp.h>\r | |
24 | #include <Protocol/ManagedNetwork.h>\r | |
25 | \r | |
26 | #include <Library/DebugLib.h>\r | |
27 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
28 | #include <Library/UefiDriverEntryPoint.h>\r | |
29 | #include <Library/UefiBootServicesTableLib.h>\r | |
30 | #include <Library/BaseLib.h>\r | |
31 | #include <Library/UefiLib.h>\r | |
32 | #include <Library/NetLib.h>\r | |
33 | #include <Library/BaseMemoryLib.h>\r | |
34 | #include <Library/MemoryAllocationLib.h>\r | |
35 | #include <Library/DpcLib.h>\r | |
36 | \r | |
37 | #include "Ip4Common.h"\r | |
38 | #include "Ip4Driver.h"\r | |
39 | #include "Ip4If.h"\r | |
40 | #include "Ip4Icmp.h"\r | |
41 | #include "Ip4Option.h"\r | |
42 | #include "Ip4Igmp.h"\r | |
43 | #include "Ip4Route.h"\r | |
44 | #include "Ip4Input.h"\r | |
45 | #include "Ip4Output.h"\r | |
46 | \r | |
47 | #define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')\r | |
48 | #define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')\r | |
49 | \r | |
50 | //\r | |
51 | // The state of IP4 protocol. It starts from UNCONFIGED. if it is\r | |
52 | // successfully configured, it goes to CONFIGED. if configure NULL\r | |
53 | // is called, it becomes UNCONFIGED again. If (partly) destoried, it\r | |
54 | // becomes DESTORY.\r | |
55 | //\r | |
56 | #define IP4_STATE_UNCONFIGED 0\r | |
57 | #define IP4_STATE_CONFIGED 1\r | |
58 | #define IP4_STATE_DESTORY 2\r | |
59 | \r | |
60 | //\r | |
61 | // The state of IP4 service. It starts from UNSTARTED. It transits\r | |
62 | // to STARTED if autoconfigure is started. If default address is\r | |
63 | // configured, it becomes CONFIGED. and if partly destoried, it goes\r | |
64 | // to DESTORY.\r | |
65 | //\r | |
66 | #define IP4_SERVICE_UNSTARTED 0\r | |
67 | #define IP4_SERVICE_STARTED 1\r | |
68 | #define IP4_SERVICE_CONFIGED 2\r | |
69 | #define IP4_SERVICE_DESTORY 3\r | |
70 | \r | |
71 | \r | |
72 | ///\r | |
73 | /// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.\r | |
74 | /// The user's data is kept in the Packet. When fragment is\r | |
75 | /// needed, each fragment of the Packet has a reference to the\r | |
76 | /// Packet, no data is actually copied. The Packet will be\r | |
77 | /// released when all the fragments of it have been recycled by\r | |
78 | /// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and\r | |
79 | /// user's event signalled.\r | |
80 | ///\r | |
81 | typedef struct {\r | |
82 | IP4_PROTOCOL *IpInstance;\r | |
83 | EFI_IP4_COMPLETION_TOKEN *Token;\r | |
84 | EFI_EVENT IpSecRecycleSignal;\r | |
85 | NET_BUF *Packet;\r | |
86 | BOOLEAN Sent;\r | |
87 | INTN Life;\r | |
88 | } IP4_TXTOKEN_WRAP;\r | |
89 | \r | |
90 | ///\r | |
91 | /// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r | |
92 | /// will be released after it has been processed by the receiver. Upon then,\r | |
93 | /// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r | |
94 | /// to notice IPsec to free the resources.\r | |
95 | ///\r | |
96 | typedef struct {\r | |
97 | EFI_EVENT IpSecRecycleSignal;\r | |
98 | NET_BUF *Packet;\r | |
99 | } IP4_IPSEC_WRAP;\r | |
100 | \r | |
101 | ///\r | |
102 | /// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r | |
103 | /// upper layers. The received packet is kept in the Packet.\r | |
104 | /// The Packet itself may be constructured from some fragments.\r | |
105 | /// All the fragments of the Packet is organized by a\r | |
106 | /// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by\r | |
107 | /// the upper layer, the assemble entry and its associated\r | |
108 | /// fragments will be freed at last.\r | |
109 | ///\r | |
110 | typedef struct {\r | |
111 | LIST_ENTRY Link;\r | |
112 | IP4_PROTOCOL *IpInstance;\r | |
113 | NET_BUF *Packet;\r | |
114 | EFI_IP4_RECEIVE_DATA RxData;\r | |
115 | } IP4_RXDATA_WRAP;\r | |
116 | \r | |
117 | \r | |
118 | struct _IP4_PROTOCOL {\r | |
119 | UINT32 Signature;\r | |
120 | \r | |
121 | EFI_IP4_PROTOCOL Ip4Proto;\r | |
122 | EFI_HANDLE Handle;\r | |
123 | INTN State;\r | |
124 | \r | |
125 | IP4_SERVICE *Service;\r | |
126 | LIST_ENTRY Link; // Link to all the IP protocol from the service\r | |
127 | \r | |
128 | //\r | |
129 | // User's transmit/receive tokens, and received/deliverd packets\r | |
130 | //\r | |
131 | NET_MAP RxTokens;\r | |
132 | NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)\r | |
133 | LIST_ENTRY Received; // Received but not delivered packet\r | |
134 | LIST_ENTRY Delivered; // Delivered and to be recycled packets\r | |
135 | EFI_LOCK RecycleLock;\r | |
136 | \r | |
137 | //\r | |
138 | // Instance's address and route tables. There are two route tables.\r | |
139 | // RouteTable is used by the IP4 driver to route packet. EfiRouteTable\r | |
140 | // is used to communicate the current route info to the upper layer.\r | |
141 | //\r | |
142 | IP4_INTERFACE *Interface;\r | |
143 | LIST_ENTRY AddrLink; // Ip instances with the same IP address.\r | |
144 | IP4_ROUTE_TABLE *RouteTable;\r | |
145 | \r | |
146 | EFI_IP4_ROUTE_TABLE *EfiRouteTable;\r | |
147 | UINT32 EfiRouteCount;\r | |
148 | \r | |
149 | //\r | |
150 | // IGMP data for this instance\r | |
151 | //\r | |
152 | IP4_ADDR *Groups; // stored in network byte order\r | |
153 | UINT32 GroupCount;\r | |
154 | \r | |
155 | EFI_IP4_CONFIG_DATA ConfigData;\r | |
156 | \r | |
157 | };\r | |
158 | \r | |
159 | struct _IP4_SERVICE {\r | |
160 | UINT32 Signature;\r | |
161 | EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r | |
162 | INTN State;\r | |
163 | BOOLEAN InDestory;\r | |
164 | \r | |
165 | //\r | |
166 | // List of all the IP instances and interfaces, and default\r | |
167 | // interface and route table and caches.\r | |
168 | //\r | |
169 | UINTN NumChildren;\r | |
170 | LIST_ENTRY Children;\r | |
171 | \r | |
172 | LIST_ENTRY Interfaces;\r | |
173 | \r | |
174 | IP4_INTERFACE *DefaultInterface;\r | |
175 | IP4_ROUTE_TABLE *DefaultRouteTable;\r | |
176 | \r | |
177 | //\r | |
178 | // Ip reassemble utilities, and IGMP data\r | |
179 | //\r | |
180 | IP4_ASSEMBLE_TABLE Assemble;\r | |
181 | IGMP_SERVICE_DATA IgmpCtrl;\r | |
182 | \r | |
183 | //\r | |
184 | // Low level protocol used by this service instance\r | |
185 | //\r | |
186 | EFI_HANDLE Image;\r | |
187 | EFI_HANDLE Controller;\r | |
188 | \r | |
189 | EFI_HANDLE MnpChildHandle;\r | |
190 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
191 | \r | |
192 | EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;\r | |
193 | EFI_SIMPLE_NETWORK_MODE SnpMode;\r | |
194 | \r | |
195 | EFI_EVENT Timer;\r | |
196 | \r | |
197 | //\r | |
198 | // Auto configure staff\r | |
199 | //\r | |
200 | EFI_IP4_CONFIG_PROTOCOL *Ip4Config;\r | |
201 | EFI_EVENT DoneEvent;\r | |
202 | EFI_EVENT ReconfigEvent;\r | |
203 | EFI_EVENT ActiveEvent;\r | |
204 | \r | |
205 | //\r | |
206 | // The string representation of the current mac address of the\r | |
207 | // NIC this IP4_SERVICE works on.\r | |
208 | //\r | |
209 | CHAR16 *MacString;\r | |
210 | UINT32 MaxPacketSize;\r | |
211 | UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.\r | |
212 | };\r | |
213 | \r | |
214 | #define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r | |
215 | CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)\r | |
216 | \r | |
217 | #define IP4_SERVICE_FROM_PROTOCOL(Sb) \\r | |
218 | CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)\r | |
219 | \r | |
220 | #define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)\r | |
221 | \r | |
222 | extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;\r | |
223 | \r | |
224 | /**\r | |
225 | Config the MNP parameter used by IP. The IP driver use one MNP\r | |
226 | child to transmit/receive frames. By default, it configures MNP\r | |
227 | to receive unicast/multicast/broadcast. And it will enable/disable\r | |
228 | the promiscous receive according to whether there is IP child\r | |
229 | enable that or not. If Force is FALSE, it will iterate through\r | |
230 | all the IP children to check whether the promiscuous receive\r | |
231 | setting has been changed. If it hasn't been changed, it won't\r | |
232 | reconfigure the MNP. If Force is TRUE, the MNP is configured no\r | |
233 | matter whether that is changed or not.\r | |
234 | \r | |
235 | @param[in] IpSb The IP4 service instance that is to be changed.\r | |
236 | @param[in] Force Force the configuration or not.\r | |
237 | \r | |
238 | @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r | |
239 | @retval Others Configuration failed.\r | |
240 | \r | |
241 | **/\r | |
242 | EFI_STATUS\r | |
243 | Ip4ServiceConfigMnp (\r | |
244 | IN IP4_SERVICE *IpSb,\r | |
245 | IN BOOLEAN Force\r | |
246 | );\r | |
247 | \r | |
248 | /**\r | |
249 | Intiialize the IP4_PROTOCOL structure to the unconfigured states.\r | |
250 | \r | |
251 | @param IpSb The IP4 service instance.\r | |
252 | @param IpInstance The IP4 child instance.\r | |
253 | \r | |
254 | **/\r | |
255 | VOID\r | |
256 | Ip4InitProtocol (\r | |
257 | IN IP4_SERVICE *IpSb,\r | |
258 | IN OUT IP4_PROTOCOL *IpInstance\r | |
259 | );\r | |
260 | \r | |
261 | /**\r | |
262 | Clean up the IP4 child, release all the resources used by it.\r | |
263 | \r | |
264 | @param[in] IpInstance The IP4 child to clean up.\r | |
265 | \r | |
266 | @retval EFI_SUCCESS The IP4 child is cleaned up\r | |
267 | @retval EFI_DEVICE_ERROR Some resources failed to be released\r | |
268 | \r | |
269 | **/\r | |
270 | EFI_STATUS\r | |
271 | Ip4CleanProtocol (\r | |
272 | IN IP4_PROTOCOL *IpInstance\r | |
273 | );\r | |
274 | \r | |
275 | /**\r | |
276 | Cancel the user's receive/transmit request.\r | |
277 | \r | |
278 | @param[in] IpInstance The IP4 child\r | |
279 | @param[in] Token The token to cancel. If NULL, all token will be\r | |
280 | cancelled.\r | |
281 | \r | |
282 | @retval EFI_SUCCESS The token is cancelled\r | |
283 | @retval EFI_NOT_FOUND The token isn't found on either the\r | |
284 | transmit/receive queue\r | |
285 | @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r | |
286 | \r | |
287 | **/\r | |
288 | EFI_STATUS\r | |
289 | Ip4Cancel (\r | |
290 | IN IP4_PROTOCOL *IpInstance,\r | |
291 | IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r | |
292 | );\r | |
293 | \r | |
294 | /**\r | |
295 | Change the IP4 child's multicast setting. The caller\r | |
296 | should make sure that the parameters is valid.\r | |
297 | \r | |
298 | @param[in] IpInstance The IP4 child to change the setting.\r | |
299 | @param[in] JoinFlag TRUE to join the group, otherwise leave it\r | |
300 | @param[in] GroupAddress The target group address\r | |
301 | \r | |
302 | @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r | |
303 | @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r | |
304 | @retval EFI_DEVICE_ERROR Failed to set the group configuraton\r | |
305 | @retval EFI_SUCCESS Successfully updated the group setting.\r | |
306 | @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r | |
307 | \r | |
308 | **/\r | |
309 | EFI_STATUS\r | |
310 | Ip4Groups (\r | |
311 | IN IP4_PROTOCOL *IpInstance,\r | |
312 | IN BOOLEAN JoinFlag,\r | |
313 | IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r | |
314 | );\r | |
315 | \r | |
316 | /**\r | |
317 | The heart beat timer of IP4 service instance. It times out\r | |
318 | all of its IP4 children's received-but-not-delivered and\r | |
319 | transmitted-but-not-recycle packets, and provides time input\r | |
320 | for its IGMP protocol.\r | |
321 | \r | |
322 | @param[in] Event The IP4 service instance's heart beat timer.\r | |
323 | @param[in] Context The IP4 service instance.\r | |
324 | \r | |
325 | **/\r | |
326 | VOID\r | |
327 | EFIAPI\r | |
328 | Ip4TimerTicking (\r | |
329 | IN EFI_EVENT Event,\r | |
330 | IN VOID *Context\r | |
331 | );\r | |
332 | \r | |
333 | /**\r | |
334 | Decrease the life of the transmitted packets. If it is\r | |
335 | decreased to zero, cancel the packet. This function is\r | |
336 | called by Ip4PacketTimerTicking which time out both the\r | |
337 | received-but-not-delivered and transmitted-but-not-recycle\r | |
338 | packets.\r | |
339 | \r | |
340 | @param[in] Map The IP4 child's transmit map.\r | |
341 | @param[in] Item Current transmitted packet\r | |
342 | @param[in] Context Not used.\r | |
343 | \r | |
344 | @retval EFI_SUCCESS Always returns EFI_SUCCESS\r | |
345 | \r | |
346 | **/\r | |
347 | EFI_STATUS\r | |
348 | Ip4SentPacketTicking (\r | |
349 | IN NET_MAP *Map,\r | |
350 | IN NET_MAP_ITEM *Item,\r | |
351 | IN VOID *Context\r | |
352 | );\r | |
353 | \r | |
354 | /**\r | |
355 | The callback function for the net buffer which wraps the user's\r | |
356 | transmit token. Although it seems this function is pretty simple,\r | |
357 | there are some subtle things.\r | |
358 | When user requests the IP to transmit a packet by passing it a\r | |
359 | token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r | |
360 | is wrapped in an net buffer. the net buffer's Free function is\r | |
361 | set to Ip4FreeTxToken. The Token and token wrap are added to the\r | |
362 | IP child's TxToken map. Then the buffer is passed to Ip4Output for\r | |
363 | transmission. If something error happened before that, the buffer\r | |
364 | is freed, which in turn will free the token wrap. The wrap may\r | |
365 | have been added to the TxToken map or not, and the user's event\r | |
366 | shouldn't be fired because we are still in the EfiIp4Transmit. If\r | |
367 | the buffer has been sent by Ip4Output, it should be removed from\r | |
368 | the TxToken map and user's event signaled. The token wrap and buffer\r | |
369 | are bound together. Check the comments in Ip4Output for information\r | |
370 | about IP fragmentation.\r | |
371 | \r | |
372 | @param[in] Context The token's wrap\r | |
373 | \r | |
374 | **/\r | |
375 | VOID\r | |
376 | Ip4FreeTxToken (\r | |
377 | IN VOID *Context\r | |
378 | );\r | |
379 | \r | |
380 | extern EFI_IPSEC_PROTOCOL *mIpSec;\r | |
381 | \r | |
382 | #endif\r |