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