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