]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/EfiSocketLib/Tcp6.c
Eliminate duplicated file GUID.
[mirror_edk2.git] / StdLib / EfiSocketLib / Tcp6.c
CommitLineData
3bdf9aae 1/** @file\r
2 Implement the TCP6 driver support for the socket layer.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13\r
14 \section ConnectionManagement Connection Management\r
15 \r
16 The ::EslTcp6Listen routine initially places the SOCK_STREAM or\r
17 SOCK_SEQPACKET socket into a listen state. When a remote machine\r
18 makes a connection to the socket, the TCPv6 network layer calls\r
19 ::EslTcp6ListenComplete to complete the connection processing.\r
20 EslTcp6ListenComplete manages the connections by placing them in\r
21 FIFO order in a queue to be serviced by the application. When the\r
22 number of connections exceeds the backlog (ESL_SOCKET::MaxFifoDepth),\r
23 the new connection is closed. Eventually, the application indirectly\r
24 calls ::EslTcp6Accept to remove the next connection from the queue\r
25 and get the associated socket.\r
26\r
27**/\r
28\r
29#include "Socket.h"\r
30\r
31\r
32/**\r
33 Attempt to connect to a remote TCP port\r
34\r
35 This routine starts the connection processing for a SOCK_STREAM\r
36 or SOCK_SEQPAKCET socket using the TCPv6 network layer. It\r
37 configures the local TCPv6 connection point and then attempts to\r
38 connect to a remote system. Upon completion, the\r
39 ::EslTcp6ConnectComplete routine gets called with the connection\r
40 status.\r
41\r
42 This routine is called by ::EslSocketConnect to initiate the TCPv6\r
43 network specific connect operations. The connection processing is\r
44 initiated by this routine and finished by ::EslTcp6ConnectComplete.\r
45 This pair of routines walks through the list of local TCPv6\r
46 connection points until a connection to the remote system is\r
47 made.\r
48\r
49 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
50\r
51 @retval EFI_SUCCESS The connection was successfully established.\r
52 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
53 @retval Others The connection attempt failed.\r
54\r
55 **/\r
56EFI_STATUS\r
57EslTcp6ConnectStart (\r
58 IN ESL_SOCKET * pSocket\r
59 );\r
60\r
61\r
62/**\r
63 Process the connection attempt\r
64\r
65 A system has initiated a connection attempt with a socket in the\r
66 listen state. Attempt to complete the connection.\r
67\r
68 The TCPv6 layer calls this routine when a connection is made to\r
69 the socket in the listen state. See the\r
70 \ref ConnectionManagement section.\r
71\r
72 @param [in] Event The listen completion event\r
73\r
74 @param [in] pPort Address of an ::ESL_PORT structure.\r
75\r
76**/\r
77VOID\r
78EslTcp6ListenComplete (\r
79 IN EFI_EVENT Event,\r
80 IN ESL_PORT * pPort\r
81 );\r
82\r
83\r
84/**\r
85 Accept a network connection.\r
86\r
87 This routine waits for a network connection to the socket and\r
88 returns the remote network address to the caller if requested.\r
89\r
90 This routine is called by ::EslSocketAccept to handle the TCPv6 protocol\r
91 specific accept operations for SOCK_STREAM and SOCK_SEQPACKET sockets.\r
92 See the \ref ConnectionManagement section.\r
93\r
94 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
95\r
96 @param [in] pSockAddr Address of a buffer to receive the remote\r
97 network address.\r
98\r
99 @param [in, out] pSockAddrLength Length in bytes of the address buffer.\r
100 On output specifies the length of the\r
101 remote network address.\r
102\r
103 @retval EFI_SUCCESS Remote address is available\r
104 @retval Others Remote address not available\r
105\r
106 **/\r
107EFI_STATUS\r
108EslTcp6Accept (\r
109 IN ESL_SOCKET * pSocket,\r
110 IN struct sockaddr * pSockAddr,\r
111 IN OUT socklen_t * pSockAddrLength\r
112 )\r
113{\r
114 ESL_PORT * pPort;\r
115 struct sockaddr_in6 * pRemoteAddress;\r
116 ESL_TCP6_CONTEXT * pTcp6;\r
117 EFI_STATUS Status;\r
118\r
119 DBG_ENTER ( );\r
120\r
121 //\r
122 // Validate the socket length\r
123 //\r
124 pRemoteAddress = (struct sockaddr_in6 *) pSockAddr;\r
125 if (( NULL == pSockAddrLength )\r
126 || ( sizeof ( *pRemoteAddress ) > *pSockAddrLength )) {\r
127 //\r
128 // Invalid socket address\r
129 //\r
130 Status = EFI_INVALID_PARAMETER;\r
131 pSocket->errno = EINVAL;\r
132 DEBUG (( DEBUG_ACCEPT,\r
133 "ERROR - Invalid address length\r\n" ));\r
134 }\r
135 else {\r
136 //\r
137 // Assume success\r
138 //\r
139 Status = EFI_SUCCESS;\r
140\r
141 //\r
142 // Locate the address context\r
143 //\r
144 pPort = pSocket->pPortList;\r
145 pTcp6 = &pPort->Context.Tcp6;\r
146\r
147 //\r
148 // Fill-in the remote address structure\r
149 //\r
150 ZeroMem ( pRemoteAddress, sizeof ( *pRemoteAddress ));\r
151 pRemoteAddress->sin6_len = sizeof ( *pRemoteAddress );\r
152 pRemoteAddress->sin6_family = AF_INET6;\r
153 pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );\r
154 CopyMem ( &pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],\r
155 &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
156 sizeof ( pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr ));\r
157 }\r
158\r
159 //\r
160 // Return the operation status\r
161 //\r
162 DBG_EXIT_STATUS ( Status );\r
163 return Status;\r
164}\r
165\r
166\r
167/**\r
168 Process the remote connection completion event.\r
169\r
170 This routine handles the completion of a connection attempt. It\r
171 releases the port (TCPv6 adapter connection) in the case of an\r
172 error and start a connection attempt on the next port. If the\r
173 connection attempt was successful then this routine releases all\r
174 of the other ports.\r
175\r
176 This routine is called by the TCPv6 layer when a connect request\r
177 completes. It sets the ESL_SOCKET::bConnected flag to notify the\r
178 ::EslTcp6ConnectComplete routine that the connection is available.\r
179 The flag is set when the connection is established or no more ports\r
180 exist in the list. The connection status is passed via\r
181 ESL_SOCKET::ConnectStatus.\r
182\r
183 @param [in] Event The connect completion event\r
184\r
185 @param [in] pPort Address of an ::ESL_PORT structure.\r
186\r
187**/\r
188VOID\r
189EslTcp6ConnectComplete (\r
190 IN EFI_EVENT Event,\r
191 IN ESL_PORT * pPort\r
192 )\r
193{\r
194 BOOLEAN bRemoveFirstPort;\r
195 BOOLEAN bRemovePorts;\r
196 ESL_PORT * pNextPort;\r
197 ESL_SOCKET * pSocket;\r
198 ESL_TCP6_CONTEXT * pTcp6;\r
199 EFI_STATUS Status;\r
200\r
201 DBG_ENTER ( );\r
202\r
203 //\r
204 // Locate the TCP context\r
205 //\r
206 pSocket = pPort->pSocket;\r
207 pTcp6 = &pPort->Context.Tcp6;\r
208\r
209 //\r
210 // Get the connection status\r
211 //\r
212 bRemoveFirstPort = FALSE;\r
213 bRemovePorts = FALSE;\r
214 Status = pTcp6->ConnectToken.CompletionToken.Status;\r
215 pSocket->ConnectStatus = Status;\r
216 if ( !EFI_ERROR ( Status )) {\r
217 //\r
218 // The connection was successful\r
219 //\r
220 DEBUG (( DEBUG_CONNECT,\r
221 "0x%08x: Port connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
222 pPort,\r
223 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
224 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],\r
225 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],\r
226 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],\r
227 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],\r
228 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],\r
229 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],\r
230 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],\r
231 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],\r
232 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],\r
233 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],\r
234 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],\r
235 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],\r
236 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],\r
237 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],\r
238 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],\r
239 pTcp6->ConfigData.AccessPoint.RemotePort ));\r
240\r
ceecdc62 241 //\r
242 // Start the receive operations\r
243 //\r
244 pSocket->bConfigured = TRUE;\r
245 pSocket->State = SOCKET_STATE_CONNECTED;\r
246 EslSocketRxStart ( pPort );\r
247\r
3bdf9aae 248 //\r
249 // Remove the rest of the ports\r
250 //\r
251 bRemovePorts = TRUE;\r
252 }\r
253 else {\r
254 //\r
255 // The connection failed\r
256 //\r
44538ba5 257 if ( pPort->bConfigured ) {\r
258 DEBUG (( DEBUG_CONNECT,\r
259 "0x%08x: Port connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d failed, Status: %r\r\n",\r
260 pPort,\r
261 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
262 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],\r
263 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],\r
264 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],\r
265 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],\r
266 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],\r
267 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],\r
268 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],\r
269 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],\r
270 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],\r
271 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],\r
272 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],\r
273 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],\r
274 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],\r
275 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],\r
276 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],\r
277 pTcp6->ConfigData.AccessPoint.RemotePort,\r
278 Status ));\r
279 }\r
3bdf9aae 280\r
281 //\r
282 // Close the current port\r
283 //\r
284 Status = EslSocketPortClose ( pPort );\r
285 if ( !EFI_ERROR ( Status )) {\r
286 DEBUG (( DEBUG_CONNECT,\r
287 "0x%08x: Port closed\r\n",\r
288 pPort ));\r
289 }\r
290 else {\r
291 DEBUG (( DEBUG_CONNECT,\r
292 "ERROR - Failed to close port 0x%08x, Status: %r\r\n",\r
293 pPort,\r
294 Status ));\r
295 }\r
296\r
297 //\r
298 // Try to connect using the next port\r
299 //\r
300 Status = EslTcp6ConnectStart ( pSocket );\r
301 if ( EFI_NOT_READY != Status ) {\r
3bdf9aae 302 bRemoveFirstPort = TRUE;\r
303 }\r
304 }\r
305\r
306 //\r
307 // Remove the ports if necessary\r
308 //\r
309 if ( bRemoveFirstPort || bRemovePorts ) {\r
310 //\r
311 // Remove the first port if necessary\r
312 //\r
313 pPort = pSocket->pPortList;\r
314 if (( !bRemoveFirstPort ) && ( NULL != pPort )) {\r
315 pPort = pPort->pLinkSocket;\r
316 }\r
317\r
318 //\r
319 // Remove the rest of the list\r
320 //\r
321 while ( NULL != pPort ) {\r
322 pNextPort = pPort->pLinkSocket;\r
323 EslSocketPortClose ( pPort );\r
324 if ( !EFI_ERROR ( Status )) {\r
325 DEBUG (( DEBUG_CONNECT,\r
326 "0x%08x: Port closed\r\n",\r
327 pPort ));\r
328 }\r
329 else {\r
330 DEBUG (( DEBUG_CONNECT,\r
331 "ERROR - Failed to close port 0x%08x, Status: %r\r\n",\r
332 pPort,\r
333 Status ));\r
334 }\r
335 pPort = pNextPort;\r
336 }\r
337\r
338 //\r
339 // Notify the poll routine\r
340 //\r
341 pSocket->bConnected = TRUE;\r
342 }\r
343\r
344 DBG_EXIT ( );\r
345}\r
346\r
347\r
348/**\r
349 Poll for completion of the connection attempt.\r
350\r
351 This routine polls the ESL_SOCKET::bConnected flag to determine\r
352 when the connection attempt is complete.\r
353\r
354 This routine is called from ::EslSocketConnect to determine when\r
355 the connection is complete. The ESL_SOCKET::bConnected flag is\r
356 set by ::EslTcp6ConnectComplete when the TCPv6 layer establishes\r
357 a connection or runs out of local network adapters. This routine\r
358 gets the connection status from ESL_SOCKET::ConnectStatus.\r
359\r
360 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
361\r
362 @retval EFI_SUCCESS The connection was successfully established.\r
363 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
364 @retval Others The connection attempt failed.\r
365\r
366 **/\r
367EFI_STATUS\r
368EslTcp6ConnectPoll (\r
369 IN ESL_SOCKET * pSocket\r
370 )\r
371{\r
372 EFI_STATUS Status;\r
373\r
374 DBG_ENTER ( );\r
375\r
376 //\r
377 // Determine if the connection is complete\r
378 //\r
379 if ( !pSocket->bConnected ) {\r
380 //\r
381 // Not connected\r
382 //\r
383 pSocket->errno = EAGAIN;\r
384 Status = EFI_NOT_READY;\r
385 }\r
386 else {\r
387 //\r
388 // The connection processing is complete\r
389 //\r
390 pSocket->bConnected = FALSE;\r
391\r
392 //\r
393 // Translate the connection status\r
394 //\r
395 Status = pSocket->ConnectStatus;\r
396 switch ( Status ) {\r
44538ba5 397 default:\r
398 case EFI_DEVICE_ERROR:\r
399 pSocket->errno = EIO;\r
400 break;\r
401 \r
402 case EFI_ABORTED:\r
403 pSocket->errno = ECONNABORTED;\r
404 break;\r
405 \r
406 case EFI_ACCESS_DENIED:\r
407 pSocket->errno = EACCES;\r
408 break;\r
409 \r
410 case EFI_CONNECTION_RESET:\r
411 pSocket->errno = ECONNRESET;\r
412 break;\r
413 \r
414 case EFI_INVALID_PARAMETER:\r
415 pSocket->errno = EADDRNOTAVAIL;\r
416 break;\r
417 \r
418 case EFI_HOST_UNREACHABLE:\r
419 case EFI_NO_RESPONSE:\r
420 pSocket->errno = EHOSTUNREACH;\r
421 break;\r
422 \r
423 case EFI_NO_MAPPING:\r
424 pSocket->errno = EAFNOSUPPORT;\r
425 break;\r
426 \r
427 case EFI_NO_MEDIA:\r
428 case EFI_NETWORK_UNREACHABLE:\r
429 pSocket->errno = ENETDOWN;\r
430 break;\r
431 \r
432 case EFI_OUT_OF_RESOURCES:\r
433 pSocket->errno = ENOBUFS;\r
434 break;\r
435 \r
436 case EFI_PORT_UNREACHABLE:\r
437 case EFI_PROTOCOL_UNREACHABLE:\r
438 case EFI_CONNECTION_REFUSED:\r
439 pSocket->errno = ECONNREFUSED;\r
440 break;\r
441 \r
442 case EFI_SUCCESS:\r
443 pSocket->errno = 0;\r
44538ba5 444 break;\r
445 \r
446 case EFI_TIMEOUT:\r
447 pSocket->errno = ETIMEDOUT;\r
448 break;\r
449 \r
450 case EFI_UNSUPPORTED:\r
451 pSocket->errno = EOPNOTSUPP;\r
452 break;\r
3bdf9aae 453 }\r
44538ba5 454\r
455 //\r
456 // Display the translation\r
457 //\r
458 DEBUG (( DEBUG_CONNECT,\r
459 "ERROR - errno: %d, Status: %r\r\n",\r
460 pSocket->errno,\r
461 Status ));\r
3bdf9aae 462 }\r
463\r
464 //\r
465 // Return the initialization status\r
466 //\r
467 DBG_EXIT_STATUS ( Status );\r
468 return Status;\r
469}\r
470\r
471\r
472/**\r
473 Attempt to connect to a remote TCP port\r
474\r
475 This routine starts the connection processing for a SOCK_STREAM\r
476 or SOCK_SEQPAKCET socket using the TCPv6 network layer. It\r
477 configures the local TCPv6 connection point and then attempts to\r
478 connect to a remote system. Upon completion, the\r
479 ::EslTcp6ConnectComplete routine gets called with the connection\r
480 status.\r
481\r
482 This routine is called by ::EslSocketConnect to initiate the TCPv6\r
483 network specific connect operations. The connection processing is\r
484 initiated by this routine and finished by ::EslTcp6ConnectComplete.\r
485 This pair of routines walks through the list of local TCPv6\r
486 connection points until a connection to the remote system is\r
487 made.\r
488\r
489 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
490\r
491 @retval EFI_SUCCESS The connection was successfully established.\r
492 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
493 @retval Others The connection attempt failed.\r
494\r
495 **/\r
496EFI_STATUS\r
497EslTcp6ConnectStart (\r
498 IN ESL_SOCKET * pSocket\r
499 )\r
500{\r
501 ESL_PORT * pPort;\r
502 ESL_TCP6_CONTEXT * pTcp6;\r
503 EFI_TCP6_PROTOCOL * pTcp6Protocol;\r
3a2fc878 504 EFI_SIMPLE_NETWORK_MODE SnpModeData;\r
3bdf9aae 505 EFI_STATUS Status;\r
506\r
507 DBG_ENTER ( );\r
508 \r
509 //\r
510 // Determine if any more local adapters are available\r
511 //\r
512 pPort = pSocket->pPortList;\r
513 if ( NULL != pPort ) {\r
514 //\r
515 // Configure the port\r
516 //\r
517 pTcp6 = &pPort->Context.Tcp6;\r
518 pTcp6->ConfigData.AccessPoint.ActiveFlag = TRUE;\r
519 pTcp6->ConfigData.TrafficClass = 0;\r
520 pTcp6->ConfigData.HopLimit = 255;\r
521 pTcp6Protocol = pPort->pProtocol.TCPv6;\r
522 Status = pTcp6Protocol->Configure ( pTcp6Protocol,\r
523 &pTcp6->ConfigData );\r
524 if ( EFI_ERROR ( Status )) {\r
525 DEBUG (( DEBUG_CONNECT,\r
526 "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",\r
527 Status ));\r
3bdf9aae 528 }\r
529 else {\r
530 DEBUG (( DEBUG_CONNECT,\r
531 "0x%08x: Port configured\r\n",\r
532 pPort ));\r
533 pPort->bConfigured = TRUE;\r
534\r
535 //\r
3a2fc878 536 // Verify the port connection\r
3bdf9aae 537 //\r
3a2fc878 538 Status = pTcp6Protocol->GetModeData ( pTcp6Protocol,\r
539 NULL,\r
540 NULL,\r
541 NULL,\r
542 NULL,\r
543 &SnpModeData );\r
544 if ( !EFI_ERROR ( Status )) {\r
545 if ( SnpModeData.MediaPresentSupported\r
546 && ( !SnpModeData.MediaPresent )) {\r
547 //\r
548 // Port is not connected to the network\r
549 //\r
44538ba5 550 Status = EFI_NO_MEDIA;\r
3a2fc878 551 }\r
552 else {\r
553 //\r
554 // Attempt the connection to the remote system\r
555 //\r
556 Status = pTcp6Protocol->Connect ( pTcp6Protocol,\r
557 &pTcp6->ConnectToken );\r
558 }\r
559 }\r
44538ba5 560 if ( EFI_ERROR ( Status )) {\r
3bdf9aae 561 //\r
562 // Connection error\r
563 //\r
564 DEBUG (( DEBUG_CONNECT,\r
565 "ERROR - Port 0x%08x not connected, Status: %r\r\n",\r
566 pPort,\r
567 Status ));\r
3bdf9aae 568 }\r
569 }\r
44538ba5 570 if ( !EFI_ERROR ( Status )) {\r
571 //\r
572 // Connection in progress\r
573 //\r
574 pSocket->errno = EINPROGRESS;\r
575 DEBUG (( DEBUG_CONNECT,\r
576 "0x%08x: Port attempting connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
577 pPort,\r
578 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
579 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],\r
580 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],\r
581 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],\r
582 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],\r
583 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],\r
584 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],\r
585 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],\r
586 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],\r
587 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],\r
588 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],\r
589 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],\r
590 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],\r
591 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],\r
592 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],\r
593 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],\r
594 pTcp6->ConfigData.AccessPoint.RemotePort ));\r
595 }\r
596 else {\r
597 //\r
598 // Error return path is through EslTcp6ConnectComplete to\r
599 // enable retry on other ports\r
600 //\r
601 // Status to errno translation gets done in EslTcp4ConnectPoll\r
602 //\r
603 pTcp6->ConnectToken.CompletionToken.Status = Status;\r
604 \r
605 //\r
606 // Continue with the next port\r
607 //\r
608 gBS->CheckEvent ( pTcp6->ConnectToken.CompletionToken.Event );\r
609 gBS->SignalEvent ( pTcp6->ConnectToken.CompletionToken.Event );\r
610 }\r
611 Status = EFI_NOT_READY;\r
3bdf9aae 612 }\r
613 else {\r
614 //\r
615 // No more local adapters available\r
616 //\r
617 pSocket->errno = ENETUNREACH;\r
618 Status = EFI_NO_RESPONSE;\r
619 }\r
620\r
621 //\r
622 // Return the operation status\r
623 //\r
624 DBG_EXIT_STATUS ( Status );\r
625 return Status;\r
626}\r
627\r
628\r
629/**\r
630 Establish the known port to listen for network connections.\r
631\r
632 This routine places the port into a state that enables connection\r
633 attempts.\r
634\r
635 This routine is called by ::EslSocketListen to handle the network\r
636 specifics of the listen operation for SOCK_STREAM and SOCK_SEQPACKET\r
637 sockets. See the \ref ConnectionManagement section.\r
638\r
639 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
640\r
641 @retval EFI_SUCCESS - Socket successfully created\r
642 @retval Other - Failed to enable the socket for listen\r
643\r
644**/\r
645EFI_STATUS\r
646EslTcp6Listen (\r
647 IN ESL_SOCKET * pSocket\r
648 )\r
649{\r
650 ESL_PORT * pNextPort;\r
651 ESL_PORT * pPort;\r
652 ESL_TCP6_CONTEXT * pTcp6;\r
653 EFI_TCP6_PROTOCOL * pTcp6Protocol;\r
654 EFI_STATUS Status;\r
655\r
656 DBG_ENTER ( );\r
657\r
658 //\r
659 // Verify the socket layer synchronization\r
660 //\r
661 VERIFY_TPL ( TPL_SOCKETS );\r
662\r
663 //\r
664 // Use for/break instead of goto\r
665 //\r
666 for ( ; ; ) {\r
667 //\r
668 // Assume no ports are available\r
669 //\r
670 pSocket->errno = EOPNOTSUPP;\r
671 Status = EFI_NOT_READY;\r
672\r
673 //\r
674 // Walk the list of ports\r
675 //\r
676 pPort = pSocket->pPortList;\r
677 while ( NULL != pPort ) {\r
678 //\r
679 // Assume success\r
680 //\r
681 pSocket->errno = 0;\r
682\r
683 //\r
684 // Use for/break insteak of goto\r
685 //\r
686 for ( ; ; ) {\r
687 //\r
688 // Create the listen completion event\r
689 //\r
690 pTcp6 = &pPort->Context.Tcp6;\r
691 Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,\r
692 TPL_SOCKETS,\r
693 (EFI_EVENT_NOTIFY)EslTcp6ListenComplete,\r
694 pPort,\r
695 &pTcp6->ListenToken.CompletionToken.Event );\r
696 if ( EFI_ERROR ( Status )) {\r
697 DEBUG (( DEBUG_ERROR | DEBUG_LISTEN,\r
698 "ERROR - Failed to create the listen completion event, Status: %r\r\n",\r
699 Status ));\r
700 pSocket->errno = ENOMEM;\r
701 break;\r
702 }\r
703 DEBUG (( DEBUG_POOL,\r
704 "0x%08x: Created listen completion event\r\n",\r
705 pTcp6->ListenToken.CompletionToken.Event ));\r
706\r
707 //\r
708 // Configure the port\r
709 //\r
710 pTcp6Protocol = pPort->pProtocol.TCPv6;\r
711 Status = pTcp6Protocol->Configure ( pTcp6Protocol,\r
712 &pTcp6->ConfigData );\r
713 if ( EFI_ERROR ( Status )) {\r
714 DEBUG (( DEBUG_LISTEN,\r
715 "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",\r
716 Status ));\r
717 switch ( Status ) {\r
718 case EFI_ACCESS_DENIED:\r
719 pSocket->errno = EACCES;\r
720 break;\r
721\r
722 default:\r
723 case EFI_DEVICE_ERROR:\r
724 pSocket->errno = EIO;\r
725 break;\r
726\r
727 case EFI_INVALID_PARAMETER:\r
728 pSocket->errno = EADDRNOTAVAIL;\r
729 break;\r
730\r
731 case EFI_NO_MAPPING:\r
732 pSocket->errno = EAFNOSUPPORT;\r
733 break;\r
734\r
735 case EFI_OUT_OF_RESOURCES:\r
736 pSocket->errno = ENOBUFS;\r
737 break;\r
738\r
739 case EFI_UNSUPPORTED:\r
740 pSocket->errno = EOPNOTSUPP;\r
741 break;\r
742 }\r
743 break;\r
744 }\r
745 DEBUG (( DEBUG_LISTEN,\r
746 "0x%08x: Port configured\r\n",\r
747 pPort ));\r
748 pPort->bConfigured = TRUE;\r
749\r
750 //\r
751 // Start the listen operation on the port\r
752 //\r
753 Status = pTcp6Protocol->Accept ( pTcp6Protocol,\r
754 &pTcp6->ListenToken );\r
755 if ( EFI_ERROR ( Status )) {\r
756 DEBUG (( DEBUG_LISTEN,\r
757 "ERROR - Failed Tcp6 accept, Status: %r\r\n",\r
758 Status ));\r
759 switch ( Status ) {\r
760 case EFI_ACCESS_DENIED:\r
761 pSocket->errno = EACCES;\r
762 break;\r
763\r
764 default:\r
765 case EFI_DEVICE_ERROR:\r
766 pSocket->errno = EIO;\r
767 break;\r
768\r
769 case EFI_INVALID_PARAMETER:\r
770 pSocket->errno = EADDRNOTAVAIL;\r
771 break;\r
772\r
773 case EFI_NOT_STARTED:\r
774 pSocket->errno = ENETDOWN;\r
775 break;\r
776\r
777 case EFI_OUT_OF_RESOURCES:\r
778 pSocket->errno = ENOBUFS;\r
779 break;\r
780 }\r
781 break;\r
782 }\r
783 DEBUG (( DEBUG_LISTEN,\r
784 "0x%08x: Listen pending on Port\r\n",\r
785 pPort ));\r
786\r
787 //\r
788 // Listen is pending on this port\r
789 //\r
790 break;\r
791 }\r
792\r
793 //\r
794 // Get the next port\r
795 //\r
796 pNextPort = pPort->pLinkSocket;\r
797\r
798 //\r
799 // Close the port upon error\r
800 //\r
801 if ( EFI_ERROR ( Status )) {\r
802 EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );\r
803 }\r
804\r
805 //\r
806 // Set the next port\r
807 //\r
808 pPort = pNextPort;\r
809 }\r
810 \r
811 //\r
812 // Determine if any ports are in the listen state\r
813 //\r
814 if ( NULL == pSocket->pPortList ) {\r
815 //\r
816 // No ports in the listen state\r
817 //\r
818 pSocket->MaxFifoDepth = 0;\r
819\r
820 //\r
821 // Return the last error detected\r
822 //\r
823 break;\r
824 }\r
825\r
826 //\r
827 // Mark the socket as configured\r
828 //\r
829 pSocket->bConfigured = TRUE;\r
b497a8a8 830 Status = EFI_SUCCESS;\r
831 pSocket->errno = 0;\r
3bdf9aae 832\r
833 //\r
834 // All done\r
835 //\r
836 DEBUG (( DEBUG_LISTEN,\r
837 "0x%08x: pSocket - Listen pending on socket\r\n",\r
838 pSocket ));\r
839 break;\r
840 }\r
841\r
842 //\r
843 // Return the operation status\r
844 //\r
845 DBG_EXIT_STATUS ( Status );\r
846 return Status;\r
847}\r
848\r
849\r
850/**\r
851 Process the connection attempt\r
852\r
853 A system has initiated a connection attempt with a socket in the\r
854 listen state. Attempt to complete the connection.\r
855\r
856 The TCPv6 layer calls this routine when a connection is made to\r
857 the socket in the listen state. See the\r
858 \ref ConnectionManagement section.\r
859\r
860 @param [in] Event The listen completion event\r
861\r
862 @param [in] pPort Address of an ::ESL_PORT structure.\r
863\r
864**/\r
865VOID\r
866EslTcp6ListenComplete (\r
867 IN EFI_EVENT Event,\r
868 IN ESL_PORT * pPort\r
869 )\r
870{\r
871 EFI_HANDLE ChildHandle;\r
872 struct sockaddr_in6 LocalAddress;\r
873 EFI_TCP6_CONFIG_DATA * pConfigData;\r
874 ESL_LAYER * pLayer;\r
875 ESL_PORT * pNewPort;\r
876 ESL_SOCKET * pNewSocket;\r
877 ESL_SOCKET * pSocket;\r
878 ESL_TCP6_CONTEXT * pTcp6;\r
879 EFI_TCP6_PROTOCOL * pTcp6Protocol;\r
880 EFI_STATUS Status;\r
881 EFI_HANDLE TcpPortHandle;\r
882 EFI_STATUS TempStatus;\r
883\r
884 DBG_ENTER ( );\r
885 VERIFY_AT_TPL ( TPL_SOCKETS );\r
886\r
887 //\r
888 // Assume success\r
889 //\r
890 Status = EFI_SUCCESS;\r
891\r
892 //\r
893 // Determine if this connection fits into the connection FIFO\r
894 //\r
895 pSocket = pPort->pSocket;\r
896 TcpPortHandle = pPort->Context.Tcp6.ListenToken.NewChildHandle;\r
897 if (( SOCKET_STATE_LISTENING == pSocket->State )\r
898 && ( pSocket->MaxFifoDepth > pSocket->FifoDepth )) {\r
899 //\r
900 // Allocate a socket for this connection\r
901 //\r
902 ChildHandle = NULL;\r
903 pLayer = &mEslLayer;\r
904 Status = EslSocketAllocate ( &ChildHandle,\r
905 DEBUG_CONNECTION,\r
906 &pNewSocket );\r
907 if ( !EFI_ERROR ( Status )) {\r
908 //\r
909 // Clone the socket parameters\r
910 //\r
911 pNewSocket->pApi = pSocket->pApi;\r
912 pNewSocket->Domain = pSocket->Domain;\r
913 pNewSocket->Protocol = pSocket->Protocol;\r
914 pNewSocket->Type = pSocket->Type;\r
915\r
916 //\r
917 // Build the local address\r
918 //\r
919 pTcp6 = &pPort->Context.Tcp6;\r
920 LocalAddress.sin6_len = (uint8_t)pNewSocket->pApi->MinimumAddressLength;\r
921 LocalAddress.sin6_family = AF_INET6;\r
922 LocalAddress.sin6_port = 0;\r
923 CopyMem ( &LocalAddress.sin6_addr.__u6_addr.__u6_addr8 [ 0 ],\r
924 &pTcp6->ConfigData.AccessPoint.StationAddress.Addr [ 0 ],\r
925 sizeof ( pTcp6->ConfigData.AccessPoint.StationAddress.Addr ));\r
926\r
927 //\r
928 // Allocate a port for this connection\r
929 // Note in this instance Configure may not be called with NULL!\r
930 //\r
931 Status = EslSocketPortAllocate ( pNewSocket,\r
932 pPort->pService,\r
933 TcpPortHandle,\r
934 (struct sockaddr *)&LocalAddress,\r
935 FALSE,\r
936 DEBUG_CONNECTION,\r
937 &pNewPort );\r
938 if ( !EFI_ERROR ( Status )) {\r
939 //\r
940 // Restart the listen operation on the port\r
941 //\r
942 pTcp6Protocol = pPort->pProtocol.TCPv6;\r
943 Status = pTcp6Protocol->Accept ( pTcp6Protocol,\r
944 &pTcp6->ListenToken );\r
945\r
946 //\r
947 // Close the TCP port using SocketClose\r
948 //\r
949 TcpPortHandle = NULL;\r
950 pTcp6 = &pNewPort->Context.Tcp6;\r
951\r
952 //\r
953 // Check for an accept call error\r
954 //\r
955 if ( !EFI_ERROR ( Status )) {\r
956 //\r
957 // Get the port configuration\r
958 //\r
959 pNewPort->bConfigured = TRUE;\r
960 pConfigData = &pTcp6->ConfigData;\r
961 pConfigData->ControlOption = &pTcp6->Option;\r
962 pTcp6Protocol = pNewPort->pProtocol.TCPv6;\r
963 Status = pTcp6Protocol->GetModeData ( pTcp6Protocol,\r
964 NULL,\r
965 pConfigData,\r
966 NULL,\r
967 NULL,\r
968 NULL );\r
969 if ( !EFI_ERROR ( Status )) {\r
970 //\r
971 // Add the new socket to the connection FIFO\r
972 //\r
973 if ( NULL == pSocket->pFifoTail ) {\r
974 //\r
975 // First connection\r
976 //\r
977 pSocket->pFifoHead = pNewSocket;\r
978 }\r
979 else {\r
980 //\r
981 // Add to end of list.\r
982 //\r
983 pSocket->pFifoTail->pNextConnection = pNewSocket;\r
984 }\r
985 pSocket->pFifoTail = pNewSocket;\r
986 pSocket->FifoDepth += 1;\r
987\r
988 //\r
989 // Update the socket state\r
990 //\r
991 pNewSocket->State = SOCKET_STATE_IN_FIFO;\r
992\r
993 //\r
994 // Log the connection\r
995 //\r
996 DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,\r
997 "0x%08x: Socket on port [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
998 pNewSocket,\r
999 pConfigData->AccessPoint.StationAddress.Addr[0],\r
1000 pConfigData->AccessPoint.StationAddress.Addr[1],\r
1001 pConfigData->AccessPoint.StationAddress.Addr[2],\r
1002 pConfigData->AccessPoint.StationAddress.Addr[3],\r
1003 pConfigData->AccessPoint.StationAddress.Addr[4],\r
1004 pConfigData->AccessPoint.StationAddress.Addr[5],\r
1005 pConfigData->AccessPoint.StationAddress.Addr[6],\r
1006 pConfigData->AccessPoint.StationAddress.Addr[7],\r
1007 pConfigData->AccessPoint.StationAddress.Addr[8],\r
1008 pConfigData->AccessPoint.StationAddress.Addr[9],\r
1009 pConfigData->AccessPoint.StationAddress.Addr[10],\r
1010 pConfigData->AccessPoint.StationAddress.Addr[11],\r
1011 pConfigData->AccessPoint.StationAddress.Addr[12],\r
1012 pConfigData->AccessPoint.StationAddress.Addr[13],\r
1013 pConfigData->AccessPoint.StationAddress.Addr[14],\r
1014 pConfigData->AccessPoint.StationAddress.Addr[15],\r
1015 pConfigData->AccessPoint.StationPort,\r
1016 pConfigData->AccessPoint.RemoteAddress.Addr[0],\r
1017 pConfigData->AccessPoint.RemoteAddress.Addr[1],\r
1018 pConfigData->AccessPoint.RemoteAddress.Addr[2],\r
1019 pConfigData->AccessPoint.RemoteAddress.Addr[3],\r
1020 pConfigData->AccessPoint.RemoteAddress.Addr[4],\r
1021 pConfigData->AccessPoint.RemoteAddress.Addr[5],\r
1022 pConfigData->AccessPoint.RemoteAddress.Addr[6],\r
1023 pConfigData->AccessPoint.RemoteAddress.Addr[7],\r
1024 pConfigData->AccessPoint.RemoteAddress.Addr[8],\r
1025 pConfigData->AccessPoint.RemoteAddress.Addr[9],\r
1026 pConfigData->AccessPoint.RemoteAddress.Addr[10],\r
1027 pConfigData->AccessPoint.RemoteAddress.Addr[11],\r
1028 pConfigData->AccessPoint.RemoteAddress.Addr[12],\r
1029 pConfigData->AccessPoint.RemoteAddress.Addr[13],\r
1030 pConfigData->AccessPoint.RemoteAddress.Addr[14],\r
1031 pConfigData->AccessPoint.RemoteAddress.Addr[15],\r
1032 pConfigData->AccessPoint.RemotePort ));\r
1033 DEBUG (( DEBUG_CONNECTION | DEBUG_INFO,\r
1034 "0x%08x: Listen socket adding socket 0x%08x to FIFO, depth: %d\r\n",\r
1035 pSocket,\r
1036 pNewSocket,\r
1037 pSocket->FifoDepth ));\r
1038\r
1039 //\r
1040 // Start the receive operation\r
1041 //\r
1042 EslSocketRxStart ( pNewPort );\r
1043 }\r
1044 else {\r
1045 DEBUG (( DEBUG_ERROR | DEBUG_CONNECTION | DEBUG_INFO,\r
1046 "ERROR - GetModeData failed on port 0x%08x, Status: %r\r\n",\r
1047 pNewPort,\r
1048 Status ));\r
1049 }\r
1050 }\r
1051 else {\r
1052 //\r
1053 // The listen failed on this port\r
1054 //\r
1055 DEBUG (( DEBUG_LISTEN | DEBUG_INFO,\r
1056 "ERROR - Listen failed on port 0x%08x, Status: %r\r\n",\r
1057 pPort,\r
1058 Status ));\r
1059\r
1060 //\r
1061 // Close the listening port\r
1062 //\r
1063 EslSocketPortCloseStart ( pPort, TRUE, DEBUG_LISTEN );\r
1064 }\r
1065 }\r
1066\r
1067 //\r
1068 // Done with the socket if necessary\r
1069 //\r
1070 if ( EFI_ERROR ( Status )) {\r
1071 TempStatus = EslSocketCloseStart ( &pNewSocket->SocketProtocol,\r
1072 TRUE,\r
1073 &pSocket->errno );\r
1074 ASSERT ( EFI_SUCCESS == TempStatus );\r
1075 }\r
1076 }\r
1077 }\r
1078 else {\r
1079 DEBUG (( DEBUG_CONNECTION,\r
1080 "0x%08x: Socket FIFO full, connection refused\r\n",\r
1081 pSocket ));\r
1082\r
1083 //\r
1084 // The FIFO is full or the socket is in the wrong state\r
1085 //\r
1086 Status = EFI_BUFFER_TOO_SMALL;\r
1087 }\r
1088\r
1089 //\r
1090 // Close the connection if necessary\r
1091 //\r
1092 if (( EFI_ERROR ( Status ))\r
1093 && ( NULL == TcpPortHandle )) {\r
1094 //\r
1095 // TODO: Finish this code path\r
1096 // The new connection does not fit into the connection FIFO\r
1097 //\r
1098 // Process:\r
1099 // Call close\r
1100 // Release the resources\r
1101 \r
1102 }\r
1103\r
1104 DBG_EXIT ( );\r
1105}\r
1106\r
1107\r
1108/**\r
1109 Get the local socket address.\r
1110\r
1111 This routine returns the IPv6 address and TCP port number associated\r
1112 with the local socket.\r
1113\r
1114 This routine is called by ::EslSocketGetLocalAddress to determine the\r
1115 network address for the SOCK_STREAM or SOCK_SEQPACKET socket.\r
1116\r
1117 @param [in] pPort Address of an ::ESL_PORT structure.\r
1118\r
1119 @param [out] pSockAddr Network address to receive the local system address\r
1120\r
1121**/\r
1122VOID\r
1123EslTcp6LocalAddressGet (\r
1124 IN ESL_PORT * pPort,\r
1125 OUT struct sockaddr * pSockAddr\r
1126 )\r
1127{\r
1128 struct sockaddr_in6 * pLocalAddress;\r
1129 ESL_TCP6_CONTEXT * pTcp6;\r
1130\r
1131 DBG_ENTER ( );\r
1132\r
1133 //\r
1134 // Return the local address\r
1135 //\r
1136 pTcp6 = &pPort->Context.Tcp6;\r
1137 pLocalAddress = (struct sockaddr_in6 *)pSockAddr;\r
1138 pLocalAddress->sin6_family = AF_INET6;\r
1139 pLocalAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.StationPort );\r
1140 CopyMem ( &pLocalAddress->sin6_addr,\r
1141 &pTcp6->ConfigData.AccessPoint.StationAddress.Addr[0],\r
1142 sizeof ( pLocalAddress->sin6_addr ));\r
1143\r
1144 DBG_EXIT ( );\r
1145}\r
1146\r
1147\r
1148/**\r
1149 Set the local port address.\r
1150\r
1151 This routine sets the local port address.\r
1152\r
1153 This support routine is called by ::EslSocketPortAllocate.\r
1154\r
1155 @param [in] pPort Address of an ESL_PORT structure\r
1156 @param [in] pSockAddr Address of a sockaddr structure that contains the\r
1157 connection point on the local machine. An IPv6 address\r
1158 of INADDR_ANY specifies that the connection is made to\r
1159 all of the network stacks on the platform. Specifying a\r
1160 specific IPv6 address restricts the connection to the\r
1161 network stack supporting that address. Specifying zero\r
1162 for the port causes the network layer to assign a port\r
1163 number from the dynamic range. Specifying a specific\r
1164 port number causes the network layer to use that port.\r
1165\r
1166 @param [in] bBindTest TRUE = run bind testing\r
1167\r
1168 @retval EFI_SUCCESS The operation was successful\r
1169\r
1170 **/\r
1171EFI_STATUS\r
1172EslTcp6LocalAddressSet (\r
1173 IN ESL_PORT * pPort,\r
1174 IN CONST struct sockaddr * pSockAddr,\r
1175 IN BOOLEAN bBindTest\r
1176 )\r
1177{\r
1178 EFI_TCP6_ACCESS_POINT * pAccessPoint;\r
1179 CONST struct sockaddr_in6 * pIpAddress;\r
1180 EFI_STATUS Status;\r
1181\r
1182 DBG_ENTER ( );\r
1183\r
1184 //\r
1185 // Validate the address\r
1186 //\r
1187 pIpAddress = (struct sockaddr_in6 *)pSockAddr;\r
1188//\r
1189// TODO: Fix the following check\r
1190//\r
1191/*\r
1192 if ( INADDR_BROADCAST == pIpAddress->sin6_addr.s_addr ) {\r
1193 //\r
1194 // The local address must not be the broadcast address\r
1195 //\r
1196 Status = EFI_INVALID_PARAMETER;\r
1197 pPort->pSocket->errno = EADDRNOTAVAIL;\r
1198 }\r
1199 else {\r
1200*/\r
1201{\r
1202 //\r
1203 // Set the local address\r
1204 //\r
1205 pAccessPoint = &pPort->Context.Tcp6.ConfigData.AccessPoint;\r
1206 CopyMem ( &pAccessPoint->StationAddress.Addr[0],\r
1207 &pIpAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],\r
1208 sizeof ( pIpAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ]));\r
1209\r
1210 //\r
1211 // Validate the IP address\r
1212 //\r
1213 pAccessPoint->StationPort = 0;\r
1214 Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )\r
1215 : EFI_SUCCESS;\r
1216 if ( !EFI_ERROR ( Status )) {\r
1217 //\r
1218 // Set the port number\r
1219 //\r
1220 pAccessPoint->StationPort = SwapBytes16 ( pIpAddress->sin6_port );\r
f74dc4bb 1221 pPort->pSocket->bAddressSet = TRUE;\r
3bdf9aae 1222\r
1223 //\r
1224 // Display the local address\r
1225 //\r
1226 DEBUG (( DEBUG_BIND,\r
1227 "0x%08x: Port, Local Tcp6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
1228 pPort,\r
1229 pAccessPoint->StationAddress.Addr[0],\r
1230 pAccessPoint->StationAddress.Addr[1],\r
1231 pAccessPoint->StationAddress.Addr[2],\r
1232 pAccessPoint->StationAddress.Addr[3],\r
1233 pAccessPoint->StationAddress.Addr[4],\r
1234 pAccessPoint->StationAddress.Addr[5],\r
1235 pAccessPoint->StationAddress.Addr[6],\r
1236 pAccessPoint->StationAddress.Addr[7],\r
1237 pAccessPoint->StationAddress.Addr[8],\r
1238 pAccessPoint->StationAddress.Addr[9],\r
1239 pAccessPoint->StationAddress.Addr[10],\r
1240 pAccessPoint->StationAddress.Addr[11],\r
1241 pAccessPoint->StationAddress.Addr[12],\r
1242 pAccessPoint->StationAddress.Addr[13],\r
1243 pAccessPoint->StationAddress.Addr[14],\r
1244 pAccessPoint->StationAddress.Addr[15],\r
1245 pAccessPoint->StationPort ));\r
1246 }\r
1247 }\r
1248\r
1249 //\r
1250 // Return the operation status\r
1251 //\r
1252 DBG_EXIT_STATUS ( Status );\r
1253 return Status;\r
1254}\r
1255\r
1256\r
1257/**\r
1258 Free a receive packet\r
1259\r
1260 This routine performs the network specific operations necessary\r
1261 to free a receive packet.\r
1262\r
1263 This routine is called by ::EslSocketPortCloseTxDone to free a\r
1264 receive packet.\r
1265\r
1266 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
1267 @param [in, out] pRxBytes Address of the count of RX bytes\r
1268\r
1269**/\r
1270VOID\r
1271EslTcp6PacketFree (\r
1272 IN ESL_PACKET * pPacket,\r
1273 IN OUT size_t * pRxBytes\r
1274 )\r
1275{\r
1276 DBG_ENTER ( );\r
1277\r
1278 //\r
1279 // Account for the receive bytes\r
1280 //\r
1281 *pRxBytes -= pPacket->Op.Tcp6Rx.RxData.DataLength;\r
1282 DBG_EXIT ( );\r
1283}\r
1284\r
1285\r
1286/**\r
1287 Initialize the network specific portions of an ::ESL_PORT structure.\r
1288\r
1289 This routine initializes the network specific portions of an\r
1290 ::ESL_PORT structure for use by the socket.\r
1291\r
1292 This support routine is called by ::EslSocketPortAllocate\r
1293 to connect the socket with the underlying network adapter\r
1294 running the TCPv6 protocol.\r
1295\r
1296 @param [in] pPort Address of an ESL_PORT structure\r
1297 @param [in] DebugFlags Flags for debug messages\r
1298\r
1299 @retval EFI_SUCCESS - Socket successfully created\r
1300\r
1301 **/\r
1302EFI_STATUS\r
1303EslTcp6PortAllocate (\r
1304 IN ESL_PORT * pPort,\r
1305 IN UINTN DebugFlags\r
1306 )\r
1307{\r
1308 EFI_TCP6_ACCESS_POINT * pAccessPoint;\r
1309 ESL_SOCKET * pSocket;\r
1310 ESL_TCP6_CONTEXT * pTcp6;\r
1311 EFI_STATUS Status;\r
1312\r
1313 DBG_ENTER ( );\r
1314\r
1315 //\r
1316 // Use for/break instead of goto\r
1317 for ( ; ; ) {\r
1318 //\r
1319 // Allocate the close event\r
1320 //\r
1321 pSocket = pPort->pSocket;\r
1322 pTcp6 = &pPort->Context.Tcp6;\r
1323 Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,\r
1324 TPL_SOCKETS,\r
1325 (EFI_EVENT_NOTIFY)EslSocketPortCloseComplete,\r
1326 pPort,\r
1327 &pTcp6->CloseToken.CompletionToken.Event);\r
1328 if ( EFI_ERROR ( Status )) {\r
1329 DEBUG (( DEBUG_ERROR | DebugFlags,\r
1330 "ERROR - Failed to create the close event, Status: %r\r\n",\r
1331 Status ));\r
1332 pSocket->errno = ENOMEM;\r
1333 break;\r
1334 }\r
1335 DEBUG (( DEBUG_CLOSE | DEBUG_POOL,\r
1336 "0x%08x: Created close event\r\n",\r
1337 pTcp6->CloseToken.CompletionToken.Event ));\r
1338\r
1339 //\r
1340 // Allocate the connection event\r
1341 //\r
1342 Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,\r
1343 TPL_SOCKETS,\r
1344 (EFI_EVENT_NOTIFY)EslTcp6ConnectComplete,\r
1345 pPort,\r
1346 &pTcp6->ConnectToken.CompletionToken.Event);\r
1347 if ( EFI_ERROR ( Status )) {\r
1348 DEBUG (( DEBUG_ERROR | DebugFlags,\r
1349 "ERROR - Failed to create the connect event, Status: %r\r\n",\r
1350 Status ));\r
1351 pSocket->errno = ENOMEM;\r
1352 break;\r
1353 }\r
1354 DEBUG (( DEBUG_CLOSE | DEBUG_POOL,\r
1355 "0x%08x: Created connect event\r\n",\r
1356 pTcp6->ConnectToken.CompletionToken.Event ));\r
1357\r
1358 //\r
1359 // Initialize the port\r
1360 //\r
1361 pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Tcp6Tx.TxData );\r
1362 pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Tcp6Tx.CompletionToken.Event );\r
1363 pSocket->TxTokenOffset = OFFSET_OF ( EFI_TCP6_IO_TOKEN, Packet.TxData );\r
1364\r
1365 //\r
1366 // Save the cancel, receive and transmit addresses\r
1367 // pPort->pfnRxCancel = NULL; since the UEFI implementation returns EFI_UNSUPPORTED\r
1368 //\r
1369 pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.TCPv6->Configure;\r
1370 pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.TCPv6->Poll;\r
1371 pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv6->Receive;\r
1372 pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv6->Transmit;\r
1373\r
1374 //\r
1375 // Set the configuration flags\r
1376 //\r
1377 pAccessPoint = &pPort->Context.Tcp6.ConfigData.AccessPoint;\r
1378 pAccessPoint->ActiveFlag = FALSE;\r
1379 pTcp6->ConfigData.TrafficClass = 0;\r
1380 pTcp6->ConfigData.HopLimit = 255;\r
1381 break;\r
1382 }\r
1383\r
1384 //\r
1385 // Return the operation status\r
1386 //\r
1387 DBG_EXIT_STATUS ( Status );\r
1388 return Status;\r
1389}\r
1390\r
1391\r
1392/**\r
1393 Close a Tcp6 port.\r
1394\r
1395 This routine releases the network specific resources allocated by\r
1396 ::EslTcp6PortAllocate.\r
1397\r
1398 This routine is called by ::EslSocketPortClose.\r
1399 See the \ref PortCloseStateMachine section.\r
1400 \r
1401 @param [in] pPort Address of an ::ESL_PORT structure.\r
1402\r
1403 @retval EFI_SUCCESS The port is closed\r
1404 @retval other Port close error\r
1405\r
1406**/\r
1407EFI_STATUS\r
1408EslTcp6PortClose (\r
1409 IN ESL_PORT * pPort\r
1410 )\r
1411{\r
1412 UINTN DebugFlags;\r
1413 ESL_TCP6_CONTEXT * pTcp6;\r
1414 EFI_STATUS Status;\r
1415 \r
1416 DBG_ENTER ( );\r
1417\r
1418 //\r
1419 // Locate the port in the socket list\r
1420 //\r
1421 Status = EFI_SUCCESS;\r
1422 DebugFlags = pPort->DebugFlags;\r
1423 pTcp6 = &pPort->Context.Tcp6;\r
1424\r
1425 //\r
1426 // Done with the connect event\r
1427 //\r
1428 if ( NULL != pTcp6->ConnectToken.CompletionToken.Event ) {\r
1429 Status = gBS->CloseEvent ( pTcp6->ConnectToken.CompletionToken.Event );\r
1430 if ( !EFI_ERROR ( Status )) {\r
1431 DEBUG (( DebugFlags | DEBUG_POOL,\r
1432 "0x%08x: Closed connect event\r\n",\r
1433 pTcp6->ConnectToken.CompletionToken.Event ));\r
1434 }\r
1435 else {\r
1436 DEBUG (( DEBUG_ERROR | DebugFlags,\r
1437 "ERROR - Failed to close the connect event, Status: %r\r\n",\r
1438 Status ));\r
1439 ASSERT ( EFI_SUCCESS == Status );\r
1440 }\r
1441 }\r
1442\r
1443 //\r
1444 // Done with the close event\r
1445 //\r
1446 if ( NULL != pTcp6->CloseToken.CompletionToken.Event ) {\r
1447 Status = gBS->CloseEvent ( pTcp6->CloseToken.CompletionToken.Event );\r
1448 if ( !EFI_ERROR ( Status )) {\r
1449 DEBUG (( DebugFlags | DEBUG_POOL,\r
1450 "0x%08x: Closed close event\r\n",\r
1451 pTcp6->CloseToken.CompletionToken.Event ));\r
1452 }\r
1453 else {\r
1454 DEBUG (( DEBUG_ERROR | DebugFlags,\r
1455 "ERROR - Failed to close the close event, Status: %r\r\n",\r
1456 Status ));\r
1457 ASSERT ( EFI_SUCCESS == Status );\r
1458 }\r
1459 }\r
1460\r
1461 //\r
1462 // Done with the listen completion event\r
1463 //\r
1464 if ( NULL != pTcp6->ListenToken.CompletionToken.Event ) {\r
1465 Status = gBS->CloseEvent ( pTcp6->ListenToken.CompletionToken.Event );\r
1466 if ( !EFI_ERROR ( Status )) {\r
1467 DEBUG (( DebugFlags | DEBUG_POOL,\r
1468 "0x%08x: Closed listen completion event\r\n",\r
1469 pTcp6->ListenToken.CompletionToken.Event ));\r
1470 }\r
1471 else {\r
1472 DEBUG (( DEBUG_ERROR | DebugFlags,\r
1473 "ERROR - Failed to close the listen completion event, Status: %r\r\n",\r
1474 Status ));\r
1475 ASSERT ( EFI_SUCCESS == Status );\r
1476 }\r
1477 }\r
1478\r
1479 //\r
1480 // Return the operation status\r
1481 //\r
1482 DBG_EXIT_STATUS ( Status );\r
1483 return Status;\r
1484}\r
1485\r
1486\r
1487/**\r
1488 Perform the network specific close operation on the port.\r
1489\r
1490 This routine performs a cancel operations on the TCPv6 port to\r
1491 shutdown the receive operations on the port.\r
1492\r
1493 This routine is called by the ::EslSocketPortCloseTxDone\r
1494 routine after the port completes all of the transmission.\r
1495\r
1496 @param [in] pPort Address of an ::ESL_PORT structure.\r
1497\r
1498 @retval EFI_SUCCESS The port is closed, not normally returned\r
1499 @retval EFI_NOT_READY The port is still closing\r
1500 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,\r
1501 most likely the routine was called already.\r
1502\r
1503**/\r
1504EFI_STATUS\r
1505EslTcp6PortCloseOp (\r
1506 IN ESL_PORT * pPort\r
1507 )\r
1508{\r
1509 ESL_TCP6_CONTEXT * pTcp6;\r
1510 EFI_TCP6_PROTOCOL * pTcp6Protocol;\r
1511 EFI_STATUS Status;\r
1512\r
1513 DBG_ENTER ( );\r
1514\r
1515 //\r
1516 // Close the configured port\r
1517 //\r
1518 Status = EFI_SUCCESS;\r
1519 pTcp6 = &pPort->Context.Tcp6;\r
1520 pTcp6Protocol = pPort->pProtocol.TCPv6;\r
1521 pTcp6->CloseToken.AbortOnClose = pPort->bCloseNow;\r
1522 Status = pTcp6Protocol->Close ( pTcp6Protocol,\r
1523 &pTcp6->CloseToken );\r
1524 if ( !EFI_ERROR ( Status )) {\r
1525 DEBUG (( pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,\r
1526 "0x%08x: Port close started\r\n",\r
1527 pPort ));\r
1528 }\r
1529 else {\r
1530 DEBUG (( DEBUG_ERROR | pPort->DebugFlags | DEBUG_CLOSE | DEBUG_INFO,\r
1531 "ERROR - Close failed on port 0x%08x, Status: %r\r\n",\r
1532 pPort,\r
1533 Status ));\r
1534 }\r
1535\r
1536 //\r
1537 // Return the operation status\r
1538 //\r
1539 DBG_EXIT_STATUS ( Status );\r
1540 return Status;\r
1541}\r
1542\r
1543\r
1544/**\r
1545 Receive data from a network connection.\r
1546\r
1547 This routine attempts to return buffered data to the caller. The\r
1548 data is removed from the urgent queue if the message flag MSG_OOB\r
1549 is specified, otherwise data is removed from the normal queue.\r
1550 See the \ref ReceiveEngine section.\r
1551\r
1552 This routine is called by ::EslSocketReceive to handle the network\r
1553 specific receive operation to support SOCK_STREAM and SOCK_SEQPACKET\r
1554 sockets.\r
1555\r
1556 @param [in] pPort Address of an ::ESL_PORT structure.\r
1557\r
1558 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
1559 \r
1560 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed\r
1561 \r
1562 @param [in] BufferLength Length of the the buffer\r
1563 \r
1564 @param [in] pBuffer Address of a buffer to receive the data.\r
1565 \r
1566 @param [in] pDataLength Number of received data bytes in the buffer.\r
1567\r
1568 @param [out] pAddress Network address to receive the remote system address\r
1569\r
1570 @param [out] pSkipBytes Address to receive the number of bytes skipped\r
1571\r
1572 @return Returns the address of the next free byte in the buffer.\r
1573\r
1574 **/\r
1575UINT8 *\r
1576EslTcp6Receive (\r
1577 IN ESL_PORT * pPort,\r
1578 IN ESL_PACKET * pPacket,\r
1579 IN BOOLEAN * pbConsumePacket,\r
1580 IN size_t BufferLength,\r
1581 IN UINT8 * pBuffer,\r
1582 OUT size_t * pDataLength,\r
1583 OUT struct sockaddr * pAddress,\r
1584 OUT size_t * pSkipBytes\r
1585 )\r
1586{\r
1587 size_t DataLength;\r
1588 struct sockaddr_in6 * pRemoteAddress;\r
1589 ESL_TCP6_CONTEXT * pTcp6;\r
1590\r
1591 DBG_ENTER ( );\r
1592\r
1593 //\r
1594 // Return the remote system address if requested\r
1595 //\r
1596 if ( NULL != pAddress ) {\r
1597 //\r
1598 // Build the remote address\r
1599 //\r
1600 pTcp6 = &pPort->Context.Tcp6;\r
1601 DEBUG (( DEBUG_RX,\r
1602 "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
1603 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
1604 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[1],\r
1605 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[2],\r
1606 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[3],\r
1607 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[4],\r
1608 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[5],\r
1609 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[6],\r
1610 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[7],\r
1611 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[8],\r
1612 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[9],\r
1613 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[10],\r
1614 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[11],\r
1615 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[12],\r
1616 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[13],\r
1617 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[14],\r
1618 pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[15],\r
1619 pTcp6->ConfigData.AccessPoint.RemotePort ));\r
1620 pRemoteAddress = (struct sockaddr_in6 *)pAddress;\r
1621 CopyMem ( &pRemoteAddress->sin6_addr,\r
1622 &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
1623 sizeof ( pRemoteAddress->sin6_addr ));\r
1624 pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );\r
1625 }\r
1626\r
1627 //\r
1628 // Determine the amount of received data\r
1629 //\r
1630 DataLength = pPacket->ValidBytes;\r
1631 if ( BufferLength < DataLength ) {\r
1632 DataLength = BufferLength;\r
1633 }\r
1634\r
1635 //\r
1636 // Move the data into the buffer\r
1637 //\r
1638 DEBUG (( DEBUG_RX,\r
1639 "0x%08x: Port copy packet 0x%08x data into 0x%08x, 0x%08x bytes\r\n",\r
1640 pPort,\r
1641 pPacket,\r
1642 pBuffer,\r
1643 DataLength ));\r
1644 CopyMem ( pBuffer, pPacket->pBuffer, DataLength );\r
1645\r
fcb6f89d 1646 //\r
1647 // Set the next buffer address\r
1648 //\r
1649 pBuffer += DataLength;\r
1650\r
3bdf9aae 1651 //\r
1652 // Determine if the data is being read\r
1653 //\r
1654 if ( *pbConsumePacket ) {\r
1655 //\r
1656 // Account for the bytes consumed\r
1657 //\r
1658 pPacket->pBuffer += DataLength;\r
1659 pPacket->ValidBytes -= DataLength;\r
1660 DEBUG (( DEBUG_RX,\r
1661 "0x%08x: Port account for 0x%08x bytes\r\n",\r
1662 pPort,\r
1663 DataLength ));\r
1664\r
1665 //\r
1666 // Determine if the entire packet was consumed\r
1667 //\r
1668 if (( 0 == pPacket->ValidBytes )\r
1669 || ( SOCK_STREAM != pPort->pSocket->Type )) {\r
1670 //\r
1671 // All done with this packet\r
1672 // Account for any discarded data\r
1673 //\r
1674 *pSkipBytes = pPacket->ValidBytes;\r
1675 }\r
1676 else\r
1677 {\r
1678 //\r
1679 // More data to consume later\r
1680 //\r
1681 *pbConsumePacket = FALSE;\r
1682 }\r
1683 }\r
1684\r
1685 //\r
1686 // Return the data length and the buffer address\r
1687 //\r
1688 *pDataLength = DataLength;\r
1689 DBG_EXIT_HEX ( pBuffer );\r
1690 return pBuffer;\r
1691}\r
1692\r
1693\r
1694/**\r
1695 Get the remote socket address.\r
1696\r
1697 This routine returns the address of the remote connection point\r
1698 associated with the SOCK_STREAM or SOCK_SEQPACKET socket.\r
1699\r
1700 This routine is called by ::EslSocketGetPeerAddress to detemine\r
1701 the TCPv6 address and por number associated with the network adapter.\r
1702\r
1703 @param [in] pPort Address of an ::ESL_PORT structure.\r
1704\r
1705 @param [out] pAddress Network address to receive the remote system address\r
1706\r
1707**/\r
1708VOID\r
1709EslTcp6RemoteAddressGet (\r
1710 IN ESL_PORT * pPort,\r
1711 OUT struct sockaddr * pAddress\r
1712 )\r
1713{\r
1714 struct sockaddr_in6 * pRemoteAddress;\r
1715 ESL_TCP6_CONTEXT * pTcp6;\r
1716\r
1717 DBG_ENTER ( );\r
1718\r
1719 //\r
1720 // Return the remote address\r
1721 //\r
1722 pTcp6 = &pPort->Context.Tcp6;\r
1723 pRemoteAddress = (struct sockaddr_in6 *)pAddress;\r
1724 pRemoteAddress->sin6_family = AF_INET6;\r
1725 pRemoteAddress->sin6_port = SwapBytes16 ( pTcp6->ConfigData.AccessPoint.RemotePort );\r
1726 CopyMem ( &pRemoteAddress->sin6_addr,\r
1727 &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr[0],\r
1728 sizeof ( pRemoteAddress->sin6_addr ));\r
1729\r
1730 DBG_EXIT ( );\r
1731}\r
1732\r
1733\r
1734/**\r
1735 Set the remote address\r
1736\r
1737 This routine sets the remote address in the port.\r
1738\r
1739 This routine is called by ::EslSocketConnect to specify the\r
1740 remote network address.\r
1741\r
1742 @param [in] pPort Address of an ::ESL_PORT structure.\r
1743\r
1744 @param [in] pSockAddr Network address of the remote system.\r
1745\r
1746 @param [in] SockAddrLength Length in bytes of the network address.\r
1747\r
1748 @retval EFI_SUCCESS The operation was successful\r
1749\r
1750 **/\r
1751EFI_STATUS\r
1752EslTcp6RemoteAddressSet (\r
1753 IN ESL_PORT * pPort,\r
1754 IN CONST struct sockaddr * pSockAddr,\r
1755 IN socklen_t SockAddrLength\r
1756 )\r
1757{\r
1758 CONST struct sockaddr_in6 * pRemoteAddress;\r
1759 ESL_TCP6_CONTEXT * pTcp6;\r
1760 EFI_STATUS Status;\r
1761\r
1762 DBG_ENTER ( );\r
1763\r
1764 //\r
1765 // Set the remote address\r
1766 //\r
1767 pTcp6 = &pPort->Context.Tcp6;\r
1768 pRemoteAddress = (struct sockaddr_in6 *)pSockAddr;\r
1769 CopyMem ( &pTcp6->ConfigData.AccessPoint.RemoteAddress.Addr [ 0 ],\r
1770 &pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 [ 0 ],\r
1771 sizeof ( pRemoteAddress->sin6_addr.__u6_addr.__u6_addr8 ));\r
1772 pTcp6->ConfigData.AccessPoint.RemotePort = SwapBytes16 ( pRemoteAddress->sin6_port );\r
1773 Status = EFI_SUCCESS;\r
1774\r
1775//\r
1776// TODO: Fix the following check\r
1777//\r
1778/*\r
1779 if ( INADDR_BROADCAST == pRemoteAddress->sin6_addr.s_addr ) {\r
1780 DEBUG (( DEBUG_CONNECT,\r
1781 "ERROR - Invalid remote address\r\n" ));\r
1782 Status = EFI_INVALID_PARAMETER;\r
1783 pPort->pSocket->errno = EAFNOSUPPORT;\r
1784 }\r
1785*/\r
1786\r
1787 //\r
1788 // Return the operation status\r
1789 //\r
1790 DBG_EXIT_STATUS ( Status );\r
1791 return Status;\r
1792}\r
1793\r
1794\r
1795/**\r
1796 Process the receive completion\r
1797\r
1798 This routine queues the data in FIFO order in either the urgent\r
1799 or normal data queues depending upon the type of data received.\r
1800 See the \ref ReceiveEngine section.\r
1801\r
1802 This routine is called by the TCPv6 driver when some data is\r
1803 received.\r
1804\r
1805 Buffer the data that was just received.\r
1806\r
1807 @param [in] Event The receive completion event\r
1808\r
1809 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1810\r
1811**/\r
1812VOID\r
1813EslTcp6RxComplete (\r
1814 IN EFI_EVENT Event,\r
1815 IN ESL_IO_MGMT * pIo\r
1816 )\r
1817{\r
1818 BOOLEAN bUrgent;\r
1819 size_t LengthInBytes;\r
1820 ESL_PACKET * pPacket;\r
1821 EFI_STATUS Status;\r
1822\r
1823 DBG_ENTER ( );\r
1824\r
1825 //\r
1826 // Get the operation status.\r
1827 //\r
1828 Status = pIo->Token.Tcp6Rx.CompletionToken.Status;\r
1829\r
1830 //\r
1831 // +--------------------+ +---------------------------+\r
1832 // | ESL_IO_MGMT | | ESL_PACKET |\r
1833 // | | | |\r
1834 // | +---------------+ +-----------------------+ |\r
1835 // | | Token | | EFI_Tcp6_RECEIVE_DATA | |\r
1836 // | | RxData --> | | |\r
1837 // | | | +-----------------------+---+\r
1838 // | | Event | | Data Buffer |\r
1839 // +----+---------------+ | |\r
1840 // | |\r
1841 // +---------------------------+\r
1842 //\r
1843 //\r
1844 // Duplicate the buffer address and length for use by the\r
1845 // buffer handling code in EslTcp6Receive. These fields are\r
1846 // used when a partial read is done of the data from the\r
1847 // packet.\r
1848 //\r
1849 pPacket = pIo->pPacket;\r
1850 pPacket->pBuffer = pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentBuffer;\r
1851 LengthInBytes = pPacket->Op.Tcp6Rx.RxData.DataLength;\r
1852 pPacket->ValidBytes = LengthInBytes;\r
1853\r
1854 //\r
1855 // Get the data type so that it may be linked to the\r
1856 // correct receive buffer list on the ESL_SOCKET structure\r
1857 //\r
1858 bUrgent = pPacket->Op.Tcp6Rx.RxData.UrgentFlag;\r
1859\r
1860 //\r
1861 // Complete this request\r
1862 //\r
1863 EslSocketRxComplete ( pIo, Status, LengthInBytes, bUrgent );\r
1864 DBG_EXIT ( );\r
1865}\r
1866\r
1867\r
1868/**\r
1869 Start a receive operation\r
1870\r
1871 This routine posts a receive buffer to the TCPv6 driver.\r
1872 See the \ref ReceiveEngine section.\r
1873\r
1874 This support routine is called by EslSocketRxStart.\r
1875\r
1876 @param [in] pPort Address of an ::ESL_PORT structure.\r
1877 @param [in] pIo Address of an ::ESL_IO_MGMT structure.\r
1878\r
1879 **/\r
1880VOID\r
1881EslTcp6RxStart (\r
1882 IN ESL_PORT * pPort,\r
1883 IN ESL_IO_MGMT * pIo\r
1884 )\r
1885{\r
1886 ESL_PACKET * pPacket;\r
1887\r
1888 DBG_ENTER ( );\r
1889\r
1890 //\r
1891 // Initialize the buffer for receive\r
1892 //\r
1893 pPacket = pIo->pPacket;\r
1894 pIo->Token.Tcp6Rx.Packet.RxData = &pPacket->Op.Tcp6Rx.RxData;\r
1895 pPacket->Op.Tcp6Rx.RxData.DataLength = sizeof ( pPacket->Op.Tcp6Rx.Buffer );\r
1896 pPacket->Op.Tcp6Rx.RxData.FragmentCount = 1;\r
1897 pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentLength = pPacket->Op.Tcp6Rx.RxData.DataLength;\r
1898 pPacket->Op.Tcp6Rx.RxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp6Rx.Buffer[0];\r
1899\r
1900 DBG_EXIT ( );\r
1901}\r
1902\r
1903\r
1904/**\r
1905 Determine if the socket is configured.\r
1906\r
1907 This routine uses the flag ESL_SOCKET::bConfigured to determine\r
1908 if the network layer's configuration routine has been called.\r
1909\r
1910 This routine is called by EslSocketIsConfigured to verify\r
1911 that the socket has been configured.\r
1912\r
1913 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
1914\r
1915 @retval EFI_SUCCESS - The port is connected\r
1916 @retval EFI_NOT_STARTED - The port is not connected\r
1917\r
1918 **/\r
1919 EFI_STATUS\r
1920 EslTcp6SocketIsConfigured (\r
1921 IN ESL_SOCKET * pSocket\r
1922 )\r
1923{\r
1924 EFI_STATUS Status;\r
1925\r
1926 DBG_ENTER ( );\r
1927\r
1928 //\r
1929 // Determine the socket configuration status\r
1930 //\r
1931 Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;\r
1932\r
1933 //\r
1934 // Return the port connected state.\r
1935 //\r
1936 DBG_EXIT_STATUS ( Status );\r
1937 return Status;\r
1938}\r
1939\r
1940\r
1941/**\r
1942 Buffer data for transmission over a network connection.\r
1943\r
1944 This routine buffers data for the transmit engine in one of two\r
1945 queues, one for urgent (out-of-band) data and the other for normal\r
1946 data. The urgent data is provided to TCP as soon as it is available,\r
1947 allowing the TCP layer to schedule transmission of the urgent data\r
1948 between packets of normal data.\r
1949\r
1950 This routine is called by ::EslSocketTransmit to buffer\r
1951 data for transmission. When the \ref TransmitEngine has resources,\r
1952 this routine will start the transmission of the next buffer on\r
1953 the network connection.\r
1954\r
1955 Transmission errors are returned during the next transmission or\r
1956 during the close operation. Only buffering errors are returned\r
1957 during the current transmission attempt.\r
1958\r
1959 @param [in] pSocket Address of an ::ESL_SOCKET structure\r
1960 \r
1961 @param [in] Flags Message control flags\r
1962 \r
1963 @param [in] BufferLength Length of the the buffer\r
1964 \r
1965 @param [in] pBuffer Address of a buffer to receive the data.\r
1966 \r
1967 @param [in] pDataLength Number of received data bytes in the buffer.\r
1968\r
1969 @param [in] pAddress Network address of the remote system address\r
1970\r
1971 @param [in] AddressLength Length of the remote network address structure\r
1972\r
1973 @retval EFI_SUCCESS - Socket data successfully buffered\r
1974\r
1975 **/\r
1976EFI_STATUS\r
1977EslTcp6TxBuffer (\r
1978 IN ESL_SOCKET * pSocket,\r
1979 IN int Flags,\r
1980 IN size_t BufferLength,\r
1981 IN CONST UINT8 * pBuffer,\r
1982 OUT size_t * pDataLength,\r
1983 IN const struct sockaddr * pAddress,\r
1984 IN socklen_t AddressLength\r
1985 )\r
1986{\r
1987 BOOLEAN bUrgent;\r
1988 BOOLEAN bUrgentQueue;\r
1989 ESL_PACKET * pPacket;\r
1990 ESL_IO_MGMT ** ppActive;\r
1991 ESL_IO_MGMT ** ppFree;\r
1992 ESL_PORT * pPort;\r
1993 ESL_PACKET ** ppQueueHead;\r
1994 ESL_PACKET ** ppQueueTail;\r
1995 ESL_PACKET * pPreviousPacket;\r
1996 ESL_TCP6_CONTEXT * pTcp6;\r
1997 size_t * pTxBytes;\r
1998 EFI_TCP6_TRANSMIT_DATA * pTxData;\r
1999 EFI_STATUS Status;\r
2000 EFI_TPL TplPrevious;\r
2001\r
2002 DBG_ENTER ( );\r
2003\r
2004 //\r
2005 // Assume failure\r
2006 //\r
2007 Status = EFI_UNSUPPORTED;\r
2008 pSocket->errno = ENOTCONN;\r
2009 *pDataLength = 0;\r
2010\r
2011 //\r
2012 // Verify that the socket is connected\r
2013 //\r
2014 if ( SOCKET_STATE_CONNECTED == pSocket->State ) {\r
2015 //\r
2016 // Locate the port\r
2017 //\r
2018 pPort = pSocket->pPortList;\r
2019 if ( NULL != pPort ) {\r
2020 //\r
2021 // Determine the queue head\r
2022 //\r
2023 pTcp6 = &pPort->Context.Tcp6;\r
2024 bUrgent = (BOOLEAN)( 0 != ( Flags & MSG_OOB ));\r
2025 bUrgentQueue = bUrgent\r
2026 && ( !pSocket->bOobInLine )\r
2027 && pSocket->pApi->bOobSupported;\r
2028 if ( bUrgentQueue ) {\r
2029 ppQueueHead = &pSocket->pTxOobPacketListHead;\r
2030 ppQueueTail = &pSocket->pTxOobPacketListTail;\r
2031 ppActive = &pPort->pTxOobActive;\r
2032 ppFree = &pPort->pTxOobFree;\r
2033 pTxBytes = &pSocket->TxOobBytes;\r
2034 }\r
2035 else {\r
2036 ppQueueHead = &pSocket->pTxPacketListHead;\r
2037 ppQueueTail = &pSocket->pTxPacketListTail;\r
2038 ppActive = &pPort->pTxActive;\r
2039 ppFree = &pPort->pTxFree;\r
2040 pTxBytes = &pSocket->TxBytes;\r
2041 }\r
2042\r
2043 //\r
2044 // Verify that there is enough room to buffer another\r
2045 // transmit operation\r
2046 //\r
2047 if ( pSocket->MaxTxBuf > *pTxBytes ) {\r
2048 if ( pPort->bTxFlowControl ) {\r
2049 DEBUG (( DEBUG_TX,\r
2050 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n0x%08x: pPort, TX flow control released, Max bytes: %d > %d bufferred bytes\r\n",\r
2051 pPort,\r
2052 pSocket->MaxTxBuf,\r
2053 *pTxBytes ));\r
2054 pPort->bTxFlowControl = FALSE;\r
2055 }\r
2056\r
2057 //\r
2058 // Attempt to allocate the packet\r
2059 //\r
2060 Status = EslSocketPacketAllocate ( &pPacket,\r
2061 sizeof ( pPacket->Op.Tcp6Tx )\r
2062 - sizeof ( pPacket->Op.Tcp6Tx.Buffer )\r
2063 + BufferLength,\r
2064 0,\r
2065 DEBUG_TX );\r
2066 if ( !EFI_ERROR ( Status )) {\r
2067 //\r
2068 // Initialize the transmit operation\r
2069 //\r
2070 pTxData = &pPacket->Op.Tcp6Tx.TxData;\r
2071 pTxData->Push = TRUE || bUrgent;\r
2072 pTxData->Urgent = bUrgent;\r
2073 pTxData->DataLength = (UINT32) BufferLength;\r
2074 pTxData->FragmentCount = 1;\r
2075 pTxData->FragmentTable[0].FragmentLength = (UINT32) BufferLength;\r
2076 pTxData->FragmentTable[0].FragmentBuffer = &pPacket->Op.Tcp6Tx.Buffer[0];\r
2077\r
2078 //\r
2079 // Copy the data into the buffer\r
2080 //\r
2081 CopyMem ( &pPacket->Op.Tcp6Tx.Buffer[0],\r
2082 pBuffer,\r
2083 BufferLength );\r
2084\r
2085 //\r
2086 // Synchronize with the socket layer\r
2087 //\r
2088 RAISE_TPL ( TplPrevious, TPL_SOCKETS );\r
2089\r
2090 //\r
2091 // Stop transmission after an error\r
2092 //\r
2093 if ( !EFI_ERROR ( pSocket->TxError )) {\r
2094 //\r
2095 // Display the request\r
2096 //\r
2097 DEBUG (( DEBUG_TX,\r
2098 "Send %d %s bytes from 0x%08x\r\n",\r
2099 BufferLength,\r
2100 bUrgent ? L"urgent" : L"normal",\r
2101 pBuffer ));\r
2102\r
2103 //\r
2104 // Queue the data for transmission\r
2105 //\r
2106 pPacket->pNext = NULL;\r
2107 pPreviousPacket = *ppQueueTail;\r
2108 if ( NULL == pPreviousPacket ) {\r
2109 *ppQueueHead = pPacket;\r
2110 }\r
2111 else {\r
2112 pPreviousPacket->pNext = pPacket;\r
2113 }\r
2114 *ppQueueTail = pPacket;\r
2115 DEBUG (( DEBUG_TX,\r
2116 "0x%08x: Packet on %s transmit list\r\n",\r
2117 pPacket,\r
2118 bUrgentQueue ? L"urgent" : L"normal" ));\r
2119\r
2120 //\r
2121 // Account for the buffered data\r
2122 //\r
2123 *pTxBytes += BufferLength;\r
2124 *pDataLength = BufferLength;\r
2125\r
2126 //\r
2127 // Start the transmit engine if it is idle\r
2128 //\r
2129 if ( NULL != *ppFree ) {\r
2130 EslSocketTxStart ( pPort,\r
2131 ppQueueHead,\r
2132 ppQueueTail,\r
2133 ppActive,\r
2134 ppFree );\r
2135 }\r
2136 }\r
2137 else {\r
2138 //\r
2139 // Previous transmit error\r
2140 // Stop transmission\r
2141 //\r
2142 Status = pSocket->TxError;\r
2143 pSocket->errno = EIO;\r
2144\r
2145 //\r
2146 // Free the packet\r
2147 //\r
2148 EslSocketPacketFree ( pPacket, DEBUG_TX );\r
2149 }\r
2150\r
2151 //\r
2152 // Release the socket layer synchronization\r
2153 //\r
2154 RESTORE_TPL ( TplPrevious );\r
2155 }\r
2156 else {\r
2157 //\r
2158 // Packet allocation failed\r
2159 //\r
2160 pSocket->errno = ENOMEM;\r
2161 }\r
2162 }\r
2163 else {\r
2164 if ( !pPort->bTxFlowControl ) {\r
2165 DEBUG (( DEBUG_TX,\r
2166 "0x%08x: pPort, TX flow control applied, Max bytes %d <= %d bufferred bytes\r\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n",\r
2167 pPort,\r
2168 pSocket->MaxTxBuf,\r
2169 *pTxBytes ));\r
2170 pPort->bTxFlowControl = TRUE;\r
2171 }\r
2172 //\r
2173 // Not enough buffer space available\r
2174 //\r
2175 pSocket->errno = EAGAIN;\r
2176 Status = EFI_NOT_READY;\r
2177 }\r
2178 }\r
2179 }\r
2180\r
2181 //\r
2182 // Return the operation status\r
2183 //\r
2184 DBG_EXIT_STATUS ( Status );\r
2185 return Status;\r
2186}\r
2187\r
2188\r
2189/**\r
2190 Process the normal data transmit completion\r
2191\r
2192 This routine use ::EslSocketTxComplete to perform the transmit\r
2193 completion processing for normal data.\r
2194\r
2195 This routine is called by the TCPv6 network layer when a\r
2196 normal data transmit request completes.\r
2197\r
2198 @param [in] Event The normal transmit completion event\r
2199\r
2200 @param [in] pIo The ESL_IO_MGMT structure address\r
2201\r
2202**/\r
2203VOID\r
2204EslTcp6TxComplete (\r
2205 IN EFI_EVENT Event,\r
2206 IN ESL_IO_MGMT * pIo\r
2207 )\r
2208{\r
2209 UINT32 LengthInBytes;\r
2210 ESL_PACKET * pPacket;\r
2211 ESL_PORT * pPort;\r
2212 ESL_SOCKET * pSocket;\r
2213 EFI_STATUS Status;\r
2214 \r
2215 DBG_ENTER ( );\r
2216\r
2217 //\r
2218 // Locate the active transmit packet\r
2219 //\r
2220 pPacket = pIo->pPacket;\r
2221 pPort = pIo->pPort;\r
2222 pSocket = pPort->pSocket;\r
2223\r
2224 //\r
2225 // Get the transmit length and status\r
2226 //\r
2227 LengthInBytes = pPacket->Op.Tcp6Tx.TxData.DataLength;\r
2228 pSocket->TxBytes -= LengthInBytes;\r
2229 Status = pIo->Token.Tcp6Tx.CompletionToken.Status;\r
2230\r
2231 //\r
2232 // Complete the transmit operation\r
2233 //\r
2234 EslSocketTxComplete ( pIo,\r
2235 LengthInBytes,\r
2236 Status,\r
2237 "Normal ",\r
2238 &pSocket->pTxPacketListHead,\r
2239 &pSocket->pTxPacketListTail,\r
2240 &pPort->pTxActive,\r
2241 &pPort->pTxFree );\r
2242 DBG_EXIT ( );\r
2243}\r
2244\r
2245\r
2246/**\r
2247 Process the urgent data transmit completion\r
2248\r
2249 This routine use ::EslSocketTxComplete to perform the transmit\r
2250 completion processing for urgent data.\r
2251\r
2252 This routine is called by the TCPv6 network layer when a\r
2253 urgent data transmit request completes.\r
2254\r
2255 @param [in] Event The urgent transmit completion event\r
2256\r
2257 @param [in] pIo The ESL_IO_MGMT structure address\r
2258\r
2259**/\r
2260VOID\r
2261EslTcp6TxOobComplete (\r
2262 IN EFI_EVENT Event,\r
2263 IN ESL_IO_MGMT * pIo\r
2264 )\r
2265{\r
2266 UINT32 LengthInBytes;\r
2267 ESL_PACKET * pPacket;\r
2268 ESL_PORT * pPort;\r
2269 ESL_SOCKET * pSocket;\r
2270 EFI_STATUS Status;\r
2271\r
2272 DBG_ENTER ( );\r
2273\r
2274 //\r
2275 // Locate the active transmit packet\r
2276 //\r
2277 pPacket = pIo->pPacket;\r
2278 pPort = pIo->pPort;\r
2279 pSocket = pPort->pSocket;\r
2280\r
2281 //\r
2282 // Get the transmit length and status\r
2283 //\r
2284 LengthInBytes = pPacket->Op.Tcp6Tx.TxData.DataLength;\r
2285 pSocket->TxOobBytes -= LengthInBytes;\r
2286 Status = pIo->Token.Tcp6Tx.CompletionToken.Status;\r
2287\r
2288 //\r
2289 // Complete the transmit operation\r
2290 //\r
2291 EslSocketTxComplete ( pIo,\r
2292 LengthInBytes,\r
2293 Status,\r
2294 "Urgent ",\r
2295 &pSocket->pTxOobPacketListHead,\r
2296 &pSocket->pTxOobPacketListTail,\r
2297 &pPort->pTxOobActive,\r
2298 &pPort->pTxOobFree );\r
2299 DBG_EXIT ( );\r
2300}\r
2301\r
2302\r
2dc09dd5
LL
2303/**\r
2304 Verify the adapter's IP address\r
2305\r
2306 This support routine is called by EslSocketBindTest.\r
2307\r
2308 @param [in] pPort Address of an ::ESL_PORT structure.\r
2309 @param [in] pConfigData Address of the configuration data\r
2310\r
2311 @retval EFI_SUCCESS - The IP address is valid\r
2312 @retval EFI_NOT_STARTED - The IP address is invalid\r
2313\r
2314 **/\r
2315EFI_STATUS\r
2316EslTcp6VerifyLocalIpAddress (\r
2317 IN ESL_PORT * pPort,\r
2318 IN EFI_TCP6_CONFIG_DATA * pConfigData\r
2319 )\r
2320{\r
2321 UINTN AddressCount;\r
2322 EFI_IP6_ADDRESS_INFO * pAddressInfo;\r
2323 UINTN DataSize;\r
2324 EFI_TCP6_ACCESS_POINT * pAccess;\r
2325 EFI_IP6_CONFIG_INTERFACE_INFO * pIpConfigData;\r
2326 EFI_IP6_CONFIG_PROTOCOL * pIpConfigProtocol;\r
2327 ESL_SERVICE * pService;\r
2328 EFI_STATUS Status;\r
2329\r
2330 DBG_ENTER ( );\r
2331\r
2332 //\r
2333 // Use break instead of goto\r
2334 //\r
2335 pIpConfigData = NULL;\r
2336 for ( ; ; ) {\r
2337 //\r
2338 // Determine if the IP address is specified\r
2339 //\r
2340 pAccess = &pConfigData->AccessPoint;\r
2341 DEBUG (( DEBUG_BIND,\r
2342 "Requested IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
2343 pAccess->StationAddress.Addr[0],\r
2344 pAccess->StationAddress.Addr[1],\r
2345 pAccess->StationAddress.Addr[2],\r
2346 pAccess->StationAddress.Addr[3],\r
2347 pAccess->StationAddress.Addr[4],\r
2348 pAccess->StationAddress.Addr[5],\r
2349 pAccess->StationAddress.Addr[6],\r
2350 pAccess->StationAddress.Addr[7],\r
2351 pAccess->StationAddress.Addr[8],\r
2352 pAccess->StationAddress.Addr[9],\r
2353 pAccess->StationAddress.Addr[10],\r
2354 pAccess->StationAddress.Addr[11],\r
2355 pAccess->StationAddress.Addr[12],\r
2356 pAccess->StationAddress.Addr[13],\r
2357 pAccess->StationAddress.Addr[14],\r
2358 pAccess->StationAddress.Addr[15]));\r
2359 if (( 0 == pAccess->StationAddress.Addr [ 0 ])\r
2360 && ( 0 == pAccess->StationAddress.Addr [ 1 ])\r
2361 && ( 0 == pAccess->StationAddress.Addr [ 2 ])\r
2362 && ( 0 == pAccess->StationAddress.Addr [ 3 ])\r
2363 && ( 0 == pAccess->StationAddress.Addr [ 4 ])\r
2364 && ( 0 == pAccess->StationAddress.Addr [ 5 ])\r
2365 && ( 0 == pAccess->StationAddress.Addr [ 6 ])\r
2366 && ( 0 == pAccess->StationAddress.Addr [ 7 ])\r
2367 && ( 0 == pAccess->StationAddress.Addr [ 8 ])\r
2368 && ( 0 == pAccess->StationAddress.Addr [ 9 ])\r
2369 && ( 0 == pAccess->StationAddress.Addr [ 10 ])\r
2370 && ( 0 == pAccess->StationAddress.Addr [ 11 ])\r
2371 && ( 0 == pAccess->StationAddress.Addr [ 12 ])\r
2372 && ( 0 == pAccess->StationAddress.Addr [ 13 ])\r
2373 && ( 0 == pAccess->StationAddress.Addr [ 14 ])\r
2374 && ( 0 == pAccess->StationAddress.Addr [ 15 ]))\r
2375 {\r
2376 Status = EFI_SUCCESS;\r
2377 break;\r
2378 }\r
2379\r
2380 //\r
2381 // Open the configuration protocol\r
2382 //\r
2383 pService = pPort->pService;\r
2384 Status = gBS->OpenProtocol ( pService->Controller,\r
2385 &gEfiIp6ConfigProtocolGuid,\r
2386 (VOID **)&pIpConfigProtocol,\r
2387 NULL,\r
2388 NULL,\r
2389 EFI_OPEN_PROTOCOL_GET_PROTOCOL );\r
2390 if ( EFI_ERROR ( Status )) {\r
2391 DEBUG (( DEBUG_ERROR,\r
2392 "ERROR - IP Configuration Protocol not available, Status: %r\r\n",\r
2393 Status ));\r
2394 break;\r
2395 }\r
2396\r
2397 //\r
2398 // Get the IP configuration data size\r
2399 //\r
2400 DataSize = 0;\r
2401 Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
2402 Ip6ConfigDataTypeInterfaceInfo,\r
2403 &DataSize,\r
2404 NULL );\r
2405 if ( EFI_BUFFER_TOO_SMALL != Status ) {\r
2406 DEBUG (( DEBUG_ERROR,\r
2407 "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",\r
2408 Status ));\r
2409 break;\r
2410 }\r
2411\r
2412 //\r
2413 // Allocate the configuration data buffer\r
2414 //\r
2415 pIpConfigData = AllocatePool ( DataSize );\r
2416 if ( NULL == pIpConfigData ) {\r
2417 DEBUG (( DEBUG_ERROR,\r
2418 "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));\r
2419 Status = EFI_OUT_OF_RESOURCES;\r
2420 break;\r
2421 }\r
2422\r
2423 //\r
2424 // Get the IP configuration\r
2425 //\r
2426 Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
2427 Ip6ConfigDataTypeInterfaceInfo,\r
2428 &DataSize,\r
2429 pIpConfigData );\r
2430 if ( EFI_ERROR ( Status )) {\r
2431 DEBUG (( DEBUG_ERROR,\r
2432 "ERROR - Failed to return IP Configuration data, Status: %r\r\n",\r
2433 Status ));\r
2434 break;\r
2435 }\r
2436\r
2437 //\r
2438 // Display the current configuration\r
2439 //\r
2440 DEBUG (( DEBUG_BIND,\r
2441 "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
2442 pIpConfigData->HwAddress.Addr [ 0 ],\r
2443 pIpConfigData->HwAddress.Addr [ 1 ],\r
2444 pIpConfigData->HwAddress.Addr [ 2 ],\r
2445 pIpConfigData->HwAddress.Addr [ 3 ],\r
2446 pIpConfigData->HwAddress.Addr [ 4 ],\r
2447 pIpConfigData->HwAddress.Addr [ 5 ],\r
2448 pIpConfigData->HwAddress.Addr [ 6 ],\r
2449 pIpConfigData->HwAddress.Addr [ 7 ],\r
2450 pIpConfigData->HwAddress.Addr [ 8 ],\r
2451 pIpConfigData->HwAddress.Addr [ 9 ],\r
2452 pIpConfigData->HwAddress.Addr [ 10 ],\r
2453 pIpConfigData->HwAddress.Addr [ 11 ],\r
2454 pIpConfigData->HwAddress.Addr [ 12 ],\r
2455 pIpConfigData->HwAddress.Addr [ 13 ],\r
2456 pIpConfigData->HwAddress.Addr [ 14 ],\r
2457 pIpConfigData->HwAddress.Addr [ 15 ]));\r
2458\r
2459 //\r
2460 // Validate the hardware address\r
2461 //\r
2462 Status = EFI_SUCCESS;\r
2463 if (( 16 == pIpConfigData->HwAddressSize )\r
2464 && ( pAccess->StationAddress.Addr [ 0 ] == pIpConfigData->HwAddress.Addr [ 0 ])\r
2465 && ( pAccess->StationAddress.Addr [ 1 ] == pIpConfigData->HwAddress.Addr [ 1 ])\r
2466 && ( pAccess->StationAddress.Addr [ 2 ] == pIpConfigData->HwAddress.Addr [ 2 ])\r
2467 && ( pAccess->StationAddress.Addr [ 3 ] == pIpConfigData->HwAddress.Addr [ 3 ])\r
2468 && ( pAccess->StationAddress.Addr [ 4 ] == pIpConfigData->HwAddress.Addr [ 4 ])\r
2469 && ( pAccess->StationAddress.Addr [ 5 ] == pIpConfigData->HwAddress.Addr [ 5 ])\r
2470 && ( pAccess->StationAddress.Addr [ 6 ] == pIpConfigData->HwAddress.Addr [ 6 ])\r
2471 && ( pAccess->StationAddress.Addr [ 7 ] == pIpConfigData->HwAddress.Addr [ 7 ])\r
2472 && ( pAccess->StationAddress.Addr [ 8 ] == pIpConfigData->HwAddress.Addr [ 8 ])\r
2473 && ( pAccess->StationAddress.Addr [ 9 ] == pIpConfigData->HwAddress.Addr [ 9 ])\r
2474 && ( pAccess->StationAddress.Addr [ 10 ] == pIpConfigData->HwAddress.Addr [ 10 ])\r
2475 && ( pAccess->StationAddress.Addr [ 11 ] == pIpConfigData->HwAddress.Addr [ 11 ])\r
2476 && ( pAccess->StationAddress.Addr [ 12 ] == pIpConfigData->HwAddress.Addr [ 12 ])\r
2477 && ( pAccess->StationAddress.Addr [ 13 ] == pIpConfigData->HwAddress.Addr [ 13 ])\r
2478 && ( pAccess->StationAddress.Addr [ 14 ] == pIpConfigData->HwAddress.Addr [ 14 ])\r
2479 && ( pAccess->StationAddress.Addr [ 15 ] == pIpConfigData->HwAddress.Addr [ 15 ])) {\r
2480 break;\r
2481 }\r
2482\r
2483 //\r
2484 // Walk the list of other IP addresses assigned to this adapter\r
2485 //\r
2486 for ( AddressCount = 0; pIpConfigData->AddressInfoCount > AddressCount; AddressCount += 1 ) {\r
2487 pAddressInfo = &pIpConfigData->AddressInfo [ AddressCount ];\r
2488\r
2489 //\r
2490 // Display the IP address\r
2491 //\r
2492 DEBUG (( DEBUG_BIND,\r
2493 "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
2494 pAddressInfo->Address.Addr [ 0 ],\r
2495 pAddressInfo->Address.Addr [ 1 ],\r
2496 pAddressInfo->Address.Addr [ 2 ],\r
2497 pAddressInfo->Address.Addr [ 3 ],\r
2498 pAddressInfo->Address.Addr [ 4 ],\r
2499 pAddressInfo->Address.Addr [ 5 ],\r
2500 pAddressInfo->Address.Addr [ 6 ],\r
2501 pAddressInfo->Address.Addr [ 7 ],\r
2502 pAddressInfo->Address.Addr [ 8 ],\r
2503 pAddressInfo->Address.Addr [ 9 ],\r
2504 pAddressInfo->Address.Addr [ 10 ],\r
2505 pAddressInfo->Address.Addr [ 11 ],\r
2506 pAddressInfo->Address.Addr [ 12 ],\r
2507 pAddressInfo->Address.Addr [ 13 ],\r
2508 pAddressInfo->Address.Addr [ 14 ],\r
2509 pAddressInfo->Address.Addr [ 15 ]));\r
2510\r
2511 //\r
2512 // Validate the IP address\r
2513 //\r
2514 if (( pAccess->StationAddress.Addr [ 0 ] == pAddressInfo->Address.Addr [ 0 ])\r
2515 && ( pAccess->StationAddress.Addr [ 1 ] == pAddressInfo->Address.Addr [ 1 ])\r
2516 && ( pAccess->StationAddress.Addr [ 2 ] == pAddressInfo->Address.Addr [ 2 ])\r
2517 && ( pAccess->StationAddress.Addr [ 3 ] == pAddressInfo->Address.Addr [ 3 ])\r
2518 && ( pAccess->StationAddress.Addr [ 4 ] == pAddressInfo->Address.Addr [ 4 ])\r
2519 && ( pAccess->StationAddress.Addr [ 5 ] == pAddressInfo->Address.Addr [ 5 ])\r
2520 && ( pAccess->StationAddress.Addr [ 6 ] == pAddressInfo->Address.Addr [ 6 ])\r
2521 && ( pAccess->StationAddress.Addr [ 7 ] == pAddressInfo->Address.Addr [ 7 ])\r
2522 && ( pAccess->StationAddress.Addr [ 8 ] == pAddressInfo->Address.Addr [ 8 ])\r
2523 && ( pAccess->StationAddress.Addr [ 9 ] == pAddressInfo->Address.Addr [ 9 ])\r
2524 && ( pAccess->StationAddress.Addr [ 10 ] == pAddressInfo->Address.Addr [ 10 ])\r
2525 && ( pAccess->StationAddress.Addr [ 11 ] == pAddressInfo->Address.Addr [ 11 ])\r
2526 && ( pAccess->StationAddress.Addr [ 12 ] == pAddressInfo->Address.Addr [ 12 ])\r
2527 && ( pAccess->StationAddress.Addr [ 13 ] == pAddressInfo->Address.Addr [ 13 ])\r
2528 && ( pAccess->StationAddress.Addr [ 14 ] == pAddressInfo->Address.Addr [ 14 ])\r
2529 && ( pAccess->StationAddress.Addr [ 15 ] == pAddressInfo->Address.Addr [ 15 ])) {\r
2530 break;\r
2531 }\r
2532 }\r
2533 if ( pIpConfigData->AddressInfoCount > AddressCount ) {\r
2534 break;\r
2535 }\r
2536\r
2537 //\r
2538 // The IP address did not match\r
2539 //\r
2540 Status = EFI_NOT_STARTED;\r
2541 break;\r
2542 }\r
2543\r
2544 //\r
2545 // Free the buffer if necessary\r
2546 //\r
2547 if ( NULL != pIpConfigData ) {\r
2548 FreePool ( pIpConfigData );\r
2549 }\r
2550\r
2551 //\r
2552 // Return the IP address status\r
2553 //\r
2554 DBG_EXIT_STATUS ( Status );\r
2555 return Status;\r
2556}\r
2557\r
2558\r
3bdf9aae 2559/**\r
2560 Interface between the socket layer and the network specific\r
2561 code that supports SOCK_STREAM and SOCK_SEQPACKET sockets\r
2562 over TCPv6.\r
2563**/\r
2564CONST ESL_PROTOCOL_API cEslTcp6Api = {\r
2565 "TCPv6",\r
2566 IPPROTO_TCP,\r
2567 OFFSET_OF ( ESL_PORT, Context.Tcp6.ConfigData ),\r
2568 OFFSET_OF ( ESL_LAYER, pTcp6List ),\r
2569 sizeof ( struct sockaddr_in6 ),\r
2570 sizeof ( struct sockaddr_in6 ),\r
2571 AF_INET6,\r
2572 sizeof (((ESL_PACKET *)0 )->Op.Tcp6Rx ),\r
2573 OFFSET_OF ( ESL_PACKET, Op.Tcp6Rx.Buffer ) - OFFSET_OF ( ESL_PACKET, Op ),\r
2574 OFFSET_OF ( ESL_IO_MGMT, Token.Tcp6Rx.Packet.RxData ),\r
2575 TRUE,\r
2576 EADDRINUSE,\r
2577 EslTcp6Accept,\r
2578 EslTcp6ConnectPoll,\r
2579 EslTcp6ConnectStart,\r
2580 EslTcp6SocketIsConfigured,\r
2581 EslTcp6LocalAddressGet,\r
2582 EslTcp6LocalAddressSet,\r
2583 EslTcp6Listen,\r
2584 NULL, // OptionGet\r
2585 NULL, // OptionSet\r
2586 EslTcp6PacketFree,\r
2587 EslTcp6PortAllocate,\r
2588 EslTcp6PortClose,\r
2589 EslTcp6PortCloseOp,\r
2590 FALSE,\r
2591 EslTcp6Receive,\r
2592 EslTcp6RemoteAddressGet,\r
2593 EslTcp6RemoteAddressSet,\r
2594 EslTcp6RxComplete,\r
2595 EslTcp6RxStart,\r
2596 EslTcp6TxBuffer,\r
2597 EslTcp6TxComplete,\r
2dc09dd5 2598 EslTcp6TxOobComplete,\r
a93b0f45 2599 (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslTcp6VerifyLocalIpAddress\r
3bdf9aae 2600};\r