]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Main.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Main.c
CommitLineData
8a67d61d 1/** @file\r
dfc1f033 2 Implementation of TCP4 protocol services.\r
8a67d61d 3\r
01b5ac88 4Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
8a67d61d 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
dfc1f033 8http://opensource.org/licenses/bsd-license.php<BR>\r
8a67d61d 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
8a67d61d 13**/\r
14\r
dfc1f033 15\r
8a67d61d 16#include "Tcp4Main.h"\r
17\r
18\r
19/**\r
20 Check the integrity of the data buffer.\r
21\r
22 @param DataLen The total length of the data buffer.\r
23 @param FragmentCount The fragment count of the fragment table.\r
24 @param FragmentTable Pointer to the fragment table of the data\r
25 buffer.\r
26\r
27 @retval EFI_SUCCESS The integrity check is passed.\r
28 @retval EFI_INVALID_PARAMETER The integrity check is failed.\r
29\r
30**/\r
8a67d61d 31EFI_STATUS\r
32Tcp4ChkDataBuf (\r
33 IN UINT32 DataLen,\r
34 IN UINT32 FragmentCount,\r
35 IN EFI_TCP4_FRAGMENT_DATA *FragmentTable\r
36 )\r
37{\r
38 UINT32 Index;\r
39\r
40 UINT32 Len;\r
41\r
42 for (Index = 0, Len = 0; Index < FragmentCount; Index++) {\r
4eb65aff 43 Len = Len + (UINT32) FragmentTable[Index].FragmentLength;\r
8a67d61d 44 }\r
45\r
46 if (DataLen != Len) {\r
47 return EFI_INVALID_PARAMETER;\r
48 }\r
49\r
50 return EFI_SUCCESS;\r
51}\r
52\r
53\r
54/**\r
55 Get the current operational status.\r
85511ddf 56 \r
57 The GetModeData() function copies the current operational settings of this \r
58 EFI TCPv4 Protocol instance into user-supplied buffers. This function can \r
59 also be used to retrieve the operational setting of underlying drivers \r
60 such as IPv4, MNP, or SNP.\r
8a67d61d 61\r
62 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
63 @param Tcp4State Pointer to the buffer to receive the current TCP\r
64 state.\r
65 @param Tcp4ConfigData Pointer to the buffer to receive the current TCP\r
66 configuration.\r
85511ddf 67 @param Ip4ModeData Pointer to the buffer to receive the current IPv4 \r
68 configuration data used by the TCPv4 instance.\r
8a67d61d 69 @param MnpConfigData Pointer to the buffer to receive the current MNP\r
70 configuration data indirectly used by the TCPv4\r
71 Instance.\r
72 @param SnpModeData Pointer to the buffer to receive the current SNP\r
73 configuration data indirectly used by the TCPv4\r
74 Instance.\r
75\r
76 @retval EFI_SUCCESS The mode data was read.\r
77 @retval EFI_NOT_STARTED No configuration data is available because this\r
78 instance hasn't been started.\r
79 @retval EFI_INVALID_PARAMETER This is NULL.\r
80\r
81**/\r
82EFI_STATUS\r
83EFIAPI\r
84Tcp4GetModeData (\r
db0f0d3c 85 IN EFI_TCP4_PROTOCOL *This,\r
86 OUT EFI_TCP4_CONNECTION_STATE *Tcp4State OPTIONAL,\r
87 OUT EFI_TCP4_CONFIG_DATA *Tcp4ConfigData OPTIONAL,\r
88 OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,\r
89 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,\r
90 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
8a67d61d 91 )\r
92{\r
93 TCP4_MODE_DATA TcpMode;\r
94 SOCKET *Sock;\r
95\r
96 if (NULL == This) {\r
97 return EFI_INVALID_PARAMETER;\r
98 }\r
99\r
100 Sock = SOCK_FROM_THIS (This);\r
101\r
102 TcpMode.Tcp4State = Tcp4State;\r
103 TcpMode.Tcp4ConfigData = Tcp4ConfigData;\r
104 TcpMode.Ip4ModeData = Ip4ModeData;\r
105 TcpMode.MnpConfigData = MnpConfigData;\r
106 TcpMode.SnpModeData = SnpModeData;\r
107\r
108 return SockGetMode (Sock, &TcpMode);\r
109}\r
110\r
111\r
112/**\r
113 Initialize or brutally reset the operational parameters for\r
114 this EFI TCPv4 instance.\r
85511ddf 115 \r
116 The Configure() function does the following:\r
117 * Initialize this EFI TCPv4 instance, i.e., initialize the communication end \r
118 setting, specify active open or passive open for an instance.\r
119 * Reset this TCPv4 instance brutally, i.e., cancel all pending asynchronous \r
120 tokens, flush transmission and receiving buffer directly without informing \r
121 the communication peer.\r
122 No other TCPv4 Protocol operation can be executed by this instance \r
123 until it is configured properly. For an active TCP4 instance, after a proper \r
124 configuration it may call Connect() to initiates the three-way handshake. \r
125 For a passive TCP4 instance, its state will transit to Tcp4StateListen after \r
126 configuration, and Accept() may be called to listen the incoming TCP connection \r
127 request. If TcpConfigData is set to NULL, the instance is reset. Resetting \r
128 process will be done brutally, the state machine will be set to Tcp4StateClosed \r
129 directly, the receive queue and transmit queue will be flushed, and no traffic is \r
130 allowed through this instance.\r
8a67d61d 131\r
132 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
133 @param TcpConfigData Pointer to the configure data to configure the\r
134 instance.\r
135\r
136 @retval EFI_SUCCESS The operational settings are set, changed, or\r
137 reset successfully.\r
138 @retval EFI_NO_MAPPING When using a default address, configuration\r
139 (through DHCP, BOOTP, RARP, etc.) is not\r
140 finished.\r
141 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
142 @retval EFI_ACCESS_DENIED Configuring TCP instance when it is already\r
143 configured.\r
144 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
145 @retval EFI_UNSUPPORTED One or more of the control options are not\r
146 supported in the implementation.\r
147 @retval EFI_OUT_OF_RESOURCES Could not allocate enough system resources.\r
148\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
152Tcp4Configure (\r
85511ddf 153 IN EFI_TCP4_PROTOCOL *This,\r
154 IN EFI_TCP4_CONFIG_DATA *TcpConfigData OPTIONAL\r
8a67d61d 155 )\r
156{\r
157 EFI_TCP4_OPTION *Option;\r
158 SOCKET *Sock;\r
159 EFI_STATUS Status;\r
772db4bb 160 IP4_ADDR Ip;\r
687a2e5f 161 IP4_ADDR SubnetMask;\r
8a67d61d 162\r
163 if (NULL == This) {\r
164 return EFI_INVALID_PARAMETER;\r
165 }\r
166\r
167 //\r
168 // Tcp protocol related parameter check will be conducted here\r
169 //\r
170 if (NULL != TcpConfigData) {\r
772db4bb 171\r
e48e37fc 172 CopyMem (&Ip, &TcpConfigData->AccessPoint.RemoteAddress, sizeof (IP4_ADDR));\r
01b5ac88 173 if (IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
772db4bb 174 return EFI_INVALID_PARAMETER;\r
175 }\r
176\r
177 if (TcpConfigData->AccessPoint.ActiveFlag &&\r
178 (0 == TcpConfigData->AccessPoint.RemotePort || (Ip == 0))) {\r
8a67d61d 179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 if (!TcpConfigData->AccessPoint.UseDefaultAddress) {\r
772db4bb 183\r
e48e37fc 184 CopyMem (&Ip, &TcpConfigData->AccessPoint.StationAddress, sizeof (IP4_ADDR));\r
185 CopyMem (&SubnetMask, &TcpConfigData->AccessPoint.SubnetMask, sizeof (IP4_ADDR));\r
01b5ac88 186 if (!IP4_IS_VALID_NETMASK (NTOHL (SubnetMask)) || !NetIp4IsUnicast (NTOHL (Ip), NTOHL (SubnetMask))) {\r
8a67d61d 187 return EFI_INVALID_PARAMETER;\r
188 }\r
189 }\r
190\r
8a67d61d 191 Option = TcpConfigData->ControlOption;\r
192 if ((NULL != Option) &&\r
193 (Option->EnableSelectiveAck || Option->EnablePathMtuDiscovery)) {\r
194 return EFI_UNSUPPORTED;\r
195 }\r
196 }\r
197\r
198 Sock = SOCK_FROM_THIS (This);\r
199\r
200 if (NULL == TcpConfigData) {\r
201 return SockFlush (Sock);\r
202 }\r
203\r
204 Status = SockConfigure (Sock, TcpConfigData);\r
205\r
206 if (EFI_NO_MAPPING == Status) {\r
207 Sock->ConfigureState = SO_NO_MAPPING;\r
208 }\r
209\r
210 return Status;\r
211}\r
212\r
213\r
214/**\r
215 Add or delete routing entries.\r
85511ddf 216 \r
dfc1f033 217 The Routes() function adds or deletes a route from the instance's routing table.\r
85511ddf 218 The most specific route is selected by comparing the SubnetAddress with the \r
dfc1f033 219 destination IP address's arithmetical AND to the SubnetMask.\r
85511ddf 220 The default route is added with both SubnetAddress and SubnetMask set to 0.0.0.0. \r
221 The default route matches all destination IP addresses if there is no more specific route.\r
222 Direct route is added with GatewayAddress set to 0.0.0.0. Packets are sent to \r
223 the destination host if its address can be found in the Address Resolution Protocol (ARP) \r
224 cache or it is on the local subnet. If the instance is configured to use default \r
225 address, a direct route to the local network will be added automatically.\r
226 Each TCP instance has its own independent routing table. Instance that uses the \r
dfc1f033 227 default IP address will have a copy of the EFI_IP4_CONFIG_PROTOCOL's routing table. \r
85511ddf 228 The copy will be updated automatically whenever the IP driver reconfigures its \r
dfc1f033 229 instance. As a result, the previous modification to the instance's local copy \r
85511ddf 230 will be lost. The priority of checking the route table is specific with IP \r
231 implementation and every IP implementation must comply with RFC 1122.\r
8a67d61d 232\r
233 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
234 @param DeleteRoute If TRUE, delete the specified route from routing\r
235 table; if FALSE, add the specified route to\r
236 routing table.\r
85511ddf 237 DestinationAddress and SubnetMask are used as \r
238 the keywords to search route entry.\r
8a67d61d 239 @param SubnetAddress The destination network.\r
240 @param SubnetMask The subnet mask for the destination network.\r
85511ddf 241 @param GatewayAddress The gateway address for this route. \r
242 It must be on the same subnet with the station \r
243 address unless a direct route is specified.\r
244 \r
8a67d61d 245 @retval EFI_SUCCESS The operation completed successfully.\r
246 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance has not been\r
247 configured.\r
248 @retval EFI_NO_MAPPING When using a default address, configuration\r
249 (through DHCP, BOOTP, RARP, etc.) is not\r
250 finished.\r
251 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
252 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to add the\r
253 entry to the routing table.\r
254 @retval EFI_NOT_FOUND This route is not in the routing table.\r
255 @retval EFI_ACCESS_DENIED This route is already in the routing table.\r
256 @retval EFI_UNSUPPORTED The TCP driver does not support this operation.\r
257\r
258**/\r
259EFI_STATUS\r
260EFIAPI\r
261Tcp4Routes (\r
262 IN EFI_TCP4_PROTOCOL *This,\r
263 IN BOOLEAN DeleteRoute,\r
264 IN EFI_IPv4_ADDRESS *SubnetAddress,\r
265 IN EFI_IPv4_ADDRESS *SubnetMask,\r
266 IN EFI_IPv4_ADDRESS *GatewayAddress\r
267 )\r
268{\r
269 SOCKET *Sock;\r
270 TCP4_ROUTE_INFO RouteInfo;\r
271\r
272 if (NULL == This) {\r
273 return EFI_INVALID_PARAMETER;\r
274 }\r
275\r
276 Sock = SOCK_FROM_THIS (This);\r
277\r
278 RouteInfo.DeleteRoute = DeleteRoute;\r
279 RouteInfo.SubnetAddress = SubnetAddress;\r
280 RouteInfo.SubnetMask = SubnetMask;\r
281 RouteInfo.GatewayAddress = GatewayAddress;\r
282\r
283 return SockRoute (Sock, &RouteInfo);\r
284}\r
285\r
286\r
287/**\r
288 Initiate a nonblocking TCP connection request for an active TCP instance.\r
289\r
85511ddf 290 The Connect() function will initiate an active open to the remote peer configured \r
291 in current TCP instance if it is configured active. If the connection succeeds \r
292 or fails due to any error, the ConnectionToken->CompletionToken.Event will be \r
293 signaled and ConnectionToken->CompletionToken.Status will be updated accordingly. \r
294 This function can only be called for the TCP instance in Tcp4StateClosed state. \r
295 The instance will transfer into Tcp4StateSynSent if the function returns EFI_SUCCESS. \r
296 If TCP three way handshake succeeds, its state will become Tcp4StateEstablished, \r
297 otherwise, the state will return to Tcp4StateClosed.\r
298 \r
8a67d61d 299 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
300 @param ConnectionToken Pointer to the connection token to return when\r
301 the TCP three way handshake finishes.\r
302\r
85511ddf 303 @retval EFI_SUCCESS The connection request is successfully initiated \r
304 and the state of this TCPv4 instance has \r
305 been changed to Tcp4StateSynSent.\r
8a67d61d 306 @retval EFI_NOT_STARTED This EFI_TCP4_PROTOCOL instance hasn't been\r
307 configured.\r
308 @retval EFI_ACCESS_DENIED The instance is not configured as an active one\r
309 or it is not in Tcp4StateClosed state.\r
310 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
311 @retval EFI_OUT_OF_RESOURCES The driver can't allocate enough resource to\r
312 initiate the active open.\r
313 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
314\r
315**/\r
316EFI_STATUS\r
317EFIAPI\r
318Tcp4Connect (\r
319 IN EFI_TCP4_PROTOCOL *This,\r
320 IN EFI_TCP4_CONNECTION_TOKEN *ConnectionToken\r
321 )\r
322{\r
323 SOCKET *Sock;\r
324\r
325 if (NULL == This ||\r
326 NULL == ConnectionToken ||\r
327 NULL == ConnectionToken->CompletionToken.Event) {\r
328 return EFI_INVALID_PARAMETER;\r
329 }\r
330\r
331 Sock = SOCK_FROM_THIS (This);\r
332\r
333 return SockConnect (Sock, ConnectionToken);\r
334}\r
335\r
336\r
337/**\r
338 Listen on the passive instance to accept an incoming connection request.\r
339\r
85511ddf 340 The Accept() function initiates an asynchronous accept request to wait for an \r
341 incoming connection on the passive TCP instance. If a remote peer successfully \r
342 establishes a connection with this instance, a new TCP instance will be created \r
343 and its handle will be returned in ListenToken->NewChildHandle. The newly created \r
dfc1f033 344 instance is configured by inheriting the passive instance's configuration and is \r
85511ddf 345 ready for use upon return. The instance is in the Tcp4StateEstablished state.\r
346 The ListenToken->CompletionToken.Event will be signaled when a new connection \r
347 is accepted, user aborts the listen or connection is reset. This function only \r
348 can be called when current TCP instance is in Tcp4StateListen state.\r
349\r
8a67d61d 350 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
351 @param ListenToken Pointer to the listen token to return when\r
352 operation finishes.\r
353\r
354 @retval EFI_SUCCESS The listen token has been queued successfully.\r
355 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
356 configured.\r
357 @retval EFI_ACCESS_DENIED The instatnce is not a passive one or it is not\r
358 in Tcp4StateListen state or a same listen token\r
359 has already existed in the listen token queue of\r
360 this TCP instance.\r
361 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
362 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resources to finish\r
363 the operation.\r
85511ddf 364 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above category error.\r
8a67d61d 365\r
366**/\r
367EFI_STATUS\r
368EFIAPI\r
369Tcp4Accept (\r
370 IN EFI_TCP4_PROTOCOL *This,\r
371 IN EFI_TCP4_LISTEN_TOKEN *ListenToken\r
372 )\r
373{\r
374 SOCKET *Sock;\r
375\r
376 if (NULL == This ||\r
377 NULL == ListenToken ||\r
378 NULL == ListenToken->CompletionToken.Event) {\r
379 return EFI_INVALID_PARAMETER;\r
380 }\r
381\r
382 Sock = SOCK_FROM_THIS (This);\r
383\r
384 return SockAccept (Sock, ListenToken);\r
385}\r
386\r
387\r
388/**\r
120db52c 389 Queues outgoing data into the transmit queue.\r
8a67d61d 390\r
85511ddf 391 The Transmit() function queues a sending request to this TCPv4 instance along \r
392 with the user data. The status of the token is updated and the event in the token \r
393 will be signaled once the data is sent out or some error occurs.\r
394\r
8a67d61d 395 @param This Pointer to the EFI_TCP4_PROTOCOL instance\r
396 @param Token Pointer to the completion token to queue to the\r
397 transmit queue\r
398\r
120db52c 399 @retval EFI_SUCCESS The data has been queued for transmission.\r
8a67d61d 400 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
401 configured.\r
402 @retval EFI_NO_MAPPING When using a default address, configuration\r
403 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
120db52c 404 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
8a67d61d 405 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
406 * A transmit completion token with the same\r
85511ddf 407 Token-> CompletionToken.Event was already in the\r
408 transmission queue. \r
409 * The current instance is in Tcp4StateClosed state \r
410 * The current instance is a passive one and \r
411 it is in Tcp4StateListen state. \r
412 * User has called Close() to disconnect this \r
413 connection.\r
8a67d61d 414 @retval EFI_NOT_READY The completion token could not be queued because\r
415 the transmit queue is full.\r
416 @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data because of\r
417 resource shortage.\r
418 @retval EFI_NETWORK_UNREACHABLE There is no route to the destination network or\r
419 address.\r
420\r
421**/\r
422EFI_STATUS\r
423EFIAPI\r
424Tcp4Transmit (\r
425 IN EFI_TCP4_PROTOCOL *This,\r
426 IN EFI_TCP4_IO_TOKEN *Token\r
427 )\r
428{\r
429 SOCKET *Sock;\r
430 EFI_STATUS Status;\r
431\r
432 if (NULL == This ||\r
433 NULL == Token ||\r
434 NULL == Token->CompletionToken.Event ||\r
435 NULL == Token->Packet.TxData ||\r
436 0 == Token->Packet.TxData->FragmentCount ||\r
437 0 == Token->Packet.TxData->DataLength\r
438 ) {\r
439 return EFI_INVALID_PARAMETER;\r
440 }\r
441\r
442 Status = Tcp4ChkDataBuf (\r
4eb65aff 443 (UINT32) Token->Packet.TxData->DataLength,\r
444 (UINT32) Token->Packet.TxData->FragmentCount,\r
8a67d61d 445 Token->Packet.TxData->FragmentTable\r
446 );\r
447 if (EFI_ERROR (Status)) {\r
448 return Status;\r
449 }\r
450\r
451 Sock = SOCK_FROM_THIS (This);\r
452\r
453 return SockSend (Sock, Token);\r
454\r
455}\r
456\r
457\r
458/**\r
459 Place an asynchronous receive request into the receiving queue.\r
460\r
85511ddf 461 The Receive() function places a completion token into the receive packet queue. \r
462 This function is always asynchronous. The caller must allocate the \r
463 Token->CompletionToken.Event and the FragmentBuffer used to receive data. He also \r
464 must fill the DataLength which represents the whole length of all FragmentBuffer. \r
465 When the receive operation completes, the EFI TCPv4 Protocol driver updates the \r
466 Token->CompletionToken.Status and Token->Packet.RxData fields and the \r
467 Token->CompletionToken.Event is signaled. If got data the data and its length \r
468 will be copy into the FragmentTable, in the same time the full length of received \r
469 data will be recorded in the DataLength fields. Providing a proper notification \r
470 function and context for the event will enable the user to receive the notification \r
471 and receiving status. That notification function is guaranteed to not be re-entered.\r
472\r
8a67d61d 473 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
474 @param Token Pointer to a token that is associated with the\r
475 receive data descriptor.\r
476\r
120db52c 477 @retval EFI_SUCCESS The receive completion token was cached.\r
8a67d61d 478 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
479 configured.\r
480 @retval EFI_NO_MAPPING When using a default address, configuration\r
481 (DHCP, BOOTP, RARP, etc.) is not finished yet.\r
482 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
483 @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued\r
484 due to a lack of system resources.\r
485 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
85511ddf 486 The EFI TCPv4 Protocol instance has been reset \r
487 to startup defaults.\r
8a67d61d 488 @retval EFI_ACCESS_DENIED One or more of the following conditions is TRUE:\r
489 * A receive completion token with the same\r
85511ddf 490 Token->CompletionToken.Event was already in \r
491 the receive queue. \r
492 * The current instance is in Tcp4StateClosed state. \r
493 * The current instance is a passive one and it \r
494 is in Tcp4StateListen state. \r
495 * User has called Close() to disconnect this \r
496 connection.\r
8a67d61d 497 @retval EFI_CONNECTION_FIN The communication peer has closed the connection\r
498 and there is no any buffered data in the receive\r
499 buffer of this instance.\r
500 @retval EFI_NOT_READY The receive request could not be queued because\r
501 the receive queue is full.\r
502\r
503**/\r
504EFI_STATUS\r
505EFIAPI\r
506Tcp4Receive (\r
507 IN EFI_TCP4_PROTOCOL *This,\r
508 IN EFI_TCP4_IO_TOKEN *Token\r
509 )\r
510{\r
511 SOCKET *Sock;\r
512 EFI_STATUS Status;\r
513\r
514 if (NULL == This ||\r
515 NULL == Token ||\r
516 NULL == Token->CompletionToken.Event ||\r
517 NULL == Token->Packet.RxData ||\r
518 0 == Token->Packet.RxData->FragmentCount ||\r
519 0 == Token->Packet.RxData->DataLength\r
520 ) {\r
521 return EFI_INVALID_PARAMETER;\r
522 }\r
523\r
524 Status = Tcp4ChkDataBuf (\r
4eb65aff 525 (UINT32) Token->Packet.RxData->DataLength,\r
526 (UINT32) Token->Packet.RxData->FragmentCount,\r
8a67d61d 527 Token->Packet.RxData->FragmentTable\r
528 );\r
529 if (EFI_ERROR (Status)) {\r
530 return Status;\r
531 }\r
532\r
533 Sock = SOCK_FROM_THIS (This);\r
534\r
535 return SockRcv (Sock, Token);\r
536\r
537}\r
538\r
539\r
540/**\r
541 Disconnecting a TCP connection gracefully or reset a TCP connection.\r
542\r
85511ddf 543 Initiate an asynchronous close token to TCP driver. After Close() is called, \r
544 any buffered transmission data will be sent by TCP driver and the current \r
545 instance will have a graceful close working flow described as RFC 793 if \r
546 AbortOnClose is set to FALSE, otherwise, a rest packet will be sent by TCP \r
547 driver to fast disconnect this connection. When the close operation completes \r
548 successfully the TCP instance is in Tcp4StateClosed state, all pending \r
549 asynchronous operation is signaled and any buffers used for TCP network traffic \r
550 is flushed.\r
551\r
120db52c 552 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
8a67d61d 553 @param CloseToken Pointer to the close token to return when\r
554 operation finishes.\r
555\r
120db52c 556 @retval EFI_SUCCESS The operation completed successfully.\r
8a67d61d 557 @retval EFI_NOT_STARTED The EFI_TCP4_PROTOCOL instance hasn't been\r
558 configured.\r
85511ddf 559 @retval EFI_ACCESS_DENIED One or more of the following are TRUE: \r
560 * Configure() has been called with TcpConfigData\r
561 set to NULL and this function has not returned.\r
8a67d61d 562 * Previous Close() call on this instance has not\r
85511ddf 563 finished.\r
120db52c 564 @retval EFI_INVALID_PARAMETER One ore more parameters are invalid.\r
8a67d61d 565 @retval EFI_OUT_OF_RESOURCES Could not allocate enough resource to finish the\r
120db52c 566 operation.\r
8a67d61d 567 @retval EFI_DEVICE_ERROR Any unexpected and not belonged to above\r
568 category error.\r
569\r
570**/\r
571EFI_STATUS\r
572EFIAPI\r
573Tcp4Close (\r
574 IN EFI_TCP4_PROTOCOL *This,\r
575 IN EFI_TCP4_CLOSE_TOKEN *CloseToken\r
576 )\r
577{\r
578 SOCKET *Sock;\r
579\r
580 if (NULL == This ||\r
581 NULL == CloseToken ||\r
582 NULL == CloseToken->CompletionToken.Event) {\r
583 return EFI_INVALID_PARAMETER;\r
584 }\r
585\r
586 Sock = SOCK_FROM_THIS (This);\r
587\r
588 return SockClose (Sock, CloseToken, CloseToken->AbortOnClose);\r
589}\r
590\r
591\r
592/**\r
593 Abort an asynchronous connection, listen, transmission or receive request.\r
594\r
85511ddf 595 The Cancel() function aborts a pending connection, listen, transmit or receive \r
596 request. If Token is not NULL and the token is in the connection, listen, \r
597 transmission or receive queue when it is being cancelled, its Token->Status \r
598 will be set to EFI_ABORTED and then Token->Event will be signaled. If the token \r
599 is not in one of the queues, which usually means that the asynchronous operation \r
600 has completed, EFI_NOT_FOUND is returned. If Token is NULL all asynchronous token \r
601 issued by Connect(), Accept(), Transmit() and Receive()will be aborted.\r
120db52c 602 NOTE: It has not been implemented currently.\r
603 \r
8a67d61d 604 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
605 @param Token Pointer to a token that has been issued by\r
606 Connect(), Accept(), Transmit() or Receive(). If\r
607 NULL, all pending tokens issued by above four\r
608 functions will be aborted.\r
85511ddf 609 \r
610 @retval EFI_SUCCESS The asynchronous I/O request is aborted and Token->Event\r
611 is signaled.\r
612 @retval EFI_INVALID_PARAMETER This is NULL.\r
dfc1f033 613 @retval EFI_NOT_STARTED This instance hasn's been configured.\r
85511ddf 614 @retval EFI_NO_MAPPING When using the default address, configuration\r
dfc1f033 615 (DHCP, BOOTP,RARP, etc.) hasn's finished yet.\r
616 @retval EFI_NOT_FOUND The asynchronous I/O request isn's found in the \r
85511ddf 617 transmission or receive queue. It has either \r
dfc1f033 618 completed or wasn's issued by Transmit() and Receive().\r
85511ddf 619 @retval EFI_UNSUPPORTED The operation is not supported in current\r
8a67d61d 620 implementation.\r
120db52c 621 \r
8a67d61d 622**/\r
623EFI_STATUS\r
624EFIAPI\r
625Tcp4Cancel (\r
85511ddf 626 IN EFI_TCP4_PROTOCOL *This,\r
627 IN EFI_TCP4_COMPLETION_TOKEN *Token OPTIONAL\r
8a67d61d 628 )\r
629{\r
630 return EFI_UNSUPPORTED;\r
631}\r
632\r
633\r
634/**\r
635 Poll to receive incoming data and transmit outgoing segments.\r
636\r
85511ddf 637 The Poll() function increases the rate that data is moved between the network \r
638 and application and can be called when the TCP instance is created successfully. \r
639 Its use is optional. In some implementations, the periodical timer in the MNP \r
640 driver may not poll the underlying communications device fast enough to avoid \r
641 drop packets. Drivers and applications that are experiencing packet loss should \r
642 try calling the Poll() function in a high frequency.\r
643\r
8a67d61d 644 @param This Pointer to the EFI_TCP4_PROTOCOL instance.\r
645\r
646 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
647 @retval EFI_INVALID_PARAMETER This is NULL.\r
648 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
649 @retval EFI_NOT_READY No incoming or outgoing data was processed.\r
650 @retval EFI_TIMEOUT Data was dropped out of the transmission or\r
651 receive queue. Consider increasing the polling\r
652 rate.\r
653\r
654**/\r
655EFI_STATUS\r
656EFIAPI\r
657Tcp4Poll (\r
658 IN EFI_TCP4_PROTOCOL *This\r
659 )\r
660{\r
661 SOCKET *Sock;\r
662 EFI_STATUS Status;\r
663\r
664 if (NULL == This) {\r
665 return EFI_INVALID_PARAMETER;\r
666 }\r
667\r
668 Sock = SOCK_FROM_THIS (This);\r
669\r
670 Status = Sock->ProtoHandler (Sock, SOCK_POLL, NULL);\r
671\r
672 return Status;\r
673}\r