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