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