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