]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.h
e32764d80b858bef612c3d2fab934bbea280a1d0
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4If.h
1 /** @file
2
3 Copyright (c) 2005 - 2006, 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
13 Module Name:
14
15 Ip4If.h
16
17 Abstract:
18
19 Definition for IP4 pesudo interface structure.
20
21
22 **/
23
24 #ifndef __EFI_IP4_IF_H__
25 #define __EFI_IP4_IF_H__
26
27 typedef enum {
28 IP4_FRAME_RX_SIGNATURE = SIGNATURE_32 ('I', 'P', 'F', 'R'),
29 IP4_FRAME_TX_SIGNATURE = SIGNATURE_32 ('I', 'P', 'F', 'T'),
30 IP4_FRAME_ARP_SIGNATURE = SIGNATURE_32 ('I', 'P', 'F', 'A'),
31 IP4_INTERFACE_SIGNATURE = SIGNATURE_32 ('I', 'P', 'I', 'F')
32 } IP4_IF_ENUM_TYPES;
33
34 /**
35 This prototype is used by both receive and transmission.
36 When receiving Netbuf is allocated by IP4_INTERFACE, and
37 released by IP4. Flag shows whether the frame is received
38 as link broadcast/multicast...
39
40 When transmitting, the Netbuf is from IP4, and provided
41 to the callback as a reference. Flag isn't used.
42
43 @param IpInstance The instance that sent or received the packet.
44 IpInstance can be NULL which means that it is the IP4 driver
45 itself sending the packets. IP4 driver may send packets that
46 don't belong to any instance, such as ICMP errors, ICMP echo
47 responses, or IGMP packets. IpInstance is used as a tag in
48 this module.
49 @param Packet The sent or received packet.
50 @param IoStatus Status of sending or receiving.
51 @param LinkFlag Indicate if the frame is received as link broadcast/multicast.
52 When transmitting, it is not used.
53 @param Context Additional data for callback.
54
55 @return None.
56 **/
57 typedef
58 VOID
59 (*IP4_FRAME_CALLBACK)(
60 IN IP4_PROTOCOL *IpInstance, OPTIONAL
61 IN NET_BUF *Packet,
62 IN EFI_STATUS IoStatus,
63 IN UINT32 LinkFlag,
64 IN VOID *Context
65 );
66
67 ///
68 /// Each receive request is wrapped in an IP4_LINK_RX_TOKEN.
69 /// Upon completion, the Callback will be called. Only one
70 /// receive request is send to MNP. IpInstance is always NULL.
71 /// Reference MNP's spec for information.
72 ///
73 typedef struct {
74 UINT32 Signature;
75 IP4_INTERFACE *Interface;
76
77 IP4_PROTOCOL *IpInstance;
78 IP4_FRAME_CALLBACK CallBack;
79 VOID *Context;
80
81 EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
82 } IP4_LINK_RX_TOKEN;
83
84 ///
85 /// Each transmit request is wrapped in an IP4_LINK_TX_TOKEN.
86 /// Upon completion, the Callback will be called.
87 ///
88 typedef struct {
89 UINT32 Signature;
90 LIST_ENTRY Link;
91
92 IP4_INTERFACE *Interface;
93
94 IP4_PROTOCOL *IpInstance;
95 IP4_FRAME_CALLBACK CallBack;
96 NET_BUF *Packet;
97 VOID *Context;
98
99 EFI_MAC_ADDRESS DstMac;
100 EFI_MAC_ADDRESS SrcMac;
101
102 EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
103 EFI_MANAGED_NETWORK_TRANSMIT_DATA MnpTxData;
104 } IP4_LINK_TX_TOKEN;
105
106 ///
107 /// Only one ARP request is requested for all the frames in
108 /// a time. It is started for the first frames to the Ip. Any
109 /// subsequent transmission frame will be linked to Frames, and
110 /// be sent all at once the ARP requests succeed.
111 ///
112 typedef struct {
113 UINT32 Signature;
114 LIST_ENTRY Link;
115
116 LIST_ENTRY Frames;
117 IP4_INTERFACE *Interface;
118
119 //
120 // ARP requesting staffs
121 //
122 EFI_EVENT OnResolved;
123 IP4_ADDR Ip;
124 EFI_MAC_ADDRESS Mac;
125 } IP4_ARP_QUE;
126
127 /**
128 Callback to select which frame to cancel. Caller can cancel a
129 single frame, or all the frame from an IP instance.
130
131 @param Frame The sending frame to check for cancellation.
132 @param Context Additional data for callback.
133
134 @retval TRUE The sending of the frame should be cancelled.
135 @retval FALSE Do not cancel the frame sending.
136 **/
137 typedef
138 BOOLEAN
139 (*IP4_FRAME_TO_CANCEL)(
140 IP4_LINK_TX_TOKEN *Frame,
141 VOID *Context
142 );
143
144 //
145 // Each IP4 instance has its own station address. All the instances
146 // with the same station address share a single interface structure.
147 // Each interface has its own ARP child, and shares one MNP child.
148 // Notice the special cases that DHCP can configure the interface
149 // with 0.0.0.0/0.0.0.0.
150 //
151 struct _IP4_INTERFACE {
152 UINT32 Signature;
153 LIST_ENTRY Link;
154 INTN RefCnt;
155
156 //
157 // IP address and subnet mask of the interface. It also contains
158 // the subnet/net broadcast address for quick access. The fileds
159 // are invalid if (Configured == FALSE)
160 //
161 IP4_ADDR Ip;
162 IP4_ADDR SubnetMask;
163 IP4_ADDR SubnetBrdcast;
164 IP4_ADDR NetBrdcast;
165 BOOLEAN Configured;
166
167 //
168 // Handle used to create/destory ARP child. All the IP children
169 // share one MNP which is owned by IP service binding.
170 //
171 EFI_HANDLE Controller;
172 EFI_HANDLE Image;
173
174 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
175 EFI_ARP_PROTOCOL *Arp;
176 EFI_HANDLE ArpHandle;
177
178 //
179 // Queues to keep the frames sent and waiting ARP request.
180 //
181 LIST_ENTRY ArpQues;
182 LIST_ENTRY SentFrames;
183 IP4_LINK_RX_TOKEN *RecvRequest;
184
185 //
186 // The interface's MAC and broadcast MAC address.
187 //
188 EFI_MAC_ADDRESS Mac;
189 EFI_MAC_ADDRESS BroadcastMac;
190 UINT32 HwaddrLen;
191
192 //
193 // All the IP instances that have the same IP/SubnetMask are linked
194 // together through IpInstances. If any of the instance enables
195 // promiscuous receive, PromiscRecv is true.
196 //
197 LIST_ENTRY IpInstances;
198 BOOLEAN PromiscRecv;
199 };
200
201 /**
202 Create an IP4_INTERFACE. Delay the creation of ARP instance until
203 the interface is configured.
204
205 @param Mnp The shared MNP child of this IP4 service binding
206 instance
207 @param Controller The controller this IP4 service binding instance
208 is installed. Most like the UNDI handle.
209 @param ImageHandle This driver's image handle
210
211 @return Point to the created IP4_INTERFACE, otherwise NULL.
212
213 **/
214 IP4_INTERFACE *
215 Ip4CreateInterface (
216 IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
217 IN EFI_HANDLE Controller,
218 IN EFI_HANDLE ImageHandle
219 );
220
221 /**
222 Set the interface's address, create and configure
223 the ARP child if necessary.
224
225 @param Interface The interface to set the address
226 @param IpAddr The interface's IP address
227 @param SubnetMask The interface's netmask
228
229 @retval EFI_SUCCESS The interface is configured with Ip/netmask pair,
230 and a ARP is created for it.
231 @retval Others Failed to set the interface's address.
232
233 **/
234 EFI_STATUS
235 Ip4SetAddress (
236 IN OUT IP4_INTERFACE *Interface,
237 IN IP4_ADDR IpAddr,
238 IN IP4_ADDR SubnetMask
239 );
240
241 /**
242 Free the interface used by IpInstance. All the IP instance with
243 the same Ip/Netmask pair share the same interface. It is reference
244 counted. All the frames haven't been sent will be cancelled.
245 Because the IpInstance is optional, the caller must remove
246 IpInstance from the interface's instance list itself.
247
248 @param Interface The interface used by the IpInstance
249 @param IpInstance The Ip instance that free the interface. NULL if
250 the Ip driver is releasing the default interface.
251
252 @retval EFI_SUCCESS The interface use IpInstance is freed.
253
254 **/
255 EFI_STATUS
256 Ip4FreeInterface (
257 IN IP4_INTERFACE *Interface,
258 IN IP4_PROTOCOL *IpInstance OPTIONAL
259 );
260
261 /**
262 Send a frame from the interface. If the next hop is broadcast or
263 multicast address, it is transmitted immediately. If the next hop
264 is a unicast, it will consult ARP to resolve the NextHop's MAC.
265 If some error happened, the CallBack won't be called. So, the caller
266 must test the return value, and take action when there is an error.
267
268 @param Interface The interface to send the frame from
269 @param IpInstance The IP child that request the transmission. NULL
270 if it is the IP4 driver itself.
271 @param Packet The packet to transmit.
272 @param NextHop The immediate destination to transmit the packet
273 to.
274 @param CallBack Function to call back when transmit finished.
275 @param Context Opaque parameter to the call back.
276
277 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to send the frame
278 @retval EFI_NO_MAPPING Can't resolve the MAC for the nexthop
279 @retval EFI_SUCCESS The packet is successfully transmitted.
280 @retval other Other error occurs.
281
282 **/
283 EFI_STATUS
284 Ip4SendFrame (
285 IN IP4_INTERFACE *Interface,
286 IN IP4_PROTOCOL *IpInstance, OPTIONAL
287 IN NET_BUF *Packet,
288 IN IP4_ADDR NextHop,
289 IN IP4_FRAME_CALLBACK CallBack,
290 IN VOID *Context
291 );
292
293 /**
294 Remove all the frames on the interface that pass the FrameToCancel,
295 either queued on ARP queues or that have already been delivered to
296 MNP and not yet recycled.
297
298 @param Interface Interface to remove the frames from
299 @param IoStatus The transmit status returned to the frames'
300 callback
301 @param FrameToCancel Function to select the frame to cancel, NULL to
302 select all
303 @param Context Opaque parameters passed to FrameToCancel
304
305 @return NONE
306
307 **/
308 VOID
309 Ip4CancelFrames (
310 IN IP4_INTERFACE *Interface,
311 IN EFI_STATUS IoStatus,
312 IN IP4_FRAME_TO_CANCEL FrameToCancel, OPTIONAL
313 IN VOID *Context
314 );
315
316 /**
317 If there is a pending receive request, cancel it. Don't call
318 the receive request's callback because this function can be only
319 called if the instance or driver is tearing itself down. It
320 doesn't make sense to call it back. But it is necessary to call
321 the transmit token's callback to give it a chance to free the
322 packet and update the upper layer's transmit request status, say
323 that from the UDP.
324
325 @param Interface The interface used by the IpInstance
326
327 @return None
328
329 **/
330 VOID
331 Ip4CancelReceive (
332 IN IP4_INTERFACE *Interface
333 );
334
335 /**
336 Request to receive the packet from the interface.
337
338 @param Interface The interface to receive the frames from
339 @param IpInstance The instance that requests the receive. NULL for
340 the driver itself.
341 @param CallBack Function to call when receive finished.
342 @param Context Opaque parameter to the callback
343
344 @retval EFI_ALREADY_STARTED There is already a pending receive request.
345 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive
346 @retval EFI_SUCCESS The recieve request has been started.
347 @retval other Other error occurs.
348
349 **/
350 EFI_STATUS
351 Ip4ReceiveFrame (
352 IN IP4_INTERFACE *Interface,
353 IN IP4_PROTOCOL *IpInstance, OPTIONAL
354 IN IP4_FRAME_CALLBACK CallBack,
355 IN VOID *Context
356 );
357
358 #endif