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