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