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