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