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