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