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