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