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