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