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