]>
Commit | Line | Data |
---|---|---|
772db4bb | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2005 - 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | Ip4Impl.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \r | |
19 | \r | |
20 | **/\r | |
21 | \r | |
22 | #include "Ip4Impl.h"\r | |
23 | \r | |
5405e9a6 | 24 | /**\r |
25 | Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.\r | |
26 | \r | |
27 | The GetModeData() function returns the current operational mode data for this\r | |
28 | driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This\r | |
29 | function is used optionally to retrieve the operational mode data of underlying\r | |
30 | networks or drivers.\r | |
31 | \r | |
32 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
33 | @param Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.\r | |
34 | @param MnpConfigData Pointer to the managed network configuration data structure.\r | |
35 | @param SnpModeData Pointer to the simple network mode data structure.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS The operation completed successfully.\r | |
38 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
39 | @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.\r | |
772db4bb | 40 | \r |
5405e9a6 | 41 | **/\r |
42 | EFI_STATUS\r | |
43 | EFIAPI\r | |
44 | EfiIp4GetModeData (\r | |
45 | IN CONST EFI_IP4_PROTOCOL *This,\r | |
46 | OUT EFI_IP4_MODE_DATA *Ip4ModeData, OPTIONAL\r | |
47 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL\r | |
48 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r | |
49 | );\r | |
50 | \r | |
772db4bb | 51 | /**\r |
5405e9a6 | 52 | Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.\r |
53 | \r | |
54 | The Configure() function is used to set, change, or reset the operational\r | |
55 | parameters and filter settings for this EFI IPv4 Protocol instance. Until these\r | |
56 | parameters have been set, no network traffic can be sent or received by this\r | |
57 | instance. Once the parameters have been reset (by calling this function with\r | |
58 | IpConfigData set to NULL), no more traffic can be sent or received until these\r | |
59 | parameters have been set again. Each EFI IPv4 Protocol instance can be started\r | |
60 | and stopped independently of each other by enabling or disabling their receive\r | |
61 | filter settings with the Configure() function.\r | |
62 | \r | |
63 | When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will\r | |
64 | be appended as an alias address into the addresses list in the EFI IPv4 Protocol\r | |
65 | driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL\r | |
66 | to retrieve the default IPv4 address if it is not available yet. Clients could\r | |
67 | frequently call GetModeData() to check the status to ensure that the default IPv4\r | |
68 | address is ready.\r | |
69 | \r | |
70 | If operational parameters are reset or changed, any pending transmit and receive\r | |
71 | requests will be cancelled. Their completion token status will be set to EFI_ABORTED\r | |
72 | and their events will be signaled.\r | |
73 | \r | |
74 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
75 | @param IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.\r | |
76 | \r | |
77 | @retval EFI_SUCCESS The driver instance was successfully opened.\r | |
78 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
79 | RARP, etc.) is not finished yet.\r | |
80 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
81 | @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:\r | |
82 | A configuration protocol (DHCP, BOOTP, RARP, etc.) could\r | |
83 | not be located when clients choose to use the default IPv4\r | |
84 | address. This EFI IPv4 Protocol implementation does not\r | |
85 | support this requested filter or timeout setting.\r | |
86 | @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.\r | |
87 | @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the\r | |
88 | IPv4 address or subnet mask can be changed. The interface must\r | |
89 | also be stopped when switching to/from raw packet mode.\r | |
90 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4\r | |
91 | Protocol driver instance is not opened.\r | |
772db4bb | 92 | \r |
5405e9a6 | 93 | **/\r |
94 | EFI_STATUS\r | |
95 | EFIAPI\r | |
96 | EfiIp4Configure (\r | |
97 | IN EFI_IP4_PROTOCOL *This,\r | |
98 | IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL\r | |
99 | );\r | |
100 | \r | |
101 | /**\r | |
102 | Joins and leaves multicast groups.\r | |
103 | \r | |
104 | The Groups() function is used to join and leave multicast group sessions. Joining\r | |
105 | a group will enable reception of matching multicast packets. Leaving a group will\r | |
106 | disable the multicast packet reception.\r | |
107 | \r | |
108 | If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.\r | |
109 | \r | |
110 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
111 | @param JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.\r | |
112 | @param GroupAddress Pointer to the IPv4 multicast address.\r | |
113 | \r | |
114 | @retval EFI_SUCCESS The operation completed successfully.\r | |
115 | @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:\r | |
116 | - This is NULL.\r | |
117 | - JoinFlag is TRUE and GroupAddress is NULL.\r | |
118 | - GroupAddress is not NULL and *GroupAddress is\r | |
119 | not a multicast IPv4 address.\r | |
120 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
121 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
122 | RARP, etc.) is not finished yet.\r | |
123 | @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.\r | |
124 | @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.\r | |
125 | @retval EFI_ALREADY_STARTED The group address is already in the group table (when\r | |
126 | JoinFlag is TRUE).\r | |
127 | @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).\r | |
128 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
772db4bb | 129 | \r |
5405e9a6 | 130 | **/\r |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | EfiIp4Groups (\r | |
134 | IN EFI_IP4_PROTOCOL *This,\r | |
135 | IN BOOLEAN JoinFlag,\r | |
136 | IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r | |
137 | );\r | |
138 | \r | |
139 | /**\r | |
140 | Adds and deletes routing table entries.\r | |
141 | \r | |
142 | The Routes() function adds a route to or deletes a route from the routing table.\r | |
143 | \r | |
144 | Routes are determined by comparing the SubnetAddress with the destination IPv4\r | |
145 | address arithmetically AND-ed with the SubnetMask. The gateway address must be\r | |
146 | on the same subnet as the configured station address.\r | |
147 | \r | |
148 | The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.\r | |
149 | The default route matches all destination IPv4 addresses that do not match any\r | |
150 | other routes.\r | |
151 | \r | |
152 | A GatewayAddress that is zero is a nonroute. Packets are sent to the destination\r | |
153 | IP address if it can be found in the ARP cache or on the local subnet. One automatic\r | |
154 | nonroute entry will be inserted into the routing table for outgoing packets that\r | |
155 | are addressed to a local subnet (gateway address of 0.0.0.0).\r | |
156 | \r | |
157 | Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI\r | |
158 | IPv4 Protocol instances that use the default IPv4 address will also have copies\r | |
159 | of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these\r | |
160 | copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its\r | |
161 | instances. As a result, client modification to the routing table will be lost.\r | |
162 | \r | |
163 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
164 | @param DeleteRoute Set to TRUE to delete this route from the routing table. Set to\r | |
165 | FALSE to add this route to the routing table. SubnetAddress\r | |
166 | and SubnetMask are used as the key to each route entry.\r | |
167 | @param SubnetAddress The address of the subnet that needs to be routed.\r | |
168 | @param SubnetMask The subnet mask of SubnetAddress.\r | |
169 | @param GatewayAddress The unicast gateway IPv4 address for this route.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS The operation completed successfully.\r | |
172 | @retval EFI_NOT_STARTED The driver instance has not been started.\r | |
173 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
174 | RARP, etc.) is not finished yet.\r | |
175 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
176 | - This is NULL.\r | |
177 | - SubnetAddress is NULL.\r | |
178 | - SubnetMask is NULL.\r | |
179 | - GatewayAddress is NULL.\r | |
180 | - *SubnetAddress is not a valid subnet address.\r | |
181 | - *SubnetMask is not a valid subnet mask.\r | |
182 | - *GatewayAddress is not a valid unicast IPv4 address.\r | |
183 | @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.\r | |
184 | @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).\r | |
185 | @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when\r | |
186 | DeleteRoute is FALSE).\r | |
187 | \r | |
188 | **/\r | |
189 | EFI_STATUS\r | |
190 | EFIAPI\r | |
191 | EfiIp4Routes (\r | |
192 | IN EFI_IP4_PROTOCOL *This,\r | |
193 | IN BOOLEAN DeleteRoute,\r | |
194 | IN EFI_IPv4_ADDRESS *SubnetAddress,\r | |
195 | IN EFI_IPv4_ADDRESS *SubnetMask,\r | |
196 | IN EFI_IPv4_ADDRESS *GatewayAddress\r | |
197 | );\r | |
198 | \r | |
199 | /**\r | |
200 | Places outgoing data packets into the transmit queue.\r | |
201 | \r | |
202 | The Transmit() function places a sending request in the transmit queue of this\r | |
203 | EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some\r | |
204 | errors occur, the event in the token will be signaled and the status is updated.\r | |
205 | \r | |
206 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
207 | @param Token Pointer to the transmit token.\r | |
208 | \r | |
209 | @retval EFI_SUCCESS The data has been queued for transmission.\r | |
210 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
211 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
212 | RARP, etc.) is not finished yet.\r | |
213 | @retval EFI_INVALID_PARAMETER One or more pameters are invalid.\r | |
214 | @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event\r | |
215 | was already in the transmit queue.\r | |
216 | @retval EFI_NOT_READY The completion token could not be queued because the transmit\r | |
217 | queue is full. \r | |
218 | @retval EFI_NOT_FOUND Not route is found to destination address.\r | |
219 | @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.\r | |
220 | @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too\r | |
221 | short to transmit.\r | |
222 | @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is\r | |
223 | greater than MTU (or greater than the maximum packet size if\r | |
224 | Token.Packet.TxData.OverrideData.\r | |
225 | DoNotFragment is TRUE.)\r | |
226 | \r | |
227 | **/\r | |
228 | EFI_STATUS\r | |
229 | EFIAPI\r | |
230 | EfiIp4Transmit (\r | |
231 | IN EFI_IP4_PROTOCOL *This,\r | |
232 | IN EFI_IP4_COMPLETION_TOKEN *Token\r | |
233 | );\r | |
234 | \r | |
235 | /**\r | |
236 | Places a receiving request into the receiving queue.\r | |
237 | \r | |
238 | The Receive() function places a completion token into the receive packet queue.\r | |
239 | This function is always asynchronous.\r | |
240 | \r | |
241 | The Token.Event field in the completion token must be filled in by the caller\r | |
242 | and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol\r | |
243 | driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event\r | |
244 | is signaled.\r | |
245 | \r | |
246 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
247 | @param Token Pointer to a token that is associated with the receive data descriptor.\r | |
248 | \r | |
249 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
250 | @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.\r | |
251 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)\r | |
252 | is not finished yet.\r | |
253 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
254 | - This is NULL.\r | |
255 | - Token is NULL.\r | |
256 | - Token.Event is NULL.\r | |
257 | @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system\r | |
258 | resources (usually memory).\r | |
259 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
260 | The EFI IPv4 Protocol instance has been reset to startup defaults.\r | |
261 | EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already\r | |
262 | in the receive queue.\r | |
263 | @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.\r | |
264 | @retval EFI_ICMP_ERROR An ICMP error packet was received.\r | |
265 | \r | |
266 | **/\r | |
267 | EFI_STATUS\r | |
268 | EFIAPI\r | |
269 | EfiIp4Receive (\r | |
270 | IN EFI_IP4_PROTOCOL *This,\r | |
271 | IN EFI_IP4_COMPLETION_TOKEN *Token\r | |
272 | );\r | |
273 | \r | |
274 | /**\r | |
275 | Abort an asynchronous transmit or receive request.\r | |
276 | \r | |
277 | The Cancel() function is used to abort a pending transmit or receive request.\r | |
278 | If the token is in the transmit or receive request queues, after calling this\r | |
279 | function, Token->Status will be set to EFI_ABORTED and then Token->Event will\r | |
280 | be signaled. If the token is not in one of the queues, which usually means the\r | |
281 | asynchronous operation has completed, this function will not signal the token\r | |
282 | and EFI_NOT_FOUND is returned.\r | |
283 | \r | |
284 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
285 | @param Token Pointer to a token that has been issued by\r | |
286 | EFI_IP4_PROTOCOL.Transmit() or\r | |
287 | EFI_IP4_PROTOCOL.Receive(). If NULL, all pending\r | |
288 | tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is\r | |
289 | defined in EFI_IP4_PROTOCOL.Transmit().\r | |
290 | \r | |
291 | @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r | |
292 | Token.->Event was signaled. When Token is NULL, all\r | |
293 | pending requests were aborted and their events were signaled.\r | |
294 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
295 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
296 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
297 | RARP, etc.) is not finished yet.\r | |
298 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was\r | |
299 | not found in the transmit or receive queue. It has either completed\r | |
300 | or was not issued by Transmit() and Receive().\r | |
301 | \r | |
302 | **/\r | |
303 | EFI_STATUS\r | |
304 | EFIAPI\r | |
305 | EfiIp4Cancel (\r | |
306 | IN EFI_IP4_PROTOCOL *This,\r | |
307 | IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r | |
308 | );\r | |
309 | \r | |
310 | /**\r | |
311 | Polls for incoming data packets and processes outgoing data packets.\r | |
312 | \r | |
313 | The Poll() function polls for incoming data packets and processes outgoing data\r | |
314 | packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()\r | |
315 | function to increase the rate that data packets are moved between the communications\r | |
316 | device and the transmit and receive queues.\r | |
317 | \r | |
318 | In some systems the periodic timer event may not poll the underlying communications\r | |
319 | device fast enough to transmit and/or receive all data packets without missing\r | |
320 | incoming packets or dropping outgoing packets. Drivers and applications that are\r | |
321 | experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function\r | |
322 | more often.\r | |
323 | \r | |
324 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
325 | \r | |
326 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
327 | @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.\r | |
328 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
329 | RARP, etc.) is not finished yet.\r | |
330 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
331 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
332 | @retval EFI_NOT_READY No incoming or outgoing data is processed.\r | |
333 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.\r | |
334 | Consider increasing the polling rate.\r | |
335 | \r | |
336 | **/\r | |
337 | EFI_STATUS\r | |
338 | EFIAPI\r | |
339 | EfiIp4Poll (\r | |
340 | IN EFI_IP4_PROTOCOL *This\r | |
341 | );\r | |
342 | \r | |
343 | EFI_IP4_PROTOCOL\r | |
344 | mEfiIp4ProtocolTemplete = {\r | |
345 | EfiIp4GetModeData,\r | |
346 | EfiIp4Configure,\r | |
347 | EfiIp4Groups,\r | |
348 | EfiIp4Routes,\r | |
349 | EfiIp4Transmit,\r | |
350 | EfiIp4Receive,\r | |
351 | EfiIp4Cancel,\r | |
352 | EfiIp4Poll\r | |
353 | };\r | |
354 | \r | |
355 | /**\r | |
356 | Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.\r | |
357 | \r | |
358 | The GetModeData() function returns the current operational mode data for this\r | |
359 | driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This\r | |
360 | function is used optionally to retrieve the operational mode data of underlying\r | |
361 | networks or drivers.\r | |
362 | \r | |
363 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
364 | @param Ip4ModeData Pointer to the EFI IPv4 Protocol mode data structure.\r | |
365 | @param MnpConfigData Pointer to the managed network configuration data structure.\r | |
366 | @param SnpModeData Pointer to the simple network mode data structure.\r | |
367 | \r | |
368 | @retval EFI_SUCCESS The operation completed successfully.\r | |
369 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
370 | @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.\r | |
772db4bb | 371 | \r |
372 | **/\r | |
772db4bb | 373 | EFI_STATUS\r |
374 | EFIAPI\r | |
375 | EfiIp4GetModeData (\r | |
376 | IN CONST EFI_IP4_PROTOCOL *This,\r | |
377 | OUT EFI_IP4_MODE_DATA *Ip4ModeData, OPTIONAL\r | |
378 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL\r | |
379 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r | |
380 | )\r | |
381 | {\r | |
382 | IP4_PROTOCOL *IpInstance;\r | |
383 | IP4_SERVICE *IpSb;\r | |
384 | EFI_IP4_CONFIG_DATA *Config;\r | |
385 | EFI_STATUS Status;\r | |
386 | EFI_TPL OldTpl;\r | |
387 | IP4_ADDR Ip;\r | |
388 | \r | |
389 | if (This == NULL) {\r | |
390 | return EFI_INVALID_PARAMETER;\r | |
391 | }\r | |
392 | \r | |
e48e37fc | 393 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 394 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r |
395 | IpSb = IpInstance->Service;\r | |
396 | \r | |
397 | if (Ip4ModeData != NULL) {\r | |
398 | //\r | |
399 | // IsStarted is "whether the EfiIp4Configure has been called".\r | |
400 | // IsConfigured is "whether the station address has been configured"\r | |
401 | //\r | |
402 | Ip4ModeData->IsStarted = (BOOLEAN)(IpInstance->State == IP4_STATE_CONFIGED);\r | |
687a2e5f | 403 | CopyMem (&Ip4ModeData->ConfigData, &IpInstance->ConfigData, sizeof (Ip4ModeData->ConfigData));\r |
772db4bb | 404 | Ip4ModeData->IsConfigured = FALSE;\r |
405 | \r | |
406 | Ip4ModeData->GroupCount = IpInstance->GroupCount;\r | |
407 | Ip4ModeData->GroupTable = (EFI_IPv4_ADDRESS *) IpInstance->Groups;\r | |
408 | \r | |
409 | Ip4ModeData->IcmpTypeCount = 23;\r | |
410 | Ip4ModeData->IcmpTypeList = mIp4SupportedIcmp;\r | |
411 | \r | |
412 | Ip4ModeData->RouteTable = NULL;\r | |
413 | Ip4ModeData->RouteCount = 0;\r | |
414 | \r | |
415 | //\r | |
416 | // return the current station address for this IP child. So,\r | |
417 | // the user can get the default address through this. Some\r | |
418 | // application wants to know it station address even it is\r | |
419 | // using the default one, such as a ftp server.\r | |
420 | //\r | |
421 | if (Ip4ModeData->IsStarted) {\r | |
422 | Config = &Ip4ModeData->ConfigData;\r | |
423 | \r | |
424 | Ip = HTONL (IpInstance->Interface->Ip);\r | |
e48e37fc | 425 | CopyMem (&Config->StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
772db4bb | 426 | \r |
427 | Ip = HTONL (IpInstance->Interface->SubnetMask);\r | |
e48e37fc | 428 | CopyMem (&Config->SubnetMask, &Ip, sizeof (EFI_IPv4_ADDRESS));\r |
772db4bb | 429 | \r |
430 | Ip4ModeData->IsConfigured = IpInstance->Interface->Configured;\r | |
431 | \r | |
432 | //\r | |
433 | // Build a EFI route table for user from the internal route table.\r | |
434 | //\r | |
435 | Status = Ip4BuildEfiRouteTable (IpInstance);\r | |
436 | \r | |
437 | if (EFI_ERROR (Status)) {\r | |
e48e37fc | 438 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 439 | return Status;\r |
440 | }\r | |
441 | \r | |
442 | Ip4ModeData->RouteTable = IpInstance->EfiRouteTable;\r | |
443 | Ip4ModeData->RouteCount = IpInstance->EfiRouteCount;\r | |
444 | }\r | |
445 | }\r | |
446 | \r | |
447 | if (MnpConfigData != NULL) {\r | |
687a2e5f | 448 | CopyMem (MnpConfigData, &IpSb->MnpConfigData, sizeof (*MnpConfigData));\r |
772db4bb | 449 | }\r |
450 | \r | |
451 | if (SnpModeData != NULL) {\r | |
687a2e5f | 452 | CopyMem (SnpModeData, &IpSb->SnpMode, sizeof (*SnpModeData));\r |
772db4bb | 453 | }\r |
454 | \r | |
e48e37fc | 455 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 456 | return EFI_SUCCESS;\r |
457 | }\r | |
458 | \r | |
459 | \r | |
460 | /**\r | |
461 | Config the MNP parameter used by IP. The IP driver use one MNP\r | |
462 | child to transmit/receive frames. By default, it configures MNP\r | |
463 | to receive unicast/multicast/broadcast. And it will enable/disable\r | |
464 | the promiscous receive according to whether there is IP child\r | |
5405e9a6 | 465 | enable that or not. If Force is FALSE, it will iterate through\r |
772db4bb | 466 | all the IP children to check whether the promiscuous receive\r |
467 | setting has been changed. If it hasn't been changed, it won't\r | |
5405e9a6 | 468 | reconfigure the MNP. If Force is TRUE, the MNP is configured no\r |
772db4bb | 469 | matter whether that is changed or not.\r |
470 | \r | |
471 | @param IpSb The IP4 service instance that is to be changed.\r | |
472 | @param Force Force the configuration or not.\r | |
473 | \r | |
474 | @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r | |
475 | @retval Others Configuration failed.\r | |
476 | \r | |
477 | **/\r | |
478 | EFI_STATUS\r | |
479 | Ip4ServiceConfigMnp (\r | |
480 | IN IP4_SERVICE *IpSb,\r | |
481 | IN BOOLEAN Force\r | |
482 | )\r | |
483 | {\r | |
e48e37fc | 484 | LIST_ENTRY *Entry;\r |
485 | LIST_ENTRY *ProtoEntry;\r | |
772db4bb | 486 | IP4_INTERFACE *IpIf;\r |
487 | IP4_PROTOCOL *IpInstance;\r | |
488 | BOOLEAN Reconfig;\r | |
489 | BOOLEAN PromiscReceive;\r | |
490 | EFI_STATUS Status;\r | |
491 | \r | |
492 | Reconfig = FALSE;\r | |
493 | PromiscReceive = FALSE;\r | |
494 | \r | |
495 | if (!Force) {\r | |
496 | //\r | |
497 | // Iterate through the IP children to check whether promiscuous\r | |
498 | // receive setting has been changed. Update the interface's receive\r | |
499 | // filter also.\r | |
500 | //\r | |
501 | NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {\r | |
502 | \r | |
503 | IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);\r | |
504 | IpIf->PromiscRecv = FALSE;\r | |
505 | \r | |
506 | NET_LIST_FOR_EACH (ProtoEntry, &IpIf->IpInstances) {\r | |
507 | IpInstance = NET_LIST_USER_STRUCT (ProtoEntry, IP4_PROTOCOL, AddrLink);\r | |
508 | \r | |
509 | if (IpInstance->ConfigData.AcceptPromiscuous) {\r | |
510 | IpIf->PromiscRecv = TRUE;\r | |
511 | PromiscReceive = TRUE;\r | |
512 | }\r | |
513 | }\r | |
514 | }\r | |
515 | \r | |
516 | //\r | |
517 | // If promiscuous receive isn't changed, it isn't necessary to reconfigure.\r | |
518 | //\r | |
519 | if (PromiscReceive == IpSb->MnpConfigData.EnablePromiscuousReceive) {\r | |
520 | return EFI_SUCCESS;\r | |
521 | }\r | |
522 | \r | |
523 | Reconfig = TRUE;\r | |
524 | IpSb->MnpConfigData.EnablePromiscuousReceive = PromiscReceive;\r | |
525 | }\r | |
526 | \r | |
527 | Status = IpSb->Mnp->Configure (IpSb->Mnp, &IpSb->MnpConfigData);\r | |
528 | \r | |
529 | //\r | |
530 | // recover the original configuration if failed to set the configure.\r | |
531 | //\r | |
532 | if (EFI_ERROR (Status) && Reconfig) {\r | |
687a2e5f | 533 | IpSb->MnpConfigData.EnablePromiscuousReceive = (BOOLEAN) !PromiscReceive;\r |
772db4bb | 534 | }\r |
535 | \r | |
536 | return Status;\r | |
537 | }\r | |
538 | \r | |
539 | \r | |
540 | /**\r | |
541 | The event handle for IP4 auto configuration. If IP is asked\r | |
542 | to reconfigure the default address. The original default\r | |
543 | interface and route table are removed as the default. If there\r | |
544 | is active IP children using the default address, the interface\r | |
545 | will remain valid until all the children have freed their\r | |
546 | references. If IP is signalled when auto configuration is done,\r | |
547 | it will configure the default interface and default route table\r | |
548 | with the configuration information retrieved by IP4_CONFIGURE.\r | |
549 | \r | |
772db4bb | 550 | @param Context The IP4 service binding instance.\r |
551 | \r | |
552 | @return None\r | |
553 | \r | |
554 | **/\r | |
555 | VOID\r | |
556 | EFIAPI\r | |
36ee91ca | 557 | Ip4AutoConfigCallBackDpc (\r |
772db4bb | 558 | IN VOID *Context\r |
559 | )\r | |
560 | {\r | |
561 | EFI_IP4_CONFIG_PROTOCOL *Ip4Config;\r | |
562 | EFI_IP4_IPCONFIG_DATA *Data;\r | |
563 | EFI_IP4_ROUTE_TABLE *RouteEntry;\r | |
564 | IP4_SERVICE *IpSb;\r | |
565 | IP4_ROUTE_TABLE *RouteTable;\r | |
566 | IP4_INTERFACE *IpIf;\r | |
567 | EFI_STATUS Status;\r | |
568 | UINTN Len;\r | |
569 | UINT32 Index;\r | |
570 | \r | |
571 | IpSb = (IP4_SERVICE *) Context;\r | |
572 | NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r | |
573 | \r | |
574 | Ip4Config = IpSb->Ip4Config;\r | |
575 | \r | |
576 | //\r | |
577 | // IP is asked to do the reconfiguration. If the default interface\r | |
578 | // has been configured, release the default interface and route\r | |
579 | // table, then create a new one. If there are some IP children\r | |
580 | // using it, the interface won't be physically freed until all the\r | |
581 | // children have released their reference to it. Also remember to\r | |
582 | // restart the receive on the default address. IP4 driver only receive\r | |
583 | // frames on the default address, and when the default interface is\r | |
584 | // freed, Ip4AcceptFrame won't be informed.\r | |
585 | //\r | |
36ee91ca | 586 | if (IpSb->ActiveEvent == IpSb->ReconfigEvent) {\r |
772db4bb | 587 | \r |
588 | if (IpSb->DefaultInterface->Configured) {\r | |
589 | IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);\r | |
590 | \r | |
591 | if (IpIf == NULL) {\r | |
592 | return;\r | |
593 | }\r | |
594 | \r | |
595 | RouteTable = Ip4CreateRouteTable ();\r | |
596 | \r | |
597 | if (RouteTable == NULL) {\r | |
598 | Ip4FreeInterface (IpIf, NULL);\r | |
599 | return;\r | |
600 | }\r | |
601 | \r | |
602 | Ip4CancelReceive (IpSb->DefaultInterface);\r | |
603 | Ip4FreeInterface (IpSb->DefaultInterface, NULL);\r | |
604 | Ip4FreeRouteTable (IpSb->DefaultRouteTable);\r | |
605 | \r | |
606 | IpSb->DefaultInterface = IpIf;\r | |
e48e37fc | 607 | InsertHeadList (&IpSb->Interfaces, &IpIf->Link);\r |
772db4bb | 608 | \r |
609 | IpSb->DefaultRouteTable = RouteTable;\r | |
610 | Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);\r | |
611 | }\r | |
612 | \r | |
613 | Ip4Config->Stop (Ip4Config);\r | |
614 | Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent);\r | |
615 | return ;\r | |
616 | }\r | |
617 | \r | |
618 | //\r | |
619 | // Get the configure data in two steps: get the length then the data.\r | |
620 | //\r | |
621 | Len = 0;\r | |
622 | \r | |
623 | if (Ip4Config->GetData (Ip4Config, &Len, NULL) != EFI_BUFFER_TOO_SMALL) {\r | |
624 | return ;\r | |
625 | }\r | |
626 | \r | |
e48e37fc | 627 | Data = AllocatePool (Len);\r |
772db4bb | 628 | \r |
629 | if (Data == NULL) {\r | |
630 | return ;\r | |
631 | }\r | |
632 | \r | |
633 | Status = Ip4Config->GetData (Ip4Config, &Len, Data);\r | |
634 | \r | |
635 | if (EFI_ERROR (Status)) {\r | |
636 | goto ON_EXIT;\r | |
637 | }\r | |
638 | \r | |
639 | IpIf = IpSb->DefaultInterface;\r | |
640 | \r | |
641 | //\r | |
642 | // If the default address has been configured don't change it.\r | |
643 | // This is unlikely to happen if EFI_IP4_CONFIG protocol has\r | |
644 | // informed us to reconfigure each time it wants to change the\r | |
645 | // configuration parameters.\r | |
646 | //\r | |
647 | if (IpIf->Configured) {\r | |
648 | goto ON_EXIT;\r | |
649 | }\r | |
650 | \r | |
651 | //\r | |
652 | // Set the default interface's address, then add a directed\r | |
653 | // route for it, that is, the route whose nexthop is zero.\r | |
654 | //\r | |
655 | Status = Ip4SetAddress (\r | |
656 | IpIf,\r | |
657 | EFI_NTOHL (Data->StationAddress),\r | |
658 | EFI_NTOHL (Data->SubnetMask)\r | |
659 | );\r | |
660 | \r | |
661 | if (EFI_ERROR (Status)) {\r | |
662 | goto ON_EXIT;\r | |
663 | }\r | |
664 | \r | |
665 | Ip4AddRoute (\r | |
666 | IpSb->DefaultRouteTable,\r | |
667 | EFI_NTOHL (Data->StationAddress),\r | |
668 | EFI_NTOHL (Data->SubnetMask),\r | |
669 | IP4_ALLZERO_ADDRESS\r | |
670 | );\r | |
671 | \r | |
672 | //\r | |
673 | // Add routes returned by EFI_IP4_CONFIG protocol.\r | |
674 | //\r | |
675 | for (Index = 0; Index < Data->RouteTableSize; Index++) {\r | |
676 | RouteEntry = &Data->RouteTable[Index];\r | |
677 | \r | |
678 | Ip4AddRoute (\r | |
679 | IpSb->DefaultRouteTable,\r | |
680 | EFI_NTOHL (RouteEntry->SubnetAddress),\r | |
681 | EFI_NTOHL (RouteEntry->SubnetMask),\r | |
682 | EFI_NTOHL (RouteEntry->GatewayAddress)\r | |
683 | );\r | |
684 | }\r | |
685 | \r | |
686 | IpSb->State = IP4_SERVICE_CONFIGED;\r | |
687 | \r | |
688 | Ip4SetVariableData (IpSb);\r | |
689 | \r | |
690 | ON_EXIT:\r | |
e48e37fc | 691 | gBS->FreePool (Data);\r |
772db4bb | 692 | }\r |
693 | \r | |
2ff29212 | 694 | /**\r |
695 | \r | |
5405e9a6 | 696 | Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK.\r |
697 | \r | |
698 | @param Event The event that is signalled.\r | |
699 | @param Context The IP4 service binding instance.\r | |
700 | \r | |
701 | @return None.\r | |
702 | \r | |
2ff29212 | 703 | **/\r |
36ee91ca | 704 | VOID\r |
705 | EFIAPI\r | |
706 | Ip4AutoConfigCallBack (\r | |
707 | IN EFI_EVENT Event,\r | |
708 | IN VOID *Context\r | |
709 | )\r | |
36ee91ca | 710 | {\r |
711 | IP4_SERVICE *IpSb;\r | |
712 | \r | |
713 | IpSb = (IP4_SERVICE *) Context;\r | |
714 | IpSb->ActiveEvent = Event;\r | |
715 | \r | |
716 | //\r | |
717 | // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK\r | |
718 | //\r | |
719 | NetLibQueueDpc (TPL_CALLBACK, Ip4AutoConfigCallBackDpc, Context);\r | |
720 | }\r | |
721 | \r | |
772db4bb | 722 | \r |
723 | /**\r | |
724 | Start the auto configuration for this IP service instance.\r | |
725 | It will locates the EFI_IP4_CONFIG_PROTOCOL, then start the\r | |
726 | auto configuration.\r | |
727 | \r | |
728 | @param IpSb The IP4 service instance to configure\r | |
729 | \r | |
730 | @retval EFI_SUCCESS The auto configuration is successfull started\r | |
731 | @retval Others Failed to start auto configuration.\r | |
732 | \r | |
733 | **/\r | |
734 | EFI_STATUS\r | |
735 | Ip4StartAutoConfig (\r | |
736 | IN IP4_SERVICE *IpSb\r | |
737 | )\r | |
738 | {\r | |
739 | EFI_IP4_CONFIG_PROTOCOL *Ip4Config;\r | |
740 | EFI_STATUS Status;\r | |
741 | \r | |
742 | if (IpSb->State > IP4_SERVICE_UNSTARTED) {\r | |
743 | return EFI_SUCCESS;\r | |
744 | }\r | |
745 | \r | |
746 | //\r | |
747 | // Create the DoneEvent and ReconfigEvent to call EFI_IP4_CONFIG\r | |
748 | //\r | |
749 | Status = gBS->CreateEvent (\r | |
750 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 751 | TPL_CALLBACK,\r |
772db4bb | 752 | Ip4AutoConfigCallBack,\r |
753 | IpSb,\r | |
754 | &IpSb->DoneEvent\r | |
755 | );\r | |
756 | \r | |
757 | if (EFI_ERROR (Status)) {\r | |
758 | return Status;\r | |
759 | }\r | |
760 | \r | |
761 | Status = gBS->CreateEvent (\r | |
762 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 763 | TPL_NOTIFY,\r |
772db4bb | 764 | Ip4AutoConfigCallBack,\r |
765 | IpSb,\r | |
766 | &IpSb->ReconfigEvent\r | |
767 | );\r | |
768 | \r | |
769 | if (EFI_ERROR (Status)) {\r | |
770 | goto CLOSE_DONE_EVENT;\r | |
771 | }\r | |
772 | \r | |
773 | //\r | |
774 | // Open the EFI_IP4_CONFIG protocol then start auto configure\r | |
775 | //\r | |
776 | Status = gBS->OpenProtocol (\r | |
777 | IpSb->Controller,\r | |
778 | &gEfiIp4ConfigProtocolGuid,\r | |
779 | (VOID **) &Ip4Config,\r | |
780 | IpSb->Image,\r | |
781 | IpSb->Controller,\r | |
782 | EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE\r | |
783 | );\r | |
784 | \r | |
785 | if (EFI_ERROR (Status)) {\r | |
786 | Status = EFI_UNSUPPORTED;\r | |
787 | goto CLOSE_RECONFIG_EVENT;\r | |
788 | }\r | |
789 | \r | |
790 | Status = Ip4Config->Start (Ip4Config, IpSb->DoneEvent, IpSb->ReconfigEvent);\r | |
791 | \r | |
792 | if (EFI_ERROR (Status)) {\r | |
793 | gBS->CloseProtocol (\r | |
794 | IpSb->Controller,\r | |
795 | &gEfiIp4ConfigProtocolGuid,\r | |
796 | IpSb->Image,\r | |
797 | IpSb->Controller\r | |
798 | );\r | |
799 | \r | |
800 | goto CLOSE_RECONFIG_EVENT;\r | |
801 | }\r | |
802 | \r | |
803 | IpSb->Ip4Config = Ip4Config;\r | |
804 | IpSb->State = IP4_SERVICE_STARTED;\r | |
805 | return Status;\r | |
806 | \r | |
807 | CLOSE_RECONFIG_EVENT:\r | |
808 | gBS->CloseEvent (IpSb->ReconfigEvent);\r | |
809 | IpSb->ReconfigEvent = NULL;\r | |
810 | \r | |
811 | CLOSE_DONE_EVENT:\r | |
812 | gBS->CloseEvent (IpSb->DoneEvent);\r | |
813 | IpSb->DoneEvent = NULL;\r | |
814 | \r | |
815 | return Status;\r | |
816 | }\r | |
817 | \r | |
818 | \r | |
819 | /**\r | |
820 | Intiialize the IP4_PROTOCOL structure to the unconfigured states.\r | |
821 | \r | |
822 | @param IpSb The IP4 service instance.\r | |
823 | @param IpInstance The IP4 child instance.\r | |
824 | \r | |
825 | @return None\r | |
826 | \r | |
827 | **/\r | |
828 | VOID\r | |
829 | Ip4InitProtocol (\r | |
5405e9a6 | 830 | IN IP4_SERVICE *IpSb,\r |
831 | IN OUT IP4_PROTOCOL *IpInstance\r | |
772db4bb | 832 | )\r |
833 | {\r | |
834 | ASSERT ((IpSb != NULL) && (IpInstance != NULL));\r | |
835 | \r | |
e48e37fc | 836 | ZeroMem (IpInstance, sizeof (IP4_PROTOCOL));\r |
772db4bb | 837 | \r |
838 | IpInstance->Signature = IP4_PROTOCOL_SIGNATURE;\r | |
687a2e5f | 839 | CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto));\r |
772db4bb | 840 | IpInstance->State = IP4_STATE_UNCONFIGED;\r |
841 | IpInstance->Service = IpSb;\r | |
842 | \r | |
e48e37fc | 843 | InitializeListHead (&IpInstance->Link);\r |
772db4bb | 844 | NetMapInit (&IpInstance->RxTokens);\r |
845 | NetMapInit (&IpInstance->TxTokens);\r | |
e48e37fc | 846 | InitializeListHead (&IpInstance->Received);\r |
847 | InitializeListHead (&IpInstance->Delivered);\r | |
848 | InitializeListHead (&IpInstance->AddrLink);\r | |
772db4bb | 849 | \r |
e48e37fc | 850 | EfiInitializeLock (&IpInstance->RecycleLock, TPL_NOTIFY);\r |
772db4bb | 851 | }\r |
852 | \r | |
853 | \r | |
854 | /**\r | |
855 | Configure the IP4 child. If the child is already configured,\r | |
856 | change the configuration parameter. Otherwise configure it\r | |
857 | for the first time. The caller should validate the configuration\r | |
858 | before deliver them to it. It also don't do configure NULL.\r | |
859 | \r | |
860 | @param IpInstance The IP4 child to configure.\r | |
861 | @param Config The configure data.\r | |
862 | \r | |
863 | @retval EFI_SUCCESS The IP4 child is successfully configured.\r | |
864 | @retval EFI_DEVICE_ERROR Failed to free the pending transive or to\r | |
865 | configure underlying MNP or other errors.\r | |
866 | @retval EFI_NO_MAPPING The IP4 child is configured to use default\r | |
867 | address, but the default address hasn't been\r | |
868 | configured. The IP4 child doesn't need to be\r | |
869 | reconfigured when default address is configured.\r | |
5405e9a6 | 870 | @retval EFI_OUT_OF_RESOURCES No more memory space is available.\r |
871 | @retval other Other error occurs.\r | |
772db4bb | 872 | \r |
873 | **/\r | |
874 | EFI_STATUS\r | |
875 | Ip4ConfigProtocol (\r | |
5405e9a6 | 876 | IN OUT IP4_PROTOCOL *IpInstance,\r |
877 | IN EFI_IP4_CONFIG_DATA *Config\r | |
772db4bb | 878 | )\r |
879 | {\r | |
880 | IP4_SERVICE *IpSb;\r | |
881 | IP4_INTERFACE *IpIf;\r | |
882 | EFI_STATUS Status;\r | |
883 | IP4_ADDR Ip;\r | |
884 | IP4_ADDR Netmask;\r | |
885 | \r | |
886 | IpSb = IpInstance->Service;\r | |
887 | \r | |
888 | //\r | |
889 | // User is changing packet filters. It must be stopped\r | |
890 | // before the station address can be changed.\r | |
891 | //\r | |
892 | if (IpInstance->State == IP4_STATE_CONFIGED) {\r | |
893 | //\r | |
894 | // Cancel all the pending transmit/receive from upper layer\r | |
895 | //\r | |
896 | Status = Ip4Cancel (IpInstance, NULL);\r | |
897 | \r | |
898 | if (EFI_ERROR (Status)) {\r | |
899 | return EFI_DEVICE_ERROR;\r | |
900 | }\r | |
901 | \r | |
687a2e5f | 902 | CopyMem (&IpInstance->ConfigData, Config, sizeof (IpInstance->ConfigData));\r |
772db4bb | 903 | return EFI_SUCCESS;\r |
904 | }\r | |
905 | \r | |
906 | //\r | |
907 | // Configure a fresh IP4 protocol instance. Create a route table.\r | |
908 | // Each IP child has its own route table, which may point to the\r | |
909 | // default table if it is using default address.\r | |
910 | //\r | |
911 | Status = EFI_OUT_OF_RESOURCES;\r | |
912 | IpInstance->RouteTable = Ip4CreateRouteTable ();\r | |
913 | \r | |
914 | if (IpInstance->RouteTable == NULL) {\r | |
915 | return Status;\r | |
916 | }\r | |
917 | \r | |
918 | //\r | |
919 | // Set up the interface.\r | |
920 | //\r | |
e48e37fc | 921 | CopyMem (&Ip, &Config->StationAddress, sizeof (IP4_ADDR));\r |
922 | CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));\r | |
772db4bb | 923 | \r |
924 | Ip = NTOHL (Ip);\r | |
925 | Netmask = NTOHL (Netmask);\r | |
926 | \r | |
927 | if (!Config->UseDefaultAddress) {\r | |
928 | //\r | |
929 | // Find whether there is already an interface with the same\r | |
930 | // station address. All the instances with the same station\r | |
931 | // address shares one interface.\r | |
932 | //\r | |
933 | IpIf = Ip4FindStationAddress (IpSb, Ip, Netmask);\r | |
934 | \r | |
935 | if (IpIf != NULL) {\r | |
936 | NET_GET_REF (IpIf);\r | |
937 | \r | |
938 | } else {\r | |
939 | IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);\r | |
940 | \r | |
941 | if (IpIf == NULL) {\r | |
942 | goto ON_ERROR;\r | |
943 | }\r | |
944 | \r | |
945 | Status = Ip4SetAddress (IpIf, Ip, Netmask);\r | |
946 | \r | |
947 | if (EFI_ERROR (Status)) {\r | |
948 | Status = EFI_DEVICE_ERROR;\r | |
949 | Ip4FreeInterface (IpIf, IpInstance);\r | |
950 | goto ON_ERROR;\r | |
951 | }\r | |
952 | \r | |
e48e37fc | 953 | InsertTailList (&IpSb->Interfaces, &IpIf->Link);\r |
772db4bb | 954 | }\r |
955 | \r | |
956 | //\r | |
957 | // Add a route to this connected network in the route table\r | |
958 | //\r | |
959 | Ip4AddRoute (IpInstance->RouteTable, Ip, Netmask, IP4_ALLZERO_ADDRESS);\r | |
960 | \r | |
961 | } else {\r | |
962 | //\r | |
963 | // Use the default address. If the default configuration hasn't\r | |
964 | // been started, start it.\r | |
965 | //\r | |
966 | if (IpSb->State == IP4_SERVICE_UNSTARTED) {\r | |
967 | Status = Ip4StartAutoConfig (IpSb);\r | |
968 | \r | |
969 | if (EFI_ERROR (Status)) {\r | |
970 | goto ON_ERROR;\r | |
971 | }\r | |
972 | }\r | |
973 | \r | |
974 | IpIf = IpSb->DefaultInterface;\r | |
975 | NET_GET_REF (IpSb->DefaultInterface);\r | |
976 | \r | |
977 | //\r | |
978 | // If default address is used, so is the default route table.\r | |
979 | // Any route set by the instance has the precedence over the\r | |
980 | // routes in the default route table. Link the default table\r | |
981 | // after the instance's table. Routing will search the local\r | |
982 | // table first.\r | |
983 | //\r | |
984 | NET_GET_REF (IpSb->DefaultRouteTable);\r | |
985 | IpInstance->RouteTable->Next = IpSb->DefaultRouteTable;\r | |
986 | }\r | |
987 | \r | |
988 | IpInstance->Interface = IpIf;\r | |
e48e37fc | 989 | InsertTailList (&IpIf->IpInstances, &IpInstance->AddrLink);\r |
772db4bb | 990 | \r |
687a2e5f | 991 | CopyMem (&IpInstance->ConfigData, Config, sizeof (IpInstance->ConfigData));\r |
772db4bb | 992 | IpInstance->State = IP4_STATE_CONFIGED;\r |
993 | \r | |
994 | //\r | |
995 | // Although EFI_NO_MAPPING is an error code, the IP child has been\r | |
996 | // successfully configured and doesn't need reconfiguration when\r | |
997 | // default address is acquired.\r | |
998 | //\r | |
999 | if (Config->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
1000 | return EFI_NO_MAPPING;\r | |
1001 | }\r | |
1002 | \r | |
1003 | return EFI_SUCCESS;\r | |
1004 | \r | |
1005 | ON_ERROR:\r | |
1006 | Ip4FreeRouteTable (IpInstance->RouteTable);\r | |
1007 | IpInstance->RouteTable = NULL;\r | |
1008 | return Status;\r | |
1009 | }\r | |
1010 | \r | |
1011 | \r | |
1012 | /**\r | |
1013 | Clean up the IP4 child, release all the resources used by it.\r | |
1014 | \r | |
1015 | @param IpInstance The IP4 child to clean up.\r | |
1016 | \r | |
1017 | @retval EFI_SUCCESS The IP4 child is cleaned up\r | |
1018 | @retval EFI_DEVICE_ERROR Some resources failed to be released\r | |
1019 | \r | |
1020 | **/\r | |
1021 | EFI_STATUS\r | |
1022 | Ip4CleanProtocol (\r | |
1023 | IN IP4_PROTOCOL *IpInstance\r | |
1024 | )\r | |
1025 | {\r | |
1026 | if (EFI_ERROR (Ip4Cancel (IpInstance, NULL))) {\r | |
1027 | return EFI_DEVICE_ERROR;\r | |
1028 | }\r | |
1029 | \r | |
1030 | if (EFI_ERROR (Ip4Groups (IpInstance, FALSE, NULL))) {\r | |
1031 | return EFI_DEVICE_ERROR;\r | |
1032 | }\r | |
1033 | \r | |
1034 | //\r | |
1035 | // Some packets haven't been recycled. It is because either the\r | |
1036 | // user forgets to recycle the packets, or because the callback\r | |
1037 | // hasn't been called. Just leave it alone.\r | |
1038 | //\r | |
e48e37fc | 1039 | if (!IsListEmpty (&IpInstance->Delivered)) {\r |
772db4bb | 1040 | ;\r |
1041 | }\r | |
1042 | \r | |
1043 | if (IpInstance->Interface != NULL) {\r | |
e48e37fc | 1044 | RemoveEntryList (&IpInstance->AddrLink);\r |
772db4bb | 1045 | Ip4FreeInterface (IpInstance->Interface, IpInstance);\r |
1046 | IpInstance->Interface = NULL;\r | |
1047 | }\r | |
1048 | \r | |
1049 | if (IpInstance->RouteTable != NULL) {\r | |
1050 | if (IpInstance->RouteTable->Next != NULL) {\r | |
1051 | Ip4FreeRouteTable (IpInstance->RouteTable->Next);\r | |
1052 | }\r | |
1053 | \r | |
1054 | Ip4FreeRouteTable (IpInstance->RouteTable);\r | |
1055 | IpInstance->RouteTable = NULL;\r | |
1056 | }\r | |
1057 | \r | |
1058 | if (IpInstance->EfiRouteTable != NULL) {\r | |
e48e37fc | 1059 | gBS->FreePool (IpInstance->EfiRouteTable);\r |
772db4bb | 1060 | IpInstance->EfiRouteTable = NULL;\r |
1061 | IpInstance->EfiRouteCount = 0;\r | |
1062 | }\r | |
1063 | \r | |
1064 | if (IpInstance->Groups != NULL) {\r | |
e48e37fc | 1065 | gBS->FreePool (IpInstance->Groups);\r |
772db4bb | 1066 | IpInstance->Groups = NULL;\r |
1067 | IpInstance->GroupCount = 0;\r | |
1068 | }\r | |
1069 | \r | |
1070 | NetMapClean (&IpInstance->TxTokens);\r | |
1071 | \r | |
1072 | NetMapClean (&IpInstance->RxTokens);\r | |
1073 | \r | |
1074 | return EFI_SUCCESS;\r | |
1075 | }\r | |
1076 | \r | |
1077 | \r | |
1078 | /**\r | |
1079 | Validate that Ip/Netmask pair is OK to be used as station\r | |
1080 | address. Only continuous netmasks are supported. and check\r | |
1081 | that StationAddress is a unicast address on the newtwork.\r | |
1082 | \r | |
1083 | @param Ip The IP address to validate\r | |
1084 | @param Netmask The netmaks of the IP\r | |
1085 | \r | |
1086 | @retval TRUE The Ip/Netmask pair is valid\r | |
5405e9a6 | 1087 | @retval FALSE The Ip/Netmask pair is invalid\r |
772db4bb | 1088 | \r |
1089 | **/\r | |
1090 | BOOLEAN\r | |
1091 | Ip4StationAddressValid (\r | |
1092 | IN IP4_ADDR Ip,\r | |
1093 | IN IP4_ADDR Netmask\r | |
1094 | )\r | |
1095 | {\r | |
1096 | IP4_ADDR NetBrdcastMask;\r | |
1097 | INTN Len;\r | |
1098 | INTN Type;\r | |
1099 | \r | |
1100 | //\r | |
1101 | // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r | |
1102 | //\r | |
1103 | if (Netmask == IP4_ALLZERO_ADDRESS) {\r | |
1104 | return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);\r | |
1105 | }\r | |
1106 | \r | |
1107 | //\r | |
1108 | // Only support the continuous net masks\r | |
1109 | //\r | |
1110 | if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) {\r | |
1111 | return FALSE;\r | |
1112 | }\r | |
1113 | \r | |
1114 | //\r | |
1115 | // Station address can't be class D or class E address\r | |
1116 | //\r | |
1117 | if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {\r | |
1118 | return FALSE;\r | |
1119 | }\r | |
1120 | \r | |
1121 | //\r | |
1122 | // Station address can't be subnet broadcast/net broadcast address\r | |
1123 | //\r | |
1124 | if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {\r | |
1125 | return FALSE;\r | |
1126 | }\r | |
1127 | \r | |
2a86ff1c | 1128 | NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];\r |
772db4bb | 1129 | \r |
1130 | if (Ip == (Ip | ~NetBrdcastMask)) {\r | |
1131 | return FALSE;\r | |
1132 | }\r | |
1133 | \r | |
1134 | return TRUE;\r | |
1135 | }\r | |
1136 | \r | |
1137 | \r | |
1138 | /**\r | |
5405e9a6 | 1139 | Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance.\r |
1140 | \r | |
1141 | The Configure() function is used to set, change, or reset the operational\r | |
1142 | parameters and filter settings for this EFI IPv4 Protocol instance. Until these\r | |
1143 | parameters have been set, no network traffic can be sent or received by this\r | |
1144 | instance. Once the parameters have been reset (by calling this function with\r | |
1145 | IpConfigData set to NULL), no more traffic can be sent or received until these\r | |
1146 | parameters have been set again. Each EFI IPv4 Protocol instance can be started\r | |
1147 | and stopped independently of each other by enabling or disabling their receive\r | |
1148 | filter settings with the Configure() function.\r | |
1149 | \r | |
1150 | When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will\r | |
1151 | be appended as an alias address into the addresses list in the EFI IPv4 Protocol\r | |
1152 | driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL\r | |
1153 | to retrieve the default IPv4 address if it is not available yet. Clients could\r | |
1154 | frequently call GetModeData() to check the status to ensure that the default IPv4\r | |
1155 | address is ready.\r | |
1156 | \r | |
1157 | If operational parameters are reset or changed, any pending transmit and receive\r | |
1158 | requests will be cancelled. Their completion token status will be set to EFI_ABORTED\r | |
1159 | and their events will be signaled.\r | |
1160 | \r | |
1161 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
1162 | @param IpConfigData Pointer to the EFI IPv4 Protocol configuration data structure.\r | |
1163 | \r | |
1164 | @retval EFI_SUCCESS The driver instance was successfully opened.\r | |
1165 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
1166 | RARP, etc.) is not finished yet.\r | |
1167 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1168 | @retval EFI_UNSUPPORTED One or more of the following conditions is TRUE:\r | |
1169 | A configuration protocol (DHCP, BOOTP, RARP, etc.) could\r | |
1170 | not be located when clients choose to use the default IPv4\r | |
1171 | address. This EFI IPv4 Protocol implementation does not\r | |
1172 | support this requested filter or timeout setting.\r | |
1173 | @retval EFI_OUT_OF_RESOURCES The EFI IPv4 Protocol driver instance data could not be allocated.\r | |
1174 | @retval EFI_ALREADY_STARTED The interface is already open and must be stopped before the\r | |
1175 | IPv4 address or subnet mask can be changed. The interface must\r | |
1176 | also be stopped when switching to/from raw packet mode.\r | |
1177 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI IPv4\r | |
1178 | Protocol driver instance is not opened.\r | |
772db4bb | 1179 | \r |
1180 | **/\r | |
772db4bb | 1181 | EFI_STATUS\r |
1182 | EFIAPI\r | |
1183 | EfiIp4Configure (\r | |
1184 | IN EFI_IP4_PROTOCOL *This,\r | |
1185 | IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL\r | |
1186 | )\r | |
1187 | {\r | |
1188 | IP4_PROTOCOL *IpInstance;\r | |
1189 | EFI_IP4_CONFIG_DATA *Current;\r | |
1190 | EFI_TPL OldTpl;\r | |
1191 | EFI_STATUS Status;\r | |
1192 | BOOLEAN AddrOk;\r | |
1193 | IP4_ADDR IpAddress;\r | |
1194 | IP4_ADDR SubnetMask;\r | |
1195 | \r | |
1196 | //\r | |
1197 | // First, validate the parameters\r | |
1198 | //\r | |
1199 | if (This == NULL) {\r | |
1200 | return EFI_INVALID_PARAMETER;\r | |
1201 | }\r | |
1202 | \r | |
1203 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
e48e37fc | 1204 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1205 | \r |
1206 | //\r | |
1207 | // Validate the configuration first.\r | |
1208 | //\r | |
1209 | if (IpConfigData != NULL) {\r | |
1210 | //\r | |
1211 | // This implementation doesn't support RawData\r | |
1212 | //\r | |
1213 | if (IpConfigData->RawData) {\r | |
1214 | Status = EFI_UNSUPPORTED;\r | |
1215 | goto ON_EXIT;\r | |
1216 | }\r | |
1217 | \r | |
1218 | \r | |
e48e37fc | 1219 | CopyMem (&IpAddress, &IpConfigData->StationAddress, sizeof (IP4_ADDR));\r |
1220 | CopyMem (&SubnetMask, &IpConfigData->SubnetMask, sizeof (IP4_ADDR));\r | |
772db4bb | 1221 | \r |
1222 | IpAddress = NTOHL (IpAddress);\r | |
1223 | SubnetMask = NTOHL (SubnetMask);\r | |
1224 | \r | |
1225 | //\r | |
1226 | // Check whether the station address is a valid unicast address\r | |
1227 | //\r | |
1228 | if (!IpConfigData->UseDefaultAddress) {\r | |
1229 | AddrOk = Ip4StationAddressValid (IpAddress, SubnetMask);\r | |
1230 | \r | |
1231 | if (!AddrOk) {\r | |
1232 | Status = EFI_INVALID_PARAMETER;\r | |
1233 | goto ON_EXIT;\r | |
1234 | }\r | |
1235 | }\r | |
1236 | \r | |
1237 | //\r | |
1238 | // User can only update packet filters when already configured.\r | |
1239 | // If it wants to change the station address, it must configure(NULL)\r | |
1240 | // the instance first.\r | |
1241 | //\r | |
1242 | if (IpInstance->State == IP4_STATE_CONFIGED) {\r | |
1243 | Current = &IpInstance->ConfigData;\r | |
1244 | \r | |
1245 | if (Current->UseDefaultAddress != IpConfigData->UseDefaultAddress) {\r | |
1246 | Status = EFI_ALREADY_STARTED;\r | |
1247 | goto ON_EXIT;\r | |
1248 | }\r | |
1249 | \r | |
1250 | if (!Current->UseDefaultAddress &&\r | |
84b5c78e | 1251 | (!EFI_IP4_EQUAL (&Current->StationAddress, &IpConfigData->StationAddress) ||\r |
1252 | !EFI_IP4_EQUAL (&Current->SubnetMask, &IpConfigData->SubnetMask))) {\r | |
772db4bb | 1253 | Status = EFI_ALREADY_STARTED;\r |
1254 | goto ON_EXIT;\r | |
1255 | }\r | |
1256 | \r | |
1257 | if (Current->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
1258 | return EFI_NO_MAPPING;\r | |
1259 | }\r | |
1260 | }\r | |
1261 | }\r | |
1262 | \r | |
1263 | //\r | |
1264 | // Configure the instance or clean it up.\r | |
1265 | //\r | |
1266 | if (IpConfigData != NULL) {\r | |
1267 | Status = Ip4ConfigProtocol (IpInstance, IpConfigData);\r | |
1268 | } else {\r | |
1269 | Status = Ip4CleanProtocol (IpInstance);\r | |
1270 | \r | |
1271 | //\r | |
1272 | // Don't change the state if it is DESTORY, consider the following\r | |
1273 | // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped,\r | |
1274 | // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED,\r | |
1275 | // the unload fails miserably.\r | |
1276 | //\r | |
1277 | if (IpInstance->State == IP4_STATE_CONFIGED) {\r | |
1278 | IpInstance->State = IP4_STATE_UNCONFIGED;\r | |
1279 | }\r | |
1280 | }\r | |
1281 | \r | |
1282 | //\r | |
1283 | // Update the MNP's configure data. Ip4ServiceConfigMnp will check\r | |
1284 | // whether it is necessary to reconfigure the MNP.\r | |
1285 | //\r | |
1286 | Ip4ServiceConfigMnp (IpInstance->Service, FALSE);\r | |
1287 | \r | |
1288 | //\r | |
1289 | // Update the variable data.\r | |
1290 | //\r | |
1291 | Ip4SetVariableData (IpInstance->Service);\r | |
1292 | \r | |
1293 | ON_EXIT:\r | |
e48e37fc | 1294 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 1295 | return Status;\r |
1296 | \r | |
1297 | }\r | |
1298 | \r | |
1299 | \r | |
1300 | /**\r | |
1301 | Change the IP4 child's multicast setting. The caller\r | |
1302 | should make sure that the parameters is valid.\r | |
1303 | \r | |
1304 | @param IpInstance The IP4 child to change the setting.\r | |
1305 | @param JoinFlag TRUE to join the group, otherwise leave it\r | |
1306 | @param GroupAddress The target group address\r | |
1307 | \r | |
1308 | @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r | |
1309 | @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r | |
1310 | @retval EFI_DEVICE_ERROR Failed to set the group configuraton\r | |
1311 | @retval EFI_SUCCESS Successfully updated the group setting.\r | |
1312 | @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r | |
1313 | \r | |
1314 | **/\r | |
1315 | EFI_STATUS\r | |
1316 | Ip4Groups (\r | |
1317 | IN IP4_PROTOCOL *IpInstance,\r | |
1318 | IN BOOLEAN JoinFlag,\r | |
1319 | IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r | |
1320 | )\r | |
1321 | {\r | |
1322 | IP4_ADDR *Members;\r | |
1323 | IP4_ADDR Group;\r | |
1324 | UINT32 Index;\r | |
1325 | \r | |
1326 | //\r | |
1327 | // Add it to the instance's Groups, and join the group by IGMP.\r | |
1328 | // IpInstance->Groups is in network byte order. IGMP operates in\r | |
1329 | // host byte order\r | |
1330 | //\r | |
1331 | if (JoinFlag) {\r | |
e48e37fc | 1332 | CopyMem (&Group, GroupAddress, sizeof (IP4_ADDR));\r |
772db4bb | 1333 | \r |
1334 | for (Index = 0; Index < IpInstance->GroupCount; Index++) {\r | |
1335 | if (IpInstance->Groups[Index] == Group) {\r | |
1336 | return EFI_ALREADY_STARTED;\r | |
1337 | }\r | |
1338 | }\r | |
1339 | \r | |
1340 | Members = Ip4CombineGroups (IpInstance->Groups, IpInstance->GroupCount, Group);\r | |
1341 | \r | |
1342 | if (Members == NULL) {\r | |
1343 | return EFI_OUT_OF_RESOURCES;\r | |
1344 | }\r | |
1345 | \r | |
1346 | if (EFI_ERROR (Ip4JoinGroup (IpInstance, NTOHL (Group)))) {\r | |
e48e37fc | 1347 | gBS->FreePool (Members);\r |
772db4bb | 1348 | return EFI_DEVICE_ERROR;\r |
1349 | }\r | |
1350 | \r | |
1351 | if (IpInstance->Groups != NULL) {\r | |
e48e37fc | 1352 | gBS->FreePool (IpInstance->Groups);\r |
772db4bb | 1353 | }\r |
1354 | \r | |
1355 | IpInstance->Groups = Members;\r | |
1356 | IpInstance->GroupCount++;\r | |
1357 | \r | |
1358 | return EFI_SUCCESS;\r | |
1359 | }\r | |
1360 | \r | |
1361 | //\r | |
1362 | // Leave the group. Leave all the groups if GroupAddress is NULL.\r | |
1363 | // Must iterate from the end to the beginning because the GroupCount\r | |
1364 | // is decreamented each time an address is removed..\r | |
1365 | //\r | |
1366 | for (Index = IpInstance->GroupCount; Index > 0 ; Index--) {\r | |
1367 | Group = IpInstance->Groups[Index - 1];\r | |
1368 | \r | |
84b5c78e | 1369 | if ((GroupAddress == NULL) || EFI_IP4_EQUAL (&Group, GroupAddress)) {\r |
772db4bb | 1370 | if (EFI_ERROR (Ip4LeaveGroup (IpInstance, NTOHL (Group)))) {\r |
1371 | return EFI_DEVICE_ERROR;\r | |
1372 | }\r | |
1373 | \r | |
1374 | Ip4RemoveGroupAddr (IpInstance->Groups, IpInstance->GroupCount, Group);\r | |
1375 | IpInstance->GroupCount--;\r | |
1376 | \r | |
1377 | if (IpInstance->GroupCount == 0) {\r | |
1378 | ASSERT (Index == 1);\r | |
1379 | \r | |
e48e37fc | 1380 | gBS->FreePool (IpInstance->Groups);\r |
772db4bb | 1381 | IpInstance->Groups = NULL;\r |
1382 | }\r | |
1383 | \r | |
1384 | if (GroupAddress != NULL) {\r | |
1385 | return EFI_SUCCESS;\r | |
1386 | }\r | |
1387 | }\r | |
1388 | }\r | |
1389 | \r | |
1390 | return ((GroupAddress != NULL) ? EFI_NOT_FOUND : EFI_SUCCESS);\r | |
1391 | }\r | |
1392 | \r | |
1393 | \r | |
1394 | /**\r | |
5405e9a6 | 1395 | Joins and leaves multicast groups.\r |
1396 | \r | |
1397 | The Groups() function is used to join and leave multicast group sessions. Joining\r | |
1398 | a group will enable reception of matching multicast packets. Leaving a group will\r | |
1399 | disable the multicast packet reception.\r | |
1400 | \r | |
1401 | If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left.\r | |
1402 | \r | |
1403 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
1404 | @param JoinFlag Set to TRUE to join the multicast group session and FALSE to leave.\r | |
1405 | @param GroupAddress Pointer to the IPv4 multicast address.\r | |
1406 | \r | |
1407 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1408 | @retval EFI_INVALID_PARAMETER One or more of the following is TRUE:\r | |
1409 | - This is NULL.\r | |
1410 | - JoinFlag is TRUE and GroupAddress is NULL.\r | |
1411 | - GroupAddress is not NULL and *GroupAddress is\r | |
1412 | not a multicast IPv4 address.\r | |
1413 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1414 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
1415 | RARP, etc.) is not finished yet.\r | |
1416 | @retval EFI_OUT_OF_RESOURCES System resources could not be allocated.\r | |
1417 | @retval EFI_UNSUPPORTED This EFI IPv4 Protocol implementation does not support multicast groups.\r | |
1418 | @retval EFI_ALREADY_STARTED The group address is already in the group table (when\r | |
1419 | JoinFlag is TRUE).\r | |
1420 | @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is FALSE).\r | |
1421 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
772db4bb | 1422 | \r |
1423 | **/\r | |
772db4bb | 1424 | EFI_STATUS\r |
1425 | EFIAPI\r | |
1426 | EfiIp4Groups (\r | |
1427 | IN EFI_IP4_PROTOCOL *This,\r | |
1428 | IN BOOLEAN JoinFlag,\r | |
1429 | IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r | |
1430 | )\r | |
1431 | {\r | |
1432 | IP4_PROTOCOL *IpInstance;\r | |
1433 | EFI_STATUS Status;\r | |
1434 | EFI_TPL OldTpl;\r | |
1435 | IP4_ADDR McastIp;\r | |
1436 | \r | |
1437 | if ((This == NULL) || (JoinFlag && (GroupAddress == NULL))) {\r | |
1438 | return EFI_INVALID_PARAMETER;\r | |
1439 | }\r | |
1440 | \r | |
1441 | if (GroupAddress != NULL) {\r | |
e48e37fc | 1442 | CopyMem (&McastIp, GroupAddress, sizeof (IP4_ADDR));\r |
772db4bb | 1443 | \r |
1444 | if (!IP4_IS_MULTICAST (NTOHL (McastIp))) {\r | |
1445 | return EFI_INVALID_PARAMETER;\r | |
1446 | }\r | |
1447 | }\r | |
1448 | \r | |
1449 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
e48e37fc | 1450 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1451 | \r |
1452 | if (IpInstance->State != IP4_STATE_CONFIGED) {\r | |
1453 | Status = EFI_NOT_STARTED;\r | |
1454 | goto ON_EXIT;\r | |
1455 | }\r | |
1456 | \r | |
1457 | if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
1458 | Status = EFI_NO_MAPPING;\r | |
1459 | goto ON_EXIT;\r | |
1460 | }\r | |
1461 | \r | |
1462 | Status = Ip4Groups (IpInstance, JoinFlag, GroupAddress);\r | |
1463 | \r | |
1464 | ON_EXIT:\r | |
e48e37fc | 1465 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 1466 | return Status;\r |
1467 | }\r | |
1468 | \r | |
1469 | \r | |
1470 | /**\r | |
5405e9a6 | 1471 | Adds and deletes routing table entries.\r |
1472 | \r | |
1473 | The Routes() function adds a route to or deletes a route from the routing table.\r | |
1474 | \r | |
1475 | Routes are determined by comparing the SubnetAddress with the destination IPv4\r | |
1476 | address arithmetically AND-ed with the SubnetMask. The gateway address must be\r | |
1477 | on the same subnet as the configured station address.\r | |
1478 | \r | |
1479 | The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.\r | |
1480 | The default route matches all destination IPv4 addresses that do not match any\r | |
1481 | other routes.\r | |
1482 | \r | |
1483 | A GatewayAddress that is zero is a nonroute. Packets are sent to the destination\r | |
1484 | IP address if it can be found in the ARP cache or on the local subnet. One automatic\r | |
1485 | nonroute entry will be inserted into the routing table for outgoing packets that\r | |
1486 | are addressed to a local subnet (gateway address of 0.0.0.0).\r | |
1487 | \r | |
1488 | Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI\r | |
1489 | IPv4 Protocol instances that use the default IPv4 address will also have copies\r | |
1490 | of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these\r | |
1491 | copies will be updated whenever the EIF IPv4 Protocol driver reconfigures its\r | |
1492 | instances. As a result, client modification to the routing table will be lost.\r | |
1493 | \r | |
1494 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
1495 | @param DeleteRoute Set to TRUE to delete this route from the routing table. Set to\r | |
1496 | FALSE to add this route to the routing table. SubnetAddress\r | |
1497 | and SubnetMask are used as the key to each route entry.\r | |
1498 | @param SubnetAddress The address of the subnet that needs to be routed.\r | |
1499 | @param SubnetMask The subnet mask of SubnetAddress.\r | |
1500 | @param GatewayAddress The unicast gateway IPv4 address for this route.\r | |
1501 | \r | |
1502 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1503 | @retval EFI_NOT_STARTED The driver instance has not been started.\r | |
1504 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
1505 | RARP, etc.) is not finished yet.\r | |
1506 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
1507 | - This is NULL.\r | |
1508 | - SubnetAddress is NULL.\r | |
1509 | - SubnetMask is NULL.\r | |
1510 | - GatewayAddress is NULL.\r | |
1511 | - *SubnetAddress is not a valid subnet address.\r | |
1512 | - *SubnetMask is not a valid subnet mask.\r | |
1513 | - *GatewayAddress is not a valid unicast IPv4 address.\r | |
1514 | @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.\r | |
1515 | @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE).\r | |
1516 | @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when\r | |
1517 | DeleteRoute is FALSE).\r | |
1518 | \r | |
772db4bb | 1519 | **/\r |
772db4bb | 1520 | EFI_STATUS\r |
1521 | EFIAPI\r | |
1522 | EfiIp4Routes (\r | |
1523 | IN EFI_IP4_PROTOCOL *This,\r | |
1524 | IN BOOLEAN DeleteRoute,\r | |
1525 | IN EFI_IPv4_ADDRESS *SubnetAddress,\r | |
1526 | IN EFI_IPv4_ADDRESS *SubnetMask,\r | |
1527 | IN EFI_IPv4_ADDRESS *GatewayAddress\r | |
1528 | )\r | |
1529 | {\r | |
1530 | IP4_PROTOCOL *IpInstance;\r | |
1531 | IP4_INTERFACE *IpIf;\r | |
1532 | IP4_ADDR Dest;\r | |
1533 | IP4_ADDR Netmask;\r | |
1534 | IP4_ADDR Nexthop;\r | |
1535 | EFI_STATUS Status;\r | |
1536 | EFI_TPL OldTpl;\r | |
1537 | \r | |
1538 | //\r | |
1539 | // First, validate the parameters\r | |
1540 | //\r | |
1541 | if ((This == NULL) || (SubnetAddress == NULL) ||\r | |
1542 | (SubnetMask == NULL) || (GatewayAddress == NULL)) {\r | |
1543 | return EFI_INVALID_PARAMETER;\r | |
1544 | }\r | |
1545 | \r | |
1546 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
e48e37fc | 1547 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1548 | \r |
1549 | if (IpInstance->State != IP4_STATE_CONFIGED) {\r | |
1550 | Status = EFI_NOT_STARTED;\r | |
1551 | goto ON_EXIT;\r | |
1552 | }\r | |
1553 | \r | |
1554 | if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
1555 | Status = EFI_NO_MAPPING;\r | |
1556 | goto ON_EXIT;\r | |
1557 | }\r | |
1558 | \r | |
e48e37fc | 1559 | CopyMem (&Dest, SubnetAddress, sizeof (IP4_ADDR));\r |
1560 | CopyMem (&Netmask, SubnetMask, sizeof (IP4_ADDR));\r | |
1561 | CopyMem (&Nexthop, GatewayAddress, sizeof (IP4_ADDR));\r | |
772db4bb | 1562 | \r |
1563 | Dest = NTOHL (Dest);\r | |
1564 | Netmask = NTOHL (Netmask);\r | |
1565 | Nexthop = NTOHL (Nexthop);\r | |
1566 | \r | |
1567 | IpIf = IpInstance->Interface;\r | |
1568 | \r | |
1569 | if (!IP4_IS_VALID_NETMASK (Netmask)) {\r | |
1570 | Status = EFI_INVALID_PARAMETER;\r | |
1571 | goto ON_EXIT;\r | |
1572 | }\r | |
1573 | \r | |
1574 | //\r | |
1575 | // the gateway address must be a unicast on the connected network if not zero.\r | |
1576 | //\r | |
1577 | if ((Nexthop != IP4_ALLZERO_ADDRESS) &&\r | |
1578 | (!IP4_NET_EQUAL (Nexthop, IpIf->Ip, IpIf->SubnetMask) ||\r | |
1579 | IP4_IS_BROADCAST (Ip4GetNetCast (Nexthop, IpIf)))) {\r | |
1580 | \r | |
1581 | Status = EFI_INVALID_PARAMETER;\r | |
1582 | goto ON_EXIT;\r | |
1583 | }\r | |
1584 | \r | |
1585 | if (DeleteRoute) {\r | |
1586 | Status = Ip4DelRoute (IpInstance->RouteTable, Dest, Netmask, Nexthop);\r | |
1587 | } else {\r | |
1588 | Status = Ip4AddRoute (IpInstance->RouteTable, Dest, Netmask, Nexthop);\r | |
1589 | }\r | |
1590 | \r | |
1591 | ON_EXIT:\r | |
e48e37fc | 1592 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 1593 | return Status;\r |
1594 | }\r | |
1595 | \r | |
1596 | \r | |
1597 | /**\r | |
1598 | Check whether the user's token or event has already\r | |
5405e9a6 | 1599 | been enqueued on IP4's list.\r |
772db4bb | 1600 | \r |
1601 | @param Map The container of either user's transmit or receive\r | |
1602 | token.\r | |
1603 | @param Item Current item to check against\r | |
1604 | @param Context The Token to check againist.\r | |
1605 | \r | |
1606 | @retval EFI_ACCESS_DENIED The token or event has already been enqueued in IP\r | |
1607 | @retval EFI_SUCCESS The current item isn't the same token/event as the\r | |
1608 | context.\r | |
1609 | \r | |
1610 | **/\r | |
772db4bb | 1611 | EFI_STATUS\r |
1612 | Ip4TokenExist (\r | |
1613 | IN NET_MAP *Map,\r | |
1614 | IN NET_MAP_ITEM *Item,\r | |
1615 | IN VOID *Context\r | |
1616 | )\r | |
1617 | {\r | |
1618 | EFI_IP4_COMPLETION_TOKEN *Token;\r | |
1619 | EFI_IP4_COMPLETION_TOKEN *TokenInItem;\r | |
1620 | \r | |
1621 | Token = (EFI_IP4_COMPLETION_TOKEN *) Context;\r | |
1622 | TokenInItem = (EFI_IP4_COMPLETION_TOKEN *) Item->Key;\r | |
1623 | \r | |
1624 | if ((Token == TokenInItem) || (Token->Event == TokenInItem->Event)) {\r | |
1625 | return EFI_ACCESS_DENIED;\r | |
1626 | }\r | |
1627 | \r | |
1628 | return EFI_SUCCESS;\r | |
1629 | }\r | |
1630 | \r | |
1631 | \r | |
1632 | /**\r | |
1633 | Validate the user's token against current station address.\r | |
1634 | \r | |
1635 | @param Token User's token to validate\r | |
1636 | @param IpIf The IP4 child's interface.\r | |
1637 | \r | |
1638 | @retval EFI_INVALID_PARAMETER Some parameters are invalid\r | |
1639 | @retval EFI_BAD_BUFFER_SIZE The user's option/data is too long.\r | |
1640 | @retval EFI_SUCCESS The token is OK\r | |
1641 | \r | |
1642 | **/\r | |
772db4bb | 1643 | EFI_STATUS\r |
1644 | Ip4TxTokenValid (\r | |
1645 | IN EFI_IP4_COMPLETION_TOKEN *Token,\r | |
1646 | IN IP4_INTERFACE *IpIf\r | |
1647 | )\r | |
1648 | {\r | |
1649 | EFI_IP4_TRANSMIT_DATA *TxData;\r | |
1650 | EFI_IP4_OVERRIDE_DATA *Override;\r | |
1651 | IP4_ADDR Src;\r | |
1652 | IP4_ADDR Gateway;\r | |
1653 | UINT32 Offset;\r | |
1654 | UINT32 Index;\r | |
1655 | UINT32 HeadLen;\r | |
1656 | \r | |
1657 | if ((Token == NULL) || (Token->Event == NULL) || (Token->Packet.TxData == NULL)) {\r | |
1658 | return EFI_INVALID_PARAMETER;\r | |
1659 | }\r | |
1660 | \r | |
1661 | TxData = Token->Packet.TxData;\r | |
1662 | \r | |
1663 | //\r | |
1664 | // Check the IP options: no more than 40 bytes and format is OK\r | |
1665 | //\r | |
1666 | if (TxData->OptionsLength != 0) {\r | |
1667 | if ((TxData->OptionsLength > 40) || (TxData->OptionsBuffer == NULL)) {\r | |
1668 | return EFI_INVALID_PARAMETER;\r | |
1669 | }\r | |
1670 | \r | |
1671 | if (!Ip4OptionIsValid (TxData->OptionsBuffer, TxData->OptionsLength, FALSE)) {\r | |
1672 | return EFI_INVALID_PARAMETER;\r | |
1673 | }\r | |
1674 | }\r | |
1675 | \r | |
1676 | //\r | |
1677 | // Check the fragment table: no empty fragment, and length isn't bogus\r | |
1678 | //\r | |
1679 | if ((TxData->TotalDataLength == 0) || (TxData->FragmentCount == 0)) {\r | |
1680 | return EFI_INVALID_PARAMETER;\r | |
1681 | }\r | |
1682 | \r | |
1683 | Offset = TxData->TotalDataLength;\r | |
1684 | \r | |
1685 | for (Index = 0; Index < TxData->FragmentCount; Index++) {\r | |
1686 | if ((TxData->FragmentTable[Index].FragmentBuffer == NULL) ||\r | |
1687 | (TxData->FragmentTable[Index].FragmentLength == 0)) {\r | |
1688 | \r | |
1689 | return EFI_INVALID_PARAMETER;\r | |
1690 | }\r | |
1691 | \r | |
1692 | Offset -= TxData->FragmentTable[Index].FragmentLength;\r | |
1693 | }\r | |
1694 | \r | |
1695 | if (Offset != 0) {\r | |
1696 | return EFI_INVALID_PARAMETER;\r | |
1697 | }\r | |
1698 | \r | |
1699 | //\r | |
1700 | // Check the source and gateway: they must be a valid unicast.\r | |
1701 | // Gateway must also be on the connected network.\r | |
1702 | //\r | |
1703 | if (TxData->OverrideData) {\r | |
1704 | Override = TxData->OverrideData;\r | |
1705 | \r | |
e48e37fc | 1706 | CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR));\r |
1707 | CopyMem (&Gateway, &Override->GatewayAddress, sizeof (IP4_ADDR));\r | |
772db4bb | 1708 | \r |
1709 | Src = NTOHL (Src);\r | |
1710 | Gateway = NTOHL (Gateway);\r | |
1711 | \r | |
1712 | if ((NetGetIpClass (Src) > IP4_ADDR_CLASSC) ||\r | |
1713 | (Src == IP4_ALLONE_ADDRESS) ||\r | |
1714 | IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {\r | |
1715 | \r | |
1716 | return EFI_INVALID_PARAMETER;\r | |
1717 | }\r | |
1718 | \r | |
1719 | //\r | |
1720 | // If gateway isn't zero, it must be a unicast address, and\r | |
1721 | // on the connected network.\r | |
1722 | //\r | |
1723 | if ((Gateway != IP4_ALLZERO_ADDRESS) &&\r | |
1724 | ((NetGetIpClass (Gateway) > IP4_ADDR_CLASSC) ||\r | |
1725 | !IP4_NET_EQUAL (Gateway, IpIf->Ip, IpIf->SubnetMask) ||\r | |
1726 | IP4_IS_BROADCAST (Ip4GetNetCast (Gateway, IpIf)))) {\r | |
1727 | \r | |
1728 | return EFI_INVALID_PARAMETER;\r | |
1729 | }\r | |
1730 | }\r | |
1731 | \r | |
1732 | //\r | |
1733 | // Check the packet length: Head length and packet length all has a limit\r | |
1734 | //\r | |
1735 | HeadLen = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03);\r | |
1736 | \r | |
1737 | if ((HeadLen > IP4_MAX_HEADLEN) ||\r | |
1738 | (TxData->TotalDataLength + HeadLen > IP4_MAX_PACKET_SIZE)) {\r | |
1739 | \r | |
1740 | return EFI_BAD_BUFFER_SIZE;\r | |
1741 | }\r | |
1742 | \r | |
1743 | return EFI_SUCCESS;\r | |
1744 | }\r | |
1745 | \r | |
1746 | \r | |
1747 | /**\r | |
1748 | The callback function for the net buffer which wraps the user's\r | |
1749 | transmit token. Although it seems this function is pretty simple,\r | |
1750 | there are some subtle things.\r | |
1751 | When user requests the IP to transmit a packet by passing it a\r | |
1752 | token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r | |
1753 | is wrapped in an net buffer. the net buffer's Free function is\r | |
1754 | set to Ip4FreeTxToken. The Token and token wrap are added to the\r | |
1755 | IP child's TxToken map. Then the buffer is passed to Ip4Output for\r | |
1756 | transmission. If something error happened before that, the buffer\r | |
1757 | is freed, which in turn will free the token wrap. The wrap may\r | |
1758 | have been added to the TxToken map or not, and the user's event\r | |
1759 | shouldn't be fired because we are still in the EfiIp4Transmit. If\r | |
1760 | the buffer has been sent by Ip4Output, it should be removed from\r | |
1761 | the TxToken map and user's event signaled. The token wrap and buffer\r | |
1762 | are bound together. Check the comments in Ip4Output for information\r | |
1763 | about IP fragmentation.\r | |
1764 | \r | |
1765 | @param Context The token's wrap\r | |
1766 | \r | |
1767 | @return None\r | |
1768 | \r | |
1769 | **/\r | |
772db4bb | 1770 | VOID\r |
1771 | Ip4FreeTxToken (\r | |
1772 | IN VOID *Context\r | |
1773 | )\r | |
1774 | {\r | |
1775 | IP4_TXTOKEN_WRAP *Wrap;\r | |
1776 | NET_MAP_ITEM *Item;\r | |
1777 | \r | |
1778 | Wrap = (IP4_TXTOKEN_WRAP *) Context;\r | |
1779 | \r | |
1780 | //\r | |
1781 | // Find the token in the instance's map. EfiIp4Transmit put the\r | |
1782 | // token to the map. If that failed, NetMapFindKey will return NULL.\r | |
1783 | //\r | |
1784 | Item = NetMapFindKey (&Wrap->IpInstance->TxTokens, Wrap->Token);\r | |
1785 | \r | |
1786 | if (Item != NULL) {\r | |
1787 | NetMapRemoveItem (&Wrap->IpInstance->TxTokens, Item, NULL);\r | |
1788 | }\r | |
1789 | \r | |
1790 | if (Wrap->Sent) {\r | |
1791 | gBS->SignalEvent (Wrap->Token->Event);\r | |
36ee91ca | 1792 | \r |
1793 | //\r | |
1794 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r | |
1795 | //\r | |
1796 | NetLibDispatchDpc ();\r | |
772db4bb | 1797 | }\r |
1798 | \r | |
e48e37fc | 1799 | gBS->FreePool (Wrap);\r |
772db4bb | 1800 | }\r |
1801 | \r | |
1802 | \r | |
1803 | /**\r | |
1804 | The callback function to Ip4Output to update the transmit status.\r | |
1805 | \r | |
1806 | @param Ip4Instance The Ip4Instance that request the transmit.\r | |
1807 | @param Packet The user's transmit request\r | |
1808 | @param IoStatus The result of the transmission\r | |
1809 | @param Flag Not used during transmission\r | |
1810 | @param Context The token's wrap.\r | |
1811 | \r | |
1812 | @return None\r | |
1813 | \r | |
1814 | **/\r | |
772db4bb | 1815 | VOID\r |
1816 | Ip4OnPacketSent (\r | |
1817 | IP4_PROTOCOL *Ip4Instance,\r | |
1818 | NET_BUF *Packet,\r | |
1819 | EFI_STATUS IoStatus,\r | |
1820 | UINT32 Flag,\r | |
1821 | VOID *Context\r | |
1822 | )\r | |
1823 | {\r | |
1824 | IP4_TXTOKEN_WRAP *Wrap;\r | |
1825 | \r | |
1826 | //\r | |
1827 | // This is the transmission request from upper layer,\r | |
1828 | // not the IP4 driver itself.\r | |
1829 | //\r | |
1830 | ASSERT (Ip4Instance != NULL);\r | |
1831 | \r | |
1832 | //\r | |
1833 | // The first fragment of the packet has been sent. Update\r | |
1834 | // the token's status. That is, if fragmented, the transmit's\r | |
1835 | // status is the first fragment's status. The Wrap will be\r | |
1836 | // release when all the fragments are release. Check the comments\r | |
1837 | // in Ip4FreeTxToken and Ip4Output for information.\r | |
1838 | //\r | |
1839 | Wrap = (IP4_TXTOKEN_WRAP *) Context;\r | |
1840 | Wrap->Token->Status = IoStatus;\r | |
1841 | \r | |
1842 | NetbufFree (Wrap->Packet);\r | |
1843 | }\r | |
1844 | \r | |
1845 | \r | |
1846 | /**\r | |
5405e9a6 | 1847 | Places outgoing data packets into the transmit queue.\r |
1848 | \r | |
1849 | The Transmit() function places a sending request in the transmit queue of this\r | |
1850 | EFI IPv4 Protocol instance. Whenever the packet in the token is sent out or some\r | |
1851 | errors occur, the event in the token will be signaled and the status is updated.\r | |
1852 | \r | |
1853 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
1854 | @param Token Pointer to the transmit token.\r | |
1855 | \r | |
1856 | @retval EFI_SUCCESS The data has been queued for transmission.\r | |
1857 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
1858 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
1859 | RARP, etc.) is not finished yet.\r | |
1860 | @retval EFI_INVALID_PARAMETER One or more pameters are invalid.\r | |
1861 | @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event\r | |
1862 | was already in the transmit queue.\r | |
1863 | @retval EFI_NOT_READY The completion token could not be queued because the transmit\r | |
1864 | queue is full. \r | |
1865 | @retval EFI_NOT_FOUND Not route is found to destination address.\r | |
1866 | @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.\r | |
1867 | @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too\r | |
1868 | short to transmit.\r | |
1869 | @retval EFI_BAD_BUFFER_SIZE The length of the IPv4 header + option length + total data length is\r | |
1870 | greater than MTU (or greater than the maximum packet size if\r | |
1871 | Token.Packet.TxData.OverrideData.\r | |
1872 | DoNotFragment is TRUE.)\r | |
772db4bb | 1873 | \r |
1874 | **/\r | |
772db4bb | 1875 | EFI_STATUS\r |
1876 | EFIAPI\r | |
1877 | EfiIp4Transmit (\r | |
1878 | IN EFI_IP4_PROTOCOL *This,\r | |
1879 | IN EFI_IP4_COMPLETION_TOKEN *Token\r | |
1880 | )\r | |
1881 | {\r | |
1882 | IP4_SERVICE *IpSb;\r | |
1883 | IP4_PROTOCOL *IpInstance;\r | |
1884 | IP4_INTERFACE *IpIf;\r | |
1885 | IP4_TXTOKEN_WRAP *Wrap;\r | |
1886 | EFI_IP4_TRANSMIT_DATA *TxData;\r | |
1887 | EFI_IP4_CONFIG_DATA *Config;\r | |
1888 | EFI_IP4_OVERRIDE_DATA *Override;\r | |
1889 | IP4_HEAD Head;\r | |
1890 | IP4_ADDR GateWay;\r | |
1891 | EFI_STATUS Status;\r | |
1892 | EFI_TPL OldTpl;\r | |
1893 | BOOLEAN DontFragment;\r | |
1894 | UINT32 HeadLen;\r | |
1895 | \r | |
1896 | if (This == NULL) {\r | |
1897 | return EFI_INVALID_PARAMETER;\r | |
1898 | }\r | |
1899 | \r | |
1900 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
1901 | \r | |
1902 | if (IpInstance->State != IP4_STATE_CONFIGED) {\r | |
1903 | return EFI_NOT_STARTED;\r | |
1904 | }\r | |
1905 | \r | |
e48e37fc | 1906 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 1907 | \r |
1908 | IpSb = IpInstance->Service;\r | |
1909 | IpIf = IpInstance->Interface;\r | |
1910 | Config = &IpInstance->ConfigData;\r | |
1911 | \r | |
1912 | if (Config->UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
1913 | Status = EFI_NO_MAPPING;\r | |
1914 | goto ON_EXIT;\r | |
1915 | }\r | |
1916 | \r | |
1917 | //\r | |
1918 | // make sure that token is properly formated\r | |
1919 | //\r | |
1920 | Status = Ip4TxTokenValid (Token, IpIf);\r | |
1921 | \r | |
1922 | if (EFI_ERROR (Status)) {\r | |
1923 | goto ON_EXIT;\r | |
1924 | }\r | |
1925 | \r | |
1926 | //\r | |
1927 | // Check whether the token or signal already existed.\r | |
1928 | //\r | |
1929 | if (EFI_ERROR (NetMapIterate (&IpInstance->TxTokens, Ip4TokenExist, Token))) {\r | |
1930 | Status = EFI_ACCESS_DENIED;\r | |
1931 | goto ON_EXIT;\r | |
1932 | }\r | |
1933 | \r | |
1934 | //\r | |
1935 | // Build the IP header, need to fill in the Tos, TotalLen, Id,\r | |
1936 | // fragment, Ttl, protocol, Src, and Dst.\r | |
1937 | //\r | |
1938 | TxData = Token->Packet.TxData;\r | |
1939 | \r | |
e48e37fc | 1940 | CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR));\r |
772db4bb | 1941 | Head.Dst = NTOHL (Head.Dst);\r |
1942 | \r | |
1943 | if (TxData->OverrideData) {\r | |
1944 | Override = TxData->OverrideData;\r | |
1945 | Head.Protocol = Override->Protocol;\r | |
1946 | Head.Tos = Override->TypeOfService;\r | |
1947 | Head.Ttl = Override->TimeToLive;\r | |
1948 | DontFragment = Override->DoNotFragment;\r | |
1949 | \r | |
e48e37fc | 1950 | CopyMem (&Head.Src, &Override->SourceAddress, sizeof (IP4_ADDR));\r |
1951 | CopyMem (&GateWay, &Override->GatewayAddress, sizeof (IP4_ADDR));\r | |
772db4bb | 1952 | \r |
1953 | Head.Src = NTOHL (Head.Src);\r | |
1954 | GateWay = NTOHL (GateWay);\r | |
1955 | } else {\r | |
1956 | Head.Src = IpIf->Ip;\r | |
1957 | GateWay = IP4_ALLZERO_ADDRESS;\r | |
1958 | Head.Protocol = Config->DefaultProtocol;\r | |
1959 | Head.Tos = Config->TypeOfService;\r | |
1960 | Head.Ttl = Config->TimeToLive;\r | |
1961 | DontFragment = Config->DoNotFragment;\r | |
1962 | }\r | |
1963 | \r | |
1964 | Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0);\r | |
1965 | HeadLen = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03);\r | |
1966 | \r | |
1967 | //\r | |
1968 | // If don't fragment and fragment needed, return error\r | |
1969 | //\r | |
1970 | if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->SnpMode.MaxPacketSize)) {\r | |
1971 | Status = EFI_BAD_BUFFER_SIZE;\r | |
1972 | goto ON_EXIT;\r | |
1973 | }\r | |
1974 | \r | |
1975 | //\r | |
1976 | // OK, it survives all the validation check. Wrap the token in\r | |
1977 | // a IP4_TXTOKEN_WRAP and the data in a netbuf\r | |
1978 | //\r | |
1979 | Status = EFI_OUT_OF_RESOURCES;\r | |
e48e37fc | 1980 | Wrap = AllocatePool (sizeof (IP4_TXTOKEN_WRAP));\r |
772db4bb | 1981 | if (Wrap == NULL) {\r |
1982 | goto ON_EXIT;\r | |
1983 | }\r | |
1984 | \r | |
1985 | Wrap->IpInstance = IpInstance;\r | |
1986 | Wrap->Token = Token;\r | |
1987 | Wrap->Sent = FALSE;\r | |
1988 | Wrap->Life = IP4_US_TO_SEC (Config->TransmitTimeout);\r | |
1989 | Wrap->Packet = NetbufFromExt (\r | |
1990 | (NET_FRAGMENT *) TxData->FragmentTable,\r | |
1991 | TxData->FragmentCount,\r | |
1992 | IP4_MAX_HEADLEN,\r | |
1993 | 0,\r | |
1994 | Ip4FreeTxToken,\r | |
1995 | Wrap\r | |
1996 | );\r | |
1997 | \r | |
1998 | if (Wrap->Packet == NULL) {\r | |
e48e37fc | 1999 | gBS->FreePool (Wrap);\r |
772db4bb | 2000 | goto ON_EXIT;\r |
2001 | }\r | |
2002 | \r | |
2003 | Token->Status = EFI_NOT_READY;\r | |
2004 | \r | |
2005 | if (EFI_ERROR (NetMapInsertTail (&IpInstance->TxTokens, Token, Wrap))) {\r | |
2006 | //\r | |
2007 | // NetbufFree will call Ip4FreeTxToken, which in turn will\r | |
2008 | // free the IP4_TXTOKEN_WRAP. Now, the token wrap hasn't been\r | |
2009 | // enqueued.\r | |
2010 | //\r | |
2011 | NetbufFree (Wrap->Packet);\r | |
2012 | goto ON_EXIT;\r | |
2013 | }\r | |
2014 | \r | |
36ee91ca | 2015 | //\r |
2016 | // Mark the packet sent before output it. Mark it not sent again if the\r | |
2017 | // returned status is not EFI_SUCCESS;\r | |
2018 | //\r | |
2019 | Wrap->Sent = TRUE;\r | |
2020 | \r | |
772db4bb | 2021 | Status = Ip4Output (\r |
2022 | IpSb,\r | |
2023 | IpInstance,\r | |
2024 | Wrap->Packet,\r | |
2025 | &Head,\r | |
2026 | TxData->OptionsBuffer,\r | |
2027 | TxData->OptionsLength,\r | |
2028 | GateWay,\r | |
2029 | Ip4OnPacketSent,\r | |
2030 | Wrap\r | |
2031 | );\r | |
2032 | \r | |
2033 | if (EFI_ERROR (Status)) {\r | |
36ee91ca | 2034 | Wrap->Sent = FALSE;\r |
772db4bb | 2035 | NetbufFree (Wrap->Packet);\r |
772db4bb | 2036 | }\r |
2037 | \r | |
772db4bb | 2038 | ON_EXIT:\r |
e48e37fc | 2039 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 2040 | return Status;\r |
2041 | }\r | |
2042 | \r | |
2043 | \r | |
2044 | /**\r | |
5405e9a6 | 2045 | Places a receiving request into the receiving queue.\r |
2046 | \r | |
2047 | The Receive() function places a completion token into the receive packet queue.\r | |
2048 | This function is always asynchronous.\r | |
2049 | \r | |
2050 | The Token.Event field in the completion token must be filled in by the caller\r | |
2051 | and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol\r | |
2052 | driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event\r | |
2053 | is signaled.\r | |
2054 | \r | |
2055 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
2056 | @param Token Pointer to a token that is associated with the receive data descriptor.\r | |
2057 | \r | |
2058 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
2059 | @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.\r | |
2060 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP, RARP, etc.)\r | |
2061 | is not finished yet.\r | |
2062 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
2063 | - This is NULL.\r | |
2064 | - Token is NULL.\r | |
2065 | - Token.Event is NULL.\r | |
2066 | @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system\r | |
2067 | resources (usually memory).\r | |
2068 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
2069 | The EFI IPv4 Protocol instance has been reset to startup defaults.\r | |
2070 | EFI_ACCESS_DENIED The receive completion token with the same Token.Event was already\r | |
2071 | in the receive queue.\r | |
2072 | @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.\r | |
2073 | @retval EFI_ICMP_ERROR An ICMP error packet was received.\r | |
772db4bb | 2074 | \r |
2075 | **/\r | |
772db4bb | 2076 | EFI_STATUS\r |
2077 | EFIAPI\r | |
2078 | EfiIp4Receive (\r | |
2079 | IN EFI_IP4_PROTOCOL *This,\r | |
2080 | IN EFI_IP4_COMPLETION_TOKEN *Token\r | |
2081 | )\r | |
2082 | {\r | |
2083 | IP4_PROTOCOL *IpInstance;\r | |
772db4bb | 2084 | EFI_STATUS Status;\r |
2085 | EFI_TPL OldTpl;\r | |
2086 | \r | |
2087 | //\r | |
2088 | // First validate the parameters\r | |
2089 | //\r | |
2090 | if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r | |
2091 | return EFI_INVALID_PARAMETER;\r | |
2092 | }\r | |
2093 | \r | |
2094 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
2095 | \r | |
e48e37fc | 2096 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 2097 | \r |
2098 | if (IpInstance->State != IP4_STATE_CONFIGED) {\r | |
2099 | Status = EFI_NOT_STARTED;\r | |
2100 | goto ON_EXIT;\r | |
2101 | }\r | |
2102 | \r | |
772db4bb | 2103 | //\r |
2104 | // Check whether the toke is already on the receive queue.\r | |
2105 | //\r | |
2106 | Status = NetMapIterate (&IpInstance->RxTokens, Ip4TokenExist, Token);\r | |
2107 | \r | |
2108 | if (EFI_ERROR (Status)) {\r | |
2109 | Status = EFI_ACCESS_DENIED;\r | |
2110 | goto ON_EXIT;\r | |
2111 | }\r | |
2112 | \r | |
2113 | //\r | |
2114 | // Queue the token then check whether there is pending received packet.\r | |
2115 | //\r | |
2116 | Status = NetMapInsertTail (&IpInstance->RxTokens, Token, NULL);\r | |
2117 | \r | |
2118 | if (EFI_ERROR (Status)) {\r | |
2119 | goto ON_EXIT;\r | |
2120 | }\r | |
2121 | \r | |
2122 | Status = Ip4InstanceDeliverPacket (IpInstance);\r | |
2123 | \r | |
36ee91ca | 2124 | //\r |
2125 | // Dispatch the DPC queued by the NotifyFunction of this instane's receive\r | |
2126 | // event.\r | |
2127 | //\r | |
2128 | NetLibDispatchDpc ();\r | |
2129 | \r | |
772db4bb | 2130 | ON_EXIT:\r |
e48e37fc | 2131 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 2132 | return Status;\r |
2133 | }\r | |
2134 | \r | |
2135 | \r | |
2136 | /**\r | |
2137 | Cancel the transmitted but not recycled packet. If a matching\r | |
2138 | token is found, it will call Ip4CancelPacket to cancel the\r | |
2139 | packet. Ip4CancelPacket will cancel all the fragments of the\r | |
2140 | packet. When all the fragments are freed, the IP4_TXTOKEN_WRAP\r | |
2141 | will be deleted from the Map, and user's event signalled.\r | |
2142 | Because Ip4CancelPacket and other functions are all called in\r | |
2143 | line, so, after Ip4CancelPacket returns, the Item has been freed.\r | |
2144 | \r | |
2145 | @param Map The IP4 child's transmit queue\r | |
2146 | @param Item The current transmitted packet to test.\r | |
2147 | @param Context The user's token to cancel.\r | |
2148 | \r | |
2149 | @retval EFI_SUCCESS Continue to check the next Item.\r | |
2150 | @retval EFI_ABORTED The user's Token (Token != NULL) is cancelled.\r | |
2151 | \r | |
2152 | **/\r | |
772db4bb | 2153 | EFI_STATUS\r |
2154 | Ip4CancelTxTokens (\r | |
2155 | IN NET_MAP *Map,\r | |
2156 | IN NET_MAP_ITEM *Item,\r | |
2157 | IN VOID *Context\r | |
2158 | )\r | |
2159 | {\r | |
2160 | EFI_IP4_COMPLETION_TOKEN *Token;\r | |
2161 | IP4_TXTOKEN_WRAP *Wrap;\r | |
2162 | \r | |
2163 | Token = (EFI_IP4_COMPLETION_TOKEN *) Context;\r | |
2164 | \r | |
2165 | //\r | |
2166 | // Return EFI_SUCCESS to check the next item in the map if\r | |
2167 | // this one doesn't match.\r | |
2168 | //\r | |
2169 | if ((Token != NULL) && (Token != Item->Key)) {\r | |
2170 | return EFI_SUCCESS;\r | |
2171 | }\r | |
2172 | \r | |
2173 | Wrap = (IP4_TXTOKEN_WRAP *) Item->Value;\r | |
2174 | ASSERT (Wrap != NULL);\r | |
2175 | \r | |
2176 | //\r | |
2177 | // Don't access the Item, Wrap and Token's members after this point.\r | |
2178 | // Item and wrap has been freed. And we no longer own the Token.\r | |
2179 | //\r | |
2180 | Ip4CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);\r | |
2181 | \r | |
2182 | //\r | |
2183 | // If only one item is to be cancel, return EFI_ABORTED to stop\r | |
2184 | // iterating the map any more.\r | |
2185 | //\r | |
2186 | if (Token != NULL) {\r | |
2187 | return EFI_ABORTED;\r | |
2188 | }\r | |
2189 | \r | |
2190 | return EFI_SUCCESS;\r | |
2191 | }\r | |
2192 | \r | |
2193 | \r | |
2194 | /**\r | |
2195 | Cancel the receive request. This is quiet simple, because\r | |
2196 | it is only enqueued in our local receive map.\r | |
2197 | \r | |
2198 | @param Map The IP4 child's receive queue\r | |
2199 | @param Item Current receive request to cancel.\r | |
2200 | @param Context The user's token to cancel\r | |
2201 | \r | |
2202 | @retval EFI_SUCCESS Continue to check the next receive request on the\r | |
2203 | queue.\r | |
2204 | @retval EFI_ABORTED The user's token (token != NULL) has been\r | |
2205 | cancelled.\r | |
2206 | \r | |
2207 | **/\r | |
772db4bb | 2208 | EFI_STATUS\r |
2209 | Ip4CancelRxTokens (\r | |
2210 | IN NET_MAP *Map,\r | |
2211 | IN NET_MAP_ITEM *Item,\r | |
2212 | IN VOID *Context\r | |
2213 | )\r | |
2214 | {\r | |
2215 | EFI_IP4_COMPLETION_TOKEN *Token;\r | |
2216 | EFI_IP4_COMPLETION_TOKEN *This;\r | |
2217 | \r | |
2218 | Token = (EFI_IP4_COMPLETION_TOKEN *) Context;\r | |
2219 | This = Item->Key;\r | |
2220 | \r | |
2221 | if ((Token != NULL) && (Token != This)) {\r | |
2222 | return EFI_SUCCESS;\r | |
2223 | }\r | |
2224 | \r | |
2225 | NetMapRemoveItem (Map, Item, NULL);\r | |
2226 | \r | |
2227 | This->Status = EFI_ABORTED;\r | |
2228 | This->Packet.RxData = NULL;\r | |
2229 | gBS->SignalEvent (This->Event);\r | |
2230 | \r | |
2231 | if (Token != NULL) {\r | |
2232 | return EFI_ABORTED;\r | |
2233 | }\r | |
2234 | \r | |
2235 | return EFI_SUCCESS;\r | |
2236 | }\r | |
2237 | \r | |
2238 | \r | |
2239 | /**\r | |
2240 | Cancel the user's receive/transmit request.\r | |
2241 | \r | |
2242 | @param IpInstance The IP4 child\r | |
2243 | @param Token The token to cancel. If NULL, all token will be\r | |
2244 | cancelled.\r | |
2245 | \r | |
2246 | @retval EFI_SUCCESS The token is cancelled\r | |
2247 | @retval EFI_NOT_FOUND The token isn't found on either the\r | |
2248 | transmit/receive queue\r | |
2249 | @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r | |
2250 | \r | |
2251 | **/\r | |
2252 | EFI_STATUS\r | |
2253 | Ip4Cancel (\r | |
2254 | IN IP4_PROTOCOL *IpInstance,\r | |
2255 | IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r | |
2256 | )\r | |
2257 | {\r | |
2258 | EFI_STATUS Status;\r | |
2259 | \r | |
2260 | //\r | |
2261 | // First check the transmitted packet. Ip4CancelTxTokens returns\r | |
2262 | // EFI_ABORTED to mean that the token has been cancelled when\r | |
2263 | // token != NULL. So, return EFI_SUCCESS for this condition.\r | |
2264 | //\r | |
2265 | Status = NetMapIterate (&IpInstance->TxTokens, Ip4CancelTxTokens, Token);\r | |
2266 | \r | |
2267 | if (EFI_ERROR (Status)) {\r | |
2268 | if ((Token != NULL) && (Status == EFI_ABORTED)) {\r | |
2269 | return EFI_SUCCESS;\r | |
2270 | }\r | |
2271 | \r | |
2272 | return Status;\r | |
2273 | }\r | |
2274 | \r | |
2275 | //\r | |
2276 | // Check the receive queue. Ip4CancelRxTokens also returns EFI_ABORT\r | |
2277 | // for Token!=NULL and it is cancelled.\r | |
2278 | //\r | |
2279 | Status = NetMapIterate (&IpInstance->RxTokens, Ip4CancelRxTokens, Token);\r | |
36ee91ca | 2280 | //\r |
2281 | // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r | |
2282 | // events.\r | |
2283 | //\r | |
2284 | NetLibDispatchDpc ();\r | |
772db4bb | 2285 | if (EFI_ERROR (Status)) {\r |
2286 | if ((Token != NULL) && (Status == EFI_ABORTED)) {\r | |
2287 | return EFI_SUCCESS;\r | |
2288 | }\r | |
2289 | \r | |
2290 | return Status;\r | |
2291 | }\r | |
2292 | \r | |
2293 | //\r | |
2294 | // OK, if the Token is found when Token != NULL, the NetMapIterate\r | |
2295 | // will return EFI_ABORTED, which has been interrupted as EFI_SUCCESS.\r | |
2296 | //\r | |
2297 | if (Token != NULL) {\r | |
2298 | return EFI_NOT_FOUND;\r | |
2299 | }\r | |
2300 | \r | |
2301 | //\r | |
2302 | // If Token == NULL, cancel all the tokens. return error if no\r | |
2303 | // all of them are cancelled.\r | |
2304 | //\r | |
2305 | if (!NetMapIsEmpty (&IpInstance->TxTokens) ||\r | |
2306 | !NetMapIsEmpty (&IpInstance->RxTokens)) {\r | |
2307 | \r | |
2308 | return EFI_DEVICE_ERROR;\r | |
2309 | }\r | |
2310 | \r | |
2311 | return EFI_SUCCESS;\r | |
2312 | }\r | |
2313 | \r | |
2314 | \r | |
2315 | /**\r | |
5405e9a6 | 2316 | Abort an asynchronous transmit or receive request.\r |
2317 | \r | |
2318 | The Cancel() function is used to abort a pending transmit or receive request.\r | |
2319 | If the token is in the transmit or receive request queues, after calling this\r | |
2320 | function, Token->Status will be set to EFI_ABORTED and then Token->Event will\r | |
2321 | be signaled. If the token is not in one of the queues, which usually means the\r | |
2322 | asynchronous operation has completed, this function will not signal the token\r | |
2323 | and EFI_NOT_FOUND is returned.\r | |
2324 | \r | |
2325 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
2326 | @param Token Pointer to a token that has been issued by\r | |
2327 | EFI_IP4_PROTOCOL.Transmit() or\r | |
2328 | EFI_IP4_PROTOCOL.Receive(). If NULL, all pending\r | |
2329 | tokens are aborted. Type EFI_IP4_COMPLETION_TOKEN is\r | |
2330 | defined in EFI_IP4_PROTOCOL.Transmit().\r | |
2331 | \r | |
2332 | @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r | |
2333 | Token.->Event was signaled. When Token is NULL, all\r | |
2334 | pending requests were aborted and their events were signaled.\r | |
2335 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
2336 | @retval EFI_NOT_STARTED This instance has not been started.\r | |
2337 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
2338 | RARP, etc.) is not finished yet.\r | |
2339 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was\r | |
2340 | not found in the transmit or receive queue. It has either completed\r | |
2341 | or was not issued by Transmit() and Receive().\r | |
772db4bb | 2342 | \r |
2343 | **/\r | |
772db4bb | 2344 | EFI_STATUS\r |
2345 | EFIAPI\r | |
2346 | EfiIp4Cancel (\r | |
2347 | IN EFI_IP4_PROTOCOL *This,\r | |
2348 | IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r | |
2349 | )\r | |
2350 | {\r | |
2351 | IP4_PROTOCOL *IpInstance;\r | |
2352 | EFI_STATUS Status;\r | |
2353 | EFI_TPL OldTpl;\r | |
2354 | \r | |
2355 | if (This == NULL) {\r | |
2356 | return EFI_INVALID_PARAMETER;\r | |
2357 | }\r | |
2358 | \r | |
2359 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
2360 | \r | |
e48e37fc | 2361 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
772db4bb | 2362 | \r |
2363 | if (IpInstance->State != IP4_STATE_CONFIGED) {\r | |
2364 | Status = EFI_NOT_STARTED;\r | |
2365 | goto ON_EXIT;\r | |
2366 | }\r | |
2367 | \r | |
2368 | if (IpInstance->ConfigData.UseDefaultAddress && IP4_NO_MAPPING (IpInstance)) {\r | |
2369 | Status = EFI_NO_MAPPING;\r | |
2370 | goto ON_EXIT;\r | |
2371 | }\r | |
2372 | \r | |
2373 | Status = Ip4Cancel (IpInstance, Token);\r | |
2374 | \r | |
2375 | ON_EXIT:\r | |
e48e37fc | 2376 | gBS->RestoreTPL (OldTpl);\r |
772db4bb | 2377 | return Status;\r |
2378 | }\r | |
2379 | \r | |
2380 | \r | |
2381 | /**\r | |
5405e9a6 | 2382 | Polls for incoming data packets and processes outgoing data packets.\r |
2383 | \r | |
2384 | The Poll() function polls for incoming data packets and processes outgoing data\r | |
2385 | packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll()\r | |
2386 | function to increase the rate that data packets are moved between the communications\r | |
2387 | device and the transmit and receive queues.\r | |
2388 | \r | |
2389 | In some systems the periodic timer event may not poll the underlying communications\r | |
2390 | device fast enough to transmit and/or receive all data packets without missing\r | |
2391 | incoming packets or dropping outgoing packets. Drivers and applications that are\r | |
2392 | experiencing packet loss should try calling the EFI_IP4_PROTOCOL.Poll() function\r | |
2393 | more often.\r | |
2394 | \r | |
2395 | @param This Pointer to the EFI_IP4_PROTOCOL instance.\r | |
2396 | \r | |
2397 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
2398 | @retval EFI_NOT_STARTED This EFI IPv4 Protocol instance has not been started.\r | |
2399 | @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,\r | |
2400 | RARP, etc.) is not finished yet.\r | |
2401 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
2402 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
2403 | @retval EFI_NOT_READY No incoming or outgoing data is processed.\r | |
2404 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.\r | |
2405 | Consider increasing the polling rate.\r | |
772db4bb | 2406 | \r |
2407 | **/\r | |
772db4bb | 2408 | EFI_STATUS\r |
2409 | EFIAPI\r | |
2410 | EfiIp4Poll (\r | |
2411 | IN EFI_IP4_PROTOCOL *This\r | |
2412 | )\r | |
2413 | {\r | |
2414 | IP4_PROTOCOL *IpInstance;\r | |
2415 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
2416 | \r | |
2417 | if (This == NULL) {\r | |
2418 | return EFI_INVALID_PARAMETER;\r | |
2419 | }\r | |
2420 | \r | |
2421 | IpInstance = IP4_INSTANCE_FROM_PROTOCOL (This);\r | |
2422 | \r | |
2423 | if (IpInstance->State == IP4_STATE_UNCONFIGED) {\r | |
2424 | return EFI_NOT_STARTED;\r | |
2425 | }\r | |
2426 | \r | |
2427 | Mnp = IpInstance->Service->Mnp;\r | |
2428 | \r | |
2429 | //\r | |
2430 | // Don't lock the Poll function to enable the deliver of\r | |
2431 | // the packet polled up.\r | |
2432 | //\r | |
2433 | return Mnp->Poll (Mnp);\r | |
2434 | }\r | |
2435 | \r | |
772db4bb | 2436 | /**\r |
2437 | Decrease the life of the transmitted packets. If it is\r | |
2438 | decreased to zero, cancel the packet. This function is\r | |
96e1079f | 2439 | called by Ip4PacketTimerTicking which time out both the\r |
772db4bb | 2440 | received-but-not-delivered and transmitted-but-not-recycle\r |
2441 | packets.\r | |
2442 | \r | |
2443 | @param Map The IP4 child's transmit map.\r | |
2444 | @param Item Current transmitted packet\r | |
2445 | @param Context Not used.\r | |
2446 | \r | |
2447 | @retval EFI_SUCCESS Always returns EFI_SUCCESS\r | |
2448 | \r | |
2449 | **/\r | |
2450 | EFI_STATUS\r | |
2451 | Ip4SentPacketTicking (\r | |
2452 | IN NET_MAP *Map,\r | |
2453 | IN NET_MAP_ITEM *Item,\r | |
2454 | IN VOID *Context\r | |
2455 | )\r | |
2456 | {\r | |
2457 | IP4_TXTOKEN_WRAP *Wrap;\r | |
2458 | \r | |
2459 | Wrap = (IP4_TXTOKEN_WRAP *) Item->Value;\r | |
2460 | ASSERT (Wrap != NULL);\r | |
2461 | \r | |
2462 | if ((Wrap->Life > 0) && (--Wrap->Life == 0)) {\r | |
2463 | Ip4CancelPacket (Wrap->IpInstance->Interface, Wrap->Packet, EFI_ABORTED);\r | |
2464 | }\r | |
2465 | \r | |
2466 | return EFI_SUCCESS;\r | |
2467 | }\r | |
2468 | \r | |
2469 | \r | |
2470 | /**\r | |
2471 | The heart beat timer of IP4 service instance. It times out\r | |
2472 | all of its IP4 children's received-but-not-delivered and\r | |
2473 | transmitted-but-not-recycle packets, and provides time input\r | |
2474 | for its IGMP protocol.\r | |
2475 | \r | |
2476 | @param Event The IP4 service instance's heart beat timer.\r | |
2477 | @param Context The IP4 service instance.\r | |
2478 | \r | |
2479 | @return None\r | |
2480 | \r | |
2481 | **/\r | |
2482 | VOID\r | |
2483 | EFIAPI\r | |
2484 | Ip4TimerTicking (\r | |
2485 | IN EFI_EVENT Event,\r | |
2486 | IN VOID *Context\r | |
2487 | )\r | |
2488 | {\r | |
2489 | IP4_SERVICE *IpSb;\r | |
2490 | \r | |
2491 | IpSb = (IP4_SERVICE *) Context;\r | |
2492 | NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r | |
2493 | \r | |
2494 | Ip4PacketTimerTicking (IpSb);\r | |
2495 | Ip4IgmpTicking (IpSb);\r | |
2496 | }\r |