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