]> git.proxmox.com Git - mirror_edk2.git/blame - 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
83cbd279 1/** @file\r
3e8c18da 2 Definition for IP4 pesudo interface structure.\r
d1102dba
LG
3\r
4Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
83cbd279 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
83cbd279 13**/\r
14\r
15#ifndef __EFI_IP4_IF_H__\r
16#define __EFI_IP4_IF_H__\r
17\r
f6b7393c 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
5405e9a6 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
3e8c18da 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
5405e9a6 45**/\r
83cbd279 46typedef\r
47VOID\r
5405e9a6 48(*IP4_FRAME_CALLBACK)(\r
3e8c18da 49 IN IP4_PROTOCOL *IpInstance OPTIONAL,\r
5405e9a6 50 IN NET_BUF *Packet,\r
51 IN EFI_STATUS IoStatus,\r
52 IN UINT32 LinkFlag,\r
53 IN VOID *Context\r
83cbd279 54 );\r
55\r
96e1079f 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
83cbd279 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
96e1079f 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
83cbd279 77typedef struct {\r
78 UINT32 Signature;\r
e48e37fc 79 LIST_ENTRY Link;\r
83cbd279 80\r
81 IP4_INTERFACE *Interface;\r
12ae56cf 82 IP4_SERVICE *IpSb;\r
83cbd279 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
96e1079f 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
83cbd279 102typedef struct {\r
103 UINT32 Signature;\r
e48e37fc 104 LIST_ENTRY Link;\r
83cbd279 105\r
e48e37fc 106 LIST_ENTRY Frames;\r
83cbd279 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
5405e9a6 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
83cbd279 127typedef\r
128BOOLEAN\r
5405e9a6 129(*IP4_FRAME_TO_CANCEL)(\r
83cbd279 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
c6bc765f 141struct _IP4_INTERFACE {\r
83cbd279 142 UINT32 Signature;\r
e48e37fc 143 LIST_ENTRY Link;\r
83cbd279 144 INTN RefCnt;\r
145\r
146 //\r
147 // IP address and subnet mask of the interface. It also contains\r
2048c585 148 // the subnet/net broadcast address for quick access. The fields\r
83cbd279 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
75dce340 158 // Handle used to create/destroy ARP child. All the IP children\r
83cbd279 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
e48e37fc 171 LIST_ENTRY ArpQues;\r
172 LIST_ENTRY SentFrames;\r
83cbd279 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
e48e37fc 187 LIST_ENTRY IpInstances;\r
83cbd279 188 BOOLEAN PromiscRecv;\r
c6bc765f 189};\r
83cbd279 190\r
2ff29212 191/**\r
192 Create an IP4_INTERFACE. Delay the creation of ARP instance until\r
193 the interface is configured.\r
194\r
3e8c18da 195 @param[in] Mnp The shared MNP child of this IP4 service binding\r
1f6729ff 196 instance.\r
3e8c18da 197 @param[in] Controller The controller this IP4 service binding instance\r
2ff29212 198 is installed. Most like the UNDI handle.\r
1f6729ff 199 @param[in] ImageHandle This driver's image handle.\r
2ff29212 200\r
201 @return Point to the created IP4_INTERFACE, otherwise NULL.\r
202\r
203**/\r
83cbd279 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
2ff29212 211/**\r
212 Set the interface's address, create and configure\r
213 the ARP child if necessary.\r
214\r
1f6729ff 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
2ff29212 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
83cbd279 224EFI_STATUS\r
225Ip4SetAddress (\r
2ff29212 226 IN OUT IP4_INTERFACE *Interface,\r
227 IN IP4_ADDR IpAddr,\r
228 IN IP4_ADDR SubnetMask\r
83cbd279 229 );\r
230\r
2ff29212 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
1f6729ff 238 @param[in] Interface The interface used by the IpInstance.\r
3e8c18da 239 @param[in] IpInstance The Ip instance that free the interface. NULL if\r
2ff29212 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
83cbd279 245EFI_STATUS\r
246Ip4FreeInterface (\r
247 IN IP4_INTERFACE *Interface,\r
2ff29212 248 IN IP4_PROTOCOL *IpInstance OPTIONAL\r
83cbd279 249 );\r
250\r
2ff29212 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
3e8c18da 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
2ff29212 260 if it is the IP4 driver itself.\r
3e8c18da 261 @param[in] Packet The packet to transmit.\r
262 @param[in] NextHop The immediate destination to transmit the packet\r
2ff29212 263 to.\r
3e8c18da 264 @param[in] CallBack Function to call back when transmit finished.\r
265 @param[in] Context Opaque parameter to the call back.\r
12ae56cf 266 @param[in] IpSb The pointer to the IP4 service binding instance.\r
2ff29212 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
83cbd279 274EFI_STATUS\r
275Ip4SendFrame (\r
276 IN IP4_INTERFACE *Interface,\r
24af132f 277 IN IP4_PROTOCOL *IpInstance OPTIONAL,\r
83cbd279 278 IN NET_BUF *Packet,\r
279 IN IP4_ADDR NextHop,\r
280 IN IP4_FRAME_CALLBACK CallBack,\r
12ae56cf
FS
281 IN VOID *Context,\r
282 IN IP4_SERVICE *IpSb\r
83cbd279 283 );\r
284\r
2ff29212 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
1f6729ff 290 @param[in] Interface Interface to remove the frames from.\r
3e8c18da 291 @param[in] IoStatus The transmit status returned to the frames'\r
1f6729ff 292 callback.\r
3e8c18da 293 @param[in] FrameToCancel Function to select the frame to cancel, NULL to\r
1f6729ff 294 select all.\r
295 @param[in] Context Opaque parameters passed to FrameToCancel.\r
2ff29212 296\r
297**/\r
83cbd279 298VOID\r
299Ip4CancelFrames (\r
300 IN IP4_INTERFACE *Interface,\r
301 IN EFI_STATUS IoStatus,\r
24af132f 302 IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL,\r
83cbd279 303 IN VOID *Context\r
304 );\r
305\r
2ff29212 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
3e8c18da 315 @param[in] Interface The interface used by the IpInstance\r
2ff29212 316\r
317**/\r
83cbd279 318VOID\r
319Ip4CancelReceive (\r
320 IN IP4_INTERFACE *Interface\r
321 );\r
322\r
2ff29212 323/**\r
324 Request to receive the packet from the interface.\r
325\r
1f6729ff 326 @param[in] Interface The interface to receive the frames from.\r
3e8c18da 327 @param[in] IpInstance The instance that requests the receive. NULL for\r
2ff29212 328 the driver itself.\r
3e8c18da 329 @param[in] CallBack Function to call when receive finished.\r
1f6729ff 330 @param[in] Context Opaque parameter to the callback.\r
2ff29212 331\r
332 @retval EFI_ALREADY_STARTED There is already a pending receive request.\r
1f6729ff 333 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive.\r
2ff29212 334 @retval EFI_SUCCESS The recieve request has been started.\r
335 @retval other Other error occurs.\r
336\r
337**/\r
83cbd279 338EFI_STATUS\r
339Ip4ReceiveFrame (\r
340 IN IP4_INTERFACE *Interface,\r
24af132f 341 IN IP4_PROTOCOL *IpInstance OPTIONAL,\r
83cbd279 342 IN IP4_FRAME_CALLBACK CallBack,\r
343 IN VOID *Context\r
344 );\r
345\r
346#endif\r