]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/EfiSocketLib/Udp6.c
StdLib: Remove EfiSocketLib and Ip4Config Protocol dependency.
[mirror_edk2.git] / StdLib / EfiSocketLib / Udp6.c
CommitLineData
3bdf9aae 1/** @file\r
2 Implement the UDP4 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\r
15#include "Socket.h"\r
16\r
17\r
18/**\r
19 Get the local socket address\r
20\r
21 This routine returns the IPv6 address and UDP port number associated\r
22 with the local socket.\r
23\r
24 This routine is called by ::EslSocketGetLocalAddress to determine the\r
25 network address for the SOCK_DGRAM socket.\r
26\r
27 @param [in] pPort Address of an ::ESL_PORT structure.\r
28\r
29 @param [out] pSockAddr Network address to receive the local system address\r
30\r
31**/\r
32VOID\r
33EslUdp6LocalAddressGet (\r
34 IN ESL_PORT * pPort,\r
35 OUT struct sockaddr * pSockAddr\r
36 )\r
37{\r
38 struct sockaddr_in6 * pLocalAddress;\r
39 ESL_UDP6_CONTEXT * pUdp6;\r
40\r
41 DBG_ENTER ( );\r
42\r
43 //\r
44 // Return the local address\r
45 //\r
46 pUdp6 = &pPort->Context.Udp6;\r
47 pLocalAddress = (struct sockaddr_in6 *)pSockAddr;\r
48 pLocalAddress->sin6_family = AF_INET6;\r
49 pLocalAddress->sin6_port = SwapBytes16 ( pUdp6->ConfigData.StationPort );\r
50 CopyMem ( &pLocalAddress->sin6_addr,\r
51 &pUdp6->ConfigData.StationAddress.Addr[0],\r
52 sizeof ( pLocalAddress->sin6_addr ));\r
53\r
54 DBG_EXIT ( );\r
55}\r
56\r
57\r
58/**\r
59 Set the local port address.\r
60\r
61 This routine sets the local port address.\r
62\r
63 This support routine is called by ::EslSocketPortAllocate.\r
64\r
65 @param [in] pPort Address of an ESL_PORT structure\r
66 @param [in] pSockAddr Address of a sockaddr structure that contains the\r
67 connection point on the local machine. An IPv6 address\r
68 of INADDR_ANY specifies that the connection is made to\r
69 all of the network stacks on the platform. Specifying a\r
70 specific IPv6 address restricts the connection to the\r
71 network stack supporting that address. Specifying zero\r
72 for the port causes the network layer to assign a port\r
73 number from the dynamic range. Specifying a specific\r
74 port number causes the network layer to use that port.\r
75\r
76 @param [in] bBindTest TRUE = run bind testing\r
77\r
78 @retval EFI_SUCCESS The operation was successful\r
79\r
80 **/\r
81EFI_STATUS\r
82EslUdp6LocalAddressSet (\r
83 IN ESL_PORT * pPort,\r
84 IN CONST struct sockaddr * pSockAddr,\r
85 IN BOOLEAN bBindTest\r
86 )\r
87{\r
88 EFI_UDP6_CONFIG_DATA * pConfig;\r
89 CONST struct sockaddr_in6 * pIpAddress;\r
90 CONST UINT8 * pIPv6Address;\r
91 EFI_STATUS Status;\r
92\r
93 DBG_ENTER ( );\r
94\r
95 //\r
96 // Set the local address\r
97 //\r
98 pIpAddress = (struct sockaddr_in6 *)pSockAddr;\r
99 pIPv6Address = (UINT8 *)&pIpAddress->sin6_addr;\r
100 pConfig = &pPort->Context.Udp6.ConfigData;\r
101 CopyMem ( &pConfig->StationAddress,\r
102 pIPv6Address,\r
103 sizeof ( pConfig->StationAddress ));\r
104\r
105 //\r
106 // Validate the IP address\r
107 //\r
108 pConfig->StationPort = 0;\r
109 Status = bBindTest ? EslSocketBindTest ( pPort, EADDRNOTAVAIL )\r
110 : EFI_SUCCESS;\r
111 if ( !EFI_ERROR ( Status )) {\r
112 //\r
113 // Set the port number\r
114 //\r
115 pConfig->StationPort = SwapBytes16 ( pIpAddress->sin6_port );\r
f74dc4bb 116 pPort->pSocket->bAddressSet = TRUE;\r
3bdf9aae 117\r
118 //\r
119 // Display the local address\r
120 //\r
121 DEBUG (( DEBUG_BIND,\r
122 "0x%08x: Port, Local UDP6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
123 pPort,\r
124 pConfig->StationAddress.Addr[0],\r
125 pConfig->StationAddress.Addr[1],\r
126 pConfig->StationAddress.Addr[2],\r
127 pConfig->StationAddress.Addr[3],\r
128 pConfig->StationAddress.Addr[4],\r
129 pConfig->StationAddress.Addr[5],\r
130 pConfig->StationAddress.Addr[6],\r
131 pConfig->StationAddress.Addr[7],\r
132 pConfig->StationAddress.Addr[8],\r
133 pConfig->StationAddress.Addr[9],\r
134 pConfig->StationAddress.Addr[10],\r
135 pConfig->StationAddress.Addr[11],\r
136 pConfig->StationAddress.Addr[12],\r
137 pConfig->StationAddress.Addr[13],\r
138 pConfig->StationAddress.Addr[14],\r
139 pConfig->StationAddress.Addr[15],\r
140 pConfig->StationPort ));\r
141 }\r
142\r
143 //\r
144 // Return the operation status\r
145 //\r
146 DBG_EXIT_STATUS ( Status );\r
147 return Status;\r
148}\r
149\r
150\r
151/**\r
152 Free a receive packet\r
153\r
154 This routine performs the network specific operations necessary\r
155 to free a receive packet.\r
156\r
157 This routine is called by ::EslSocketPortCloseTxDone to free a\r
158 receive packet.\r
159\r
160 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
161 @param [in, out] pRxBytes Address of the count of RX bytes\r
162\r
163**/\r
164VOID\r
165EslUdp6PacketFree (\r
166 IN ESL_PACKET * pPacket,\r
167 IN OUT size_t * pRxBytes\r
168 )\r
169{\r
170 EFI_UDP6_RECEIVE_DATA * pRxData;\r
171\r
172 DBG_ENTER ( );\r
173\r
174 //\r
175 // Account for the receive bytes\r
176 //\r
177 pRxData = pPacket->Op.Udp6Rx.pRxData;\r
178 *pRxBytes -= pRxData->DataLength;\r
179\r
180 //\r
181 // Disconnect the buffer from the packet\r
182 //\r
183 pPacket->Op.Udp6Rx.pRxData = NULL;\r
184\r
185 //\r
186 // Return the buffer to the UDP6 driver\r
187 //\r
188 gBS->SignalEvent ( pRxData->RecycleSignal );\r
189 DBG_EXIT ( );\r
190}\r
191\r
192\r
193/**\r
194 Initialize the network specific portions of an ::ESL_PORT structure.\r
195\r
196 This routine initializes the network specific portions of an\r
197 ::ESL_PORT structure for use by the socket.\r
198\r
199 This support routine is called by ::EslSocketPortAllocate\r
200 to connect the socket with the underlying network adapter\r
201 running the UDPv4 protocol.\r
202\r
203 @param [in] pPort Address of an ESL_PORT structure\r
204 @param [in] DebugFlags Flags for debug messages\r
205\r
206 @retval EFI_SUCCESS - Socket successfully created\r
207\r
208 **/\r
209EFI_STATUS\r
210EslUdp6PortAllocate (\r
211 IN ESL_PORT * pPort,\r
212 IN UINTN DebugFlags\r
213 )\r
214{\r
215 EFI_UDP6_CONFIG_DATA * pConfig;\r
216 ESL_SOCKET * pSocket;\r
217 EFI_STATUS Status;\r
218\r
219 DBG_ENTER ( );\r
220\r
221 //\r
222 // Initialize the port\r
223 //\r
224 pSocket = pPort->pSocket;\r
225 pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Udp6Tx.TxData );\r
226 pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Udp6Tx.Event );\r
227 pSocket->TxTokenOffset = OFFSET_OF ( EFI_UDP6_COMPLETION_TOKEN, Packet.TxData );\r
228\r
229 //\r
230 // Save the cancel, receive and transmit addresses\r
231 //\r
232 pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.UDPv6->Configure;\r
233 pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Cancel;\r
234 pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.UDPv6->Poll;\r
235 pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Receive;\r
236 pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv6->Transmit;\r
237\r
238 //\r
239 // Do not drop packets\r
240 //\r
241 pConfig = &pPort->Context.Udp6.ConfigData;\r
242 pConfig->ReceiveTimeout = 0;\r
243 pConfig->ReceiveTimeout = pConfig->ReceiveTimeout;\r
244\r
245 //\r
246 // Set the configuration flags\r
247 //\r
248 pConfig->AllowDuplicatePort = TRUE;\r
249 pConfig->AcceptAnyPort = FALSE;\r
250 pConfig->AcceptPromiscuous = FALSE;\r
251 pConfig->HopLimit = 255;\r
252 pConfig->TrafficClass = 0;\r
253\r
254 Status = EFI_SUCCESS;\r
255\r
256 //\r
257 // Return the operation status\r
258 //\r
259 DBG_EXIT_STATUS ( Status );\r
260 return Status;\r
261}\r
262\r
263\r
264/**\r
265 Receive data from a network connection.\r
266\r
267 This routine attempts to return buffered data to the caller. The\r
268 data is removed from the urgent queue if the message flag MSG_OOB\r
269 is specified, otherwise data is removed from the normal queue.\r
270 See the \ref ReceiveEngine section.\r
271\r
272 This routine is called by ::EslSocketReceive to handle the network\r
273 specific receive operation to support SOCK_DGRAM sockets.\r
274\r
275 @param [in] pPort Address of an ::ESL_PORT structure.\r
276\r
277 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
278 \r
279 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed\r
280 \r
281 @param [in] BufferLength Length of the the buffer\r
282 \r
283 @param [in] pBuffer Address of a buffer to receive the data.\r
284 \r
285 @param [in] pDataLength Number of received data bytes in the buffer.\r
286\r
287 @param [out] pAddress Network address to receive the remote system address\r
288\r
289 @param [out] pSkipBytes Address to receive the number of bytes skipped\r
290\r
291 @return Returns the address of the next free byte in the buffer.\r
292\r
293 **/\r
294UINT8 *\r
295EslUdp6Receive (\r
296 IN ESL_PORT * pPort,\r
297 IN ESL_PACKET * pPacket,\r
298 IN BOOLEAN * pbConsumePacket,\r
299 IN size_t BufferLength,\r
300 IN UINT8 * pBuffer,\r
301 OUT size_t * pDataLength,\r
302 OUT struct sockaddr * pAddress,\r
303 OUT size_t * pSkipBytes\r
304 )\r
305{\r
306 size_t DataBytes;\r
307 struct sockaddr_in6 * pRemoteAddress;\r
308 EFI_UDP6_RECEIVE_DATA * pRxData;\r
309\r
310 DBG_ENTER ( );\r
311\r
312 pRxData = pPacket->Op.Udp6Rx.pRxData;\r
313 //\r
314 // Return the remote system address if requested\r
315 //\r
316 if ( NULL != pAddress ) {\r
317 //\r
318 // Build the remote address\r
319 //\r
320 DEBUG (( DEBUG_RX,\r
321 "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
322 pRxData->UdpSession.SourceAddress.Addr[0],\r
323 pRxData->UdpSession.SourceAddress.Addr[1],\r
324 pRxData->UdpSession.SourceAddress.Addr[2],\r
325 pRxData->UdpSession.SourceAddress.Addr[3],\r
326 pRxData->UdpSession.SourceAddress.Addr[4],\r
327 pRxData->UdpSession.SourceAddress.Addr[5],\r
328 pRxData->UdpSession.SourceAddress.Addr[6],\r
329 pRxData->UdpSession.SourceAddress.Addr[7],\r
330 pRxData->UdpSession.SourceAddress.Addr[8],\r
331 pRxData->UdpSession.SourceAddress.Addr[9],\r
332 pRxData->UdpSession.SourceAddress.Addr[10],\r
333 pRxData->UdpSession.SourceAddress.Addr[11],\r
334 pRxData->UdpSession.SourceAddress.Addr[12],\r
335 pRxData->UdpSession.SourceAddress.Addr[13],\r
336 pRxData->UdpSession.SourceAddress.Addr[14],\r
337 pRxData->UdpSession.SourceAddress.Addr[15],\r
338 pRxData->UdpSession.SourcePort ));\r
339 pRemoteAddress = (struct sockaddr_in6 *)pAddress;\r
340 CopyMem ( &pRemoteAddress->sin6_addr,\r
341 &pRxData->UdpSession.SourceAddress.Addr[0],\r
342 sizeof ( pRemoteAddress->sin6_addr ));\r
343 pRemoteAddress->sin6_port = SwapBytes16 ( pRxData->UdpSession.SourcePort );\r
344 }\r
345\r
346 //\r
347 // Copy the received data\r
348 //\r
349 pBuffer = EslSocketCopyFragmentedBuffer ( pRxData->FragmentCount,\r
350 (EFI_IP4_FRAGMENT_DATA *)&pRxData->FragmentTable[0],\r
351 BufferLength,\r
352 pBuffer,\r
353 &DataBytes );\r
354\r
355 //\r
356 // Determine if the data is being read\r
357 //\r
358 if ( *pbConsumePacket ) {\r
359 //\r
360 // Display for the bytes consumed\r
361 //\r
362 DEBUG (( DEBUG_RX,\r
363 "0x%08x: Port account for 0x%08x bytes\r\n",\r
364 pPort,\r
365 DataBytes ));\r
366\r
367 //\r
368 // Account for any discarded data\r
369 //\r
370 *pSkipBytes = pRxData->DataLength - DataBytes;\r
371 }\r
372\r
373 //\r
374 // Return the data length and the buffer address\r
375 //\r
376 *pDataLength = DataBytes;\r
377 DBG_EXIT_HEX ( pBuffer );\r
378 return pBuffer;\r
379}\r
380\r
381\r
382/**\r
383 Get the remote socket address\r
384\r
385 This routine returns the address of the remote connection point\r
386 associated with the SOCK_DGRAM socket.\r
387\r
388 This routine is called by ::EslSocketGetPeerAddress to detemine\r
389 the UDPv4 address and port number associated with the network adapter.\r
390\r
391 @param [in] pPort Address of an ::ESL_PORT structure.\r
392\r
393 @param [out] pAddress Network address to receive the remote system address\r
394\r
395**/\r
396VOID\r
397EslUdp6RemoteAddressGet (\r
398 IN ESL_PORT * pPort,\r
399 OUT struct sockaddr * pAddress\r
400 )\r
401{\r
402 struct sockaddr_in6 * pRemoteAddress;\r
403 ESL_UDP6_CONTEXT * pUdp6;\r
404\r
405 DBG_ENTER ( );\r
406\r
407 //\r
408 // Return the remote address\r
409 //\r
410 pUdp6 = &pPort->Context.Udp6;\r
411 pRemoteAddress = (struct sockaddr_in6 *)pAddress;\r
412 pRemoteAddress->sin6_family = AF_INET6;\r
413 pRemoteAddress->sin6_port = SwapBytes16 ( pUdp6->ConfigData.RemotePort );\r
414 CopyMem ( &pRemoteAddress->sin6_addr,\r
415 &pUdp6->ConfigData.RemoteAddress.Addr[0],\r
416 sizeof ( pRemoteAddress->sin6_addr ));\r
417\r
418 DBG_EXIT ( );\r
419}\r
420\r
421\r
422/**\r
423 Set the remote address\r
424\r
425 This routine sets the remote address in the port.\r
426\r
427 This routine is called by ::EslSocketConnect to specify the\r
428 remote network address.\r
429\r
430 @param [in] pPort Address of an ::ESL_PORT structure.\r
431\r
432 @param [in] pSockAddr Network address of the remote system.\r
433\r
434 @param [in] SockAddrLength Length in bytes of the network address.\r
435\r
436 @retval EFI_SUCCESS The operation was successful\r
437\r
438 **/\r
439EFI_STATUS\r
440EslUdp6RemoteAddressSet (\r
441 IN ESL_PORT * pPort,\r
442 IN CONST struct sockaddr * pSockAddr,\r
443 IN socklen_t SockAddrLength\r
444 )\r
445{\r
446 CONST struct sockaddr_in6 * pRemoteAddress;\r
447 ESL_UDP6_CONTEXT * pUdp6;\r
448 EFI_STATUS Status;\r
449\r
450 DBG_ENTER ( );\r
451\r
452 //\r
453 // Set the remote address\r
454 //\r
455 pUdp6 = &pPort->Context.Udp6;\r
456 pRemoteAddress = (struct sockaddr_in6 *)pSockAddr;\r
457 CopyMem ( &pUdp6->ConfigData.RemoteAddress,\r
458 &pRemoteAddress->sin6_addr,\r
459 sizeof ( pUdp6->ConfigData.RemoteAddress ));\r
460 pUdp6->ConfigData.RemotePort = SwapBytes16 ( pRemoteAddress->sin6_port );\r
461 Status = EFI_SUCCESS;\r
462\r
463 //\r
464 // Return the operation status\r
465 //\r
466 DBG_EXIT_STATUS ( Status );\r
467 return Status;\r
468}\r
469\r
470\r
471/**\r
472 Process the receive completion\r
473\r
474 This routine keeps the UDPv4 driver's buffer and queues it in\r
475 in FIFO order to the data queue. The UDP6 driver's buffer will\r
476 be returned by either ::EslUdp6Receive or ::EslSocketPortCloseTxDone.\r
477 See the \ref ReceiveEngine section.\r
478\r
479 This routine is called by the UDPv4 driver when data is\r
480 received.\r
481\r
482 @param [in] Event The receive completion event\r
483\r
484 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
485\r
486**/\r
487VOID\r
488EslUdp6RxComplete (\r
489 IN EFI_EVENT Event,\r
490 IN ESL_IO_MGMT * pIo\r
491 )\r
492{\r
493 size_t LengthInBytes;\r
494 ESL_PACKET * pPacket;\r
495 EFI_UDP6_RECEIVE_DATA * pRxData;\r
496 EFI_STATUS Status;\r
497 \r
498 DBG_ENTER ( );\r
499\r
500 //\r
501 // Get the operation status.\r
502 //\r
503 Status = pIo->Token.Udp6Rx.Status;\r
504 \r
505 //\r
506 // Get the packet length\r
507 //\r
508 pRxData = pIo->Token.Udp6Rx.Packet.RxData;\r
509 LengthInBytes = pRxData->DataLength;\r
510\r
511 //\r
512 // +--------------------+ +-----------------------+\r
513 // | ESL_IO_MGMT | | Data Buffer |\r
514 // | | | (Driver owned) |\r
515 // | +---------------+ +-----------------------+\r
516 // | | Token | ^\r
517 // | | Rx Event | |\r
518 // | | | +-----------------------+\r
519 // | | RxData --> | EFI_UDP6_RECEIVE_DATA |\r
520 // +----+---------------+ | (Driver owned) |\r
521 // +-----------------------+\r
522 // +--------------------+ ^\r
523 // | ESL_PACKET | .\r
524 // | | .\r
525 // | +---------------+ .\r
526 // | | pRxData --> NULL .......\r
527 // +----+---------------+\r
528 //\r
529 //\r
530 // Save the data in the packet\r
531 //\r
532 pPacket = pIo->pPacket;\r
533 pPacket->Op.Udp6Rx.pRxData = pRxData;\r
534\r
535 //\r
536 // Complete this request\r
537 //\r
538 EslSocketRxComplete ( pIo, Status, LengthInBytes, FALSE );\r
539 DBG_EXIT ( );\r
540}\r
541\r
542\r
543/**\r
544 Determine if the socket is configured.\r
545\r
546 This routine uses the flag ESL_SOCKET::bConfigured to determine\r
547 if the network layer's configuration routine has been called.\r
548 This routine calls the bind and configuration routines if they\r
549 were not already called. After the port is configured, the\r
550 \ref ReceiveEngine is started.\r
551\r
552 This routine is called by EslSocketIsConfigured to verify\r
553 that the socket is configured.\r
554\r
555 @param [in] pSocket Address of an ::ESL_SOCKET structure\r
556\r
557 @retval EFI_SUCCESS - The port is connected\r
558 @retval EFI_NOT_STARTED - The port is not connected\r
559\r
560 **/\r
561 EFI_STATUS\r
562 EslUdp6SocketIsConfigured (\r
563 IN ESL_SOCKET * pSocket\r
564 )\r
565{\r
566 EFI_UDP6_CONFIG_DATA * pConfigData;\r
567 ESL_PORT * pPort;\r
568 ESL_PORT * pNextPort;\r
569 ESL_UDP6_CONTEXT * pUdp6;\r
570 EFI_UDP6_PROTOCOL * pUdp6Protocol;\r
571 EFI_STATUS Status;\r
572 struct sockaddr_in6 LocalAddress;\r
573\r
574 DBG_ENTER ( );\r
575\r
576 //\r
577 // Assume success\r
578 //\r
579 Status = EFI_SUCCESS;\r
580\r
581 //\r
582 // Configure the port if necessary\r
583 //\r
584 if ( !pSocket->bConfigured ) {\r
585 //\r
586 // Fill in the port list if necessary\r
587 //\r
bb3aa953 588 pSocket->errno = ENETDOWN;\r
3bdf9aae 589 if ( NULL == pSocket->pPortList ) {\r
590 ZeroMem ( &LocalAddress, sizeof ( LocalAddress ));\r
591 LocalAddress.sin6_len = sizeof ( LocalAddress );\r
592 LocalAddress.sin6_family = AF_INET6;\r
593 Status = EslSocketBind ( &pSocket->SocketProtocol,\r
594 (struct sockaddr *)&LocalAddress,\r
595 LocalAddress.sin6_len,\r
596 &pSocket->errno );\r
597 }\r
598\r
599 //\r
600 // Walk the port list\r
601 //\r
602 pPort = pSocket->pPortList;\r
603 while ( NULL != pPort ) {\r
604 //\r
605 // Attempt to configure the port\r
606 //\r
607 pNextPort = pPort->pLinkSocket;\r
608 pUdp6 = &pPort->Context.Udp6;\r
609 pUdp6Protocol = pPort->pProtocol.UDPv6;\r
610 pConfigData = &pUdp6->ConfigData;\r
611 DEBUG (( DEBUG_TX,\r
2dc09dd5 612 "0x%08x: pPort Configuring for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> ",\r
3bdf9aae 613 pPort,\r
614 pConfigData->StationAddress.Addr[0],\r
615 pConfigData->StationAddress.Addr[1],\r
616 pConfigData->StationAddress.Addr[2],\r
617 pConfigData->StationAddress.Addr[3],\r
618 pConfigData->StationAddress.Addr[4],\r
619 pConfigData->StationAddress.Addr[5],\r
620 pConfigData->StationAddress.Addr[6],\r
621 pConfigData->StationAddress.Addr[7],\r
622 pConfigData->StationAddress.Addr[8],\r
623 pConfigData->StationAddress.Addr[9],\r
624 pConfigData->StationAddress.Addr[10],\r
625 pConfigData->StationAddress.Addr[11],\r
626 pConfigData->StationAddress.Addr[12],\r
627 pConfigData->StationAddress.Addr[13],\r
628 pConfigData->StationAddress.Addr[14],\r
629 pConfigData->StationAddress.Addr[15],\r
2dc09dd5
LL
630 pConfigData->StationPort ));\r
631 DEBUG (( DEBUG_TX,\r
632 "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
3bdf9aae 633 pConfigData->RemoteAddress.Addr[0],\r
634 pConfigData->RemoteAddress.Addr[1],\r
635 pConfigData->RemoteAddress.Addr[2],\r
636 pConfigData->RemoteAddress.Addr[3],\r
637 pConfigData->RemoteAddress.Addr[4],\r
638 pConfigData->RemoteAddress.Addr[5],\r
639 pConfigData->RemoteAddress.Addr[6],\r
640 pConfigData->RemoteAddress.Addr[7],\r
641 pConfigData->RemoteAddress.Addr[8],\r
642 pConfigData->RemoteAddress.Addr[9],\r
643 pConfigData->RemoteAddress.Addr[10],\r
644 pConfigData->RemoteAddress.Addr[11],\r
645 pConfigData->RemoteAddress.Addr[12],\r
646 pConfigData->RemoteAddress.Addr[13],\r
647 pConfigData->RemoteAddress.Addr[14],\r
648 pConfigData->RemoteAddress.Addr[15],\r
649 pConfigData->RemotePort ));\r
650 Status = pUdp6Protocol->Configure ( pUdp6Protocol,\r
651 pConfigData );\r
652 if ( !EFI_ERROR ( Status )) {\r
653 //\r
654 // Update the configuration data\r
655 //\r
656 Status = pUdp6Protocol->GetModeData ( pUdp6Protocol,\r
657 pConfigData,\r
658 NULL,\r
659 NULL,\r
660 NULL );\r
661 }\r
662 if ( EFI_ERROR ( Status )) {\r
bb3aa953 663 if ( !pSocket->bConfigured ) {\r
664 DEBUG (( DEBUG_LISTEN,\r
665 "ERROR - Failed to configure the Udp6 port, Status: %r\r\n",\r
666 Status ));\r
667 switch ( Status ) {\r
668 case EFI_ACCESS_DENIED:\r
669 pSocket->errno = EACCES;\r
670 break;\r
671\r
672 default:\r
673 case EFI_DEVICE_ERROR:\r
674 pSocket->errno = EIO;\r
675 break;\r
676\r
677 case EFI_INVALID_PARAMETER:\r
678 pSocket->errno = EADDRNOTAVAIL;\r
679 break;\r
680\r
681 case EFI_NO_MAPPING:\r
682 pSocket->errno = EAFNOSUPPORT;\r
683 break;\r
684\r
685 case EFI_OUT_OF_RESOURCES:\r
686 pSocket->errno = ENOBUFS;\r
687 break;\r
688\r
689 case EFI_UNSUPPORTED:\r
690 pSocket->errno = EOPNOTSUPP;\r
691 break;\r
692 }\r
3bdf9aae 693 }\r
694 }\r
695 else {\r
696 DEBUG (( DEBUG_TX,\r
2dc09dd5 697 "0x%08x: pPort Configured for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> ",\r
3bdf9aae 698 pPort,\r
699 pConfigData->StationAddress.Addr[0],\r
700 pConfigData->StationAddress.Addr[1],\r
701 pConfigData->StationAddress.Addr[2],\r
702 pConfigData->StationAddress.Addr[3],\r
703 pConfigData->StationAddress.Addr[4],\r
704 pConfigData->StationAddress.Addr[5],\r
705 pConfigData->StationAddress.Addr[6],\r
706 pConfigData->StationAddress.Addr[7],\r
707 pConfigData->StationAddress.Addr[8],\r
708 pConfigData->StationAddress.Addr[9],\r
709 pConfigData->StationAddress.Addr[10],\r
710 pConfigData->StationAddress.Addr[11],\r
711 pConfigData->StationAddress.Addr[12],\r
712 pConfigData->StationAddress.Addr[13],\r
713 pConfigData->StationAddress.Addr[14],\r
714 pConfigData->StationAddress.Addr[15],\r
2dc09dd5
LL
715 pConfigData->StationPort ));\r
716 DEBUG (( DEBUG_TX,\r
717 "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
3bdf9aae 718 pConfigData->RemoteAddress.Addr[0],\r
719 pConfigData->RemoteAddress.Addr[1],\r
720 pConfigData->RemoteAddress.Addr[2],\r
721 pConfigData->RemoteAddress.Addr[3],\r
722 pConfigData->RemoteAddress.Addr[4],\r
723 pConfigData->RemoteAddress.Addr[5],\r
724 pConfigData->RemoteAddress.Addr[6],\r
725 pConfigData->RemoteAddress.Addr[7],\r
726 pConfigData->RemoteAddress.Addr[8],\r
727 pConfigData->RemoteAddress.Addr[9],\r
728 pConfigData->RemoteAddress.Addr[10],\r
729 pConfigData->RemoteAddress.Addr[11],\r
730 pConfigData->RemoteAddress.Addr[12],\r
731 pConfigData->RemoteAddress.Addr[13],\r
732 pConfigData->RemoteAddress.Addr[14],\r
733 pConfigData->RemoteAddress.Addr[15],\r
734 pConfigData->RemotePort ));\r
735 pPort->bConfigured = TRUE;\r
bb3aa953 736 pSocket->bConfigured = TRUE;\r
3bdf9aae 737\r
738 //\r
739 // Start the first read on the port\r
740 //\r
741 EslSocketRxStart ( pPort );\r
742\r
743 //\r
744 // The socket is connected\r
745 //\r
746 pSocket->State = SOCKET_STATE_CONNECTED;\r
bb3aa953 747 pSocket->errno = 0;\r
3bdf9aae 748 }\r
749\r
750 //\r
751 // Set the next port\r
752 //\r
753 pPort = pNextPort;\r
754 }\r
3bdf9aae 755 }\r
756\r
757 //\r
758 // Determine the socket configuration status\r
759 //\r
bb3aa953 760 Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;\r
3bdf9aae 761 \r
762 //\r
763 // Return the port connected state.\r
764 //\r
765 DBG_EXIT_STATUS ( Status );\r
766 return Status;\r
767}\r
768\r
769\r
770/**\r
771 Buffer data for transmission over a network connection.\r
772\r
773 This routine buffers data for the transmit engine in the normal\r
774 data queue. When the \ref TransmitEngine has resources, this\r
775 routine will start the transmission of the next buffer on the\r
776 network connection.\r
777\r
778 This routine is called by ::EslSocketTransmit to buffer\r
779 data for transmission. The data is copied into a local buffer\r
780 freeing the application buffer for reuse upon return. When\r
781 necessary, this routine starts the transmit engine that\r
782 performs the data transmission on the network connection. The\r
783 transmit engine transmits the data a packet at a time over the\r
784 network connection.\r
785\r
786 Transmission errors are returned during the next transmission or\r
787 during the close operation. Only buffering errors are returned\r
788 during the current transmission attempt.\r
789\r
790 @param [in] pSocket Address of an ::ESL_SOCKET structure\r
791\r
792 @param [in] Flags Message control flags\r
793\r
794 @param [in] BufferLength Length of the the buffer\r
795\r
796 @param [in] pBuffer Address of a buffer to receive the data.\r
797\r
798 @param [in] pDataLength Number of received data bytes in the buffer.\r
799\r
800 @param [in] pAddress Network address of the remote system address\r
801\r
802 @param [in] AddressLength Length of the remote network address structure\r
803\r
804 @retval EFI_SUCCESS - Socket data successfully buffered\r
805\r
806**/\r
807EFI_STATUS\r
808EslUdp6TxBuffer (\r
809 IN ESL_SOCKET * pSocket,\r
810 IN int Flags,\r
811 IN size_t BufferLength,\r
812 IN CONST UINT8 * pBuffer,\r
813 OUT size_t * pDataLength,\r
814 IN const struct sockaddr * pAddress,\r
815 IN socklen_t AddressLength\r
816 )\r
817{\r
818 ESL_PACKET * pPacket;\r
819 ESL_PACKET * pPreviousPacket;\r
820 ESL_PORT * pPort;\r
821 const struct sockaddr_in6 * pRemoteAddress;\r
822 ESL_UDP6_CONTEXT * pUdp6;\r
823 size_t * pTxBytes;\r
824 ESL_UDP6_TX_DATA * pTxData;\r
825 EFI_STATUS Status;\r
826 EFI_TPL TplPrevious;\r
827\r
828 DBG_ENTER ( );\r
829\r
830 //\r
831 // Assume failure\r
832 //\r
833 Status = EFI_UNSUPPORTED;\r
834 pSocket->errno = ENOTCONN;\r
835 *pDataLength = 0;\r
836\r
837 //\r
838 // Verify that the socket is connected\r
839 //\r
840 if ( SOCKET_STATE_CONNECTED == pSocket->State ) {\r
841 //\r
884ed923 842 // Verify that there is enough room to buffer another\r
843 // transmit operation\r
3bdf9aae 844 //\r
884ed923 845 pTxBytes = &pSocket->TxBytes;\r
846 if ( pSocket->MaxTxBuf > *pTxBytes ) {\r
3bdf9aae 847 //\r
884ed923 848 // Locate the port\r
3bdf9aae 849 //\r
884ed923 850 pPort = pSocket->pPortList;\r
851 while ( NULL != pPort ) {\r
852 //\r
853 // Determine the queue head\r
854 //\r
855 pUdp6 = &pPort->Context.Udp6;\r
3bdf9aae 856\r
3bdf9aae 857 //\r
858 // Attempt to allocate the packet\r
859 //\r
860 Status = EslSocketPacketAllocate ( &pPacket,\r
861 sizeof ( pPacket->Op.Udp6Tx )\r
862 - sizeof ( pPacket->Op.Udp6Tx.Buffer )\r
863 + BufferLength,\r
864 0,\r
865 DEBUG_TX );\r
866 if ( !EFI_ERROR ( Status )) {\r
867 //\r
868 // Initialize the transmit operation\r
869 //\r
870 pTxData = &pPacket->Op.Udp6Tx;\r
871 pTxData->TxData.UdpSessionData = NULL;\r
872 pTxData->TxData.DataLength = (UINT32) BufferLength;\r
873 pTxData->TxData.FragmentCount = 1;\r
874 pTxData->TxData.FragmentTable[0].FragmentLength = (UINT32) BufferLength;\r
875 pTxData->TxData.FragmentTable[0].FragmentBuffer = &pPacket->Op.Udp6Tx.Buffer[0];\r
876\r
877 //\r
878 // Set the remote system address if necessary\r
879 //\r
880 pTxData->TxData.UdpSessionData = NULL;\r
881 if ( NULL != pAddress ) {\r
882 pRemoteAddress = (const struct sockaddr_in6 *)pAddress;\r
883 CopyMem ( &pTxData->Session.SourceAddress,\r
884 &pUdp6->ConfigData.StationAddress,\r
885 sizeof ( pTxData->Session.SourceAddress ));\r
886 pTxData->Session.SourcePort = 0;\r
887 CopyMem ( &pTxData->Session.DestinationAddress,\r
888 &pRemoteAddress->sin6_addr,\r
889 sizeof ( pTxData->Session.DestinationAddress ));\r
890 pTxData->Session.DestinationPort = SwapBytes16 ( pRemoteAddress->sin6_port );\r
891\r
892 //\r
893 // Use the remote system address when sending this packet\r
894 //\r
895 pTxData->TxData.UdpSessionData = &pTxData->Session;\r
896 }\r
897\r
898 //\r
899 // Copy the data into the buffer\r
900 //\r
901 CopyMem ( &pPacket->Op.Udp6Tx.Buffer[0],\r
902 pBuffer,\r
903 BufferLength );\r
904\r
905 //\r
906 // Synchronize with the socket layer\r
907 //\r
908 RAISE_TPL ( TplPrevious, TPL_SOCKETS );\r
909\r
910 //\r
2dc09dd5 911 // Display the request\r
3bdf9aae 912 //\r
2dc09dd5
LL
913 DEBUG (( DEBUG_TX,\r
914 "Send %d bytes from 0x%08x to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
915 BufferLength,\r
916 pBuffer,\r
917 pTxData->Session.DestinationAddress.Addr[0],\r
918 pTxData->Session.DestinationAddress.Addr[1],\r
919 pTxData->Session.DestinationAddress.Addr[2],\r
920 pTxData->Session.DestinationAddress.Addr[3],\r
921 pTxData->Session.DestinationAddress.Addr[4],\r
922 pTxData->Session.DestinationAddress.Addr[5],\r
923 pTxData->Session.DestinationAddress.Addr[6],\r
924 pTxData->Session.DestinationAddress.Addr[7],\r
925 pTxData->Session.DestinationAddress.Addr[8],\r
926 pTxData->Session.DestinationAddress.Addr[9],\r
927 pTxData->Session.DestinationAddress.Addr[10],\r
928 pTxData->Session.DestinationAddress.Addr[11],\r
929 pTxData->Session.DestinationAddress.Addr[12],\r
930 pTxData->Session.DestinationAddress.Addr[13],\r
931 pTxData->Session.DestinationAddress.Addr[14],\r
932 pTxData->Session.DestinationAddress.Addr[15],\r
933 pTxData->Session.DestinationPort ));\r
3bdf9aae 934\r
2dc09dd5
LL
935 //\r
936 // Queue the data for transmission\r
937 //\r
938 pPacket->pNext = NULL;\r
939 pPreviousPacket = pSocket->pTxPacketListTail;\r
940 if ( NULL == pPreviousPacket ) {\r
941 pSocket->pTxPacketListHead = pPacket;\r
3bdf9aae 942 }\r
943 else {\r
2dc09dd5
LL
944 pPreviousPacket->pNext = pPacket;\r
945 }\r
946 pSocket->pTxPacketListTail = pPacket;\r
947 DEBUG (( DEBUG_TX,\r
948 "0x%08x: Packet on transmit list\r\n",\r
949 pPacket ));\r
950\r
951 //\r
952 // Account for the buffered data\r
953 //\r
954 *pTxBytes += BufferLength;\r
955 *pDataLength = BufferLength;\r
956\r
957 //\r
958 // Start the transmit engine if it is idle\r
959 //\r
960 if ( NULL != pPort->pTxFree ) {\r
961 EslSocketTxStart ( pPort,\r
962 &pSocket->pTxPacketListHead,\r
963 &pSocket->pTxPacketListTail,\r
964 &pPort->pTxActive,\r
965 &pPort->pTxFree );\r
3bdf9aae 966\r
967 //\r
2dc09dd5 968 // Ignore any transmit error\r
3bdf9aae 969 //\r
2dc09dd5
LL
970 if ( EFI_ERROR ( pSocket->TxError )) {\r
971 DEBUG (( DEBUG_TX,\r
972 "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n",\r
973 pPort,\r
974 pPacket,\r
975 pSocket->TxError ));\r
976 }\r
977 pSocket->TxError = EFI_SUCCESS;\r
3bdf9aae 978 }\r
979\r
980 //\r
981 // Release the socket layer synchronization\r
982 //\r
983 RESTORE_TPL ( TplPrevious );\r
984 }\r
985 else {\r
986 //\r
987 // Packet allocation failed\r
988 //\r
989 pSocket->errno = ENOMEM;\r
884ed923 990 break;\r
3bdf9aae 991 }\r
884ed923 992\r
3bdf9aae 993 //\r
884ed923 994 // Set the next port\r
3bdf9aae 995 //\r
884ed923 996 pPort = pPort->pLinkSocket;\r
3bdf9aae 997 }\r
998 }\r
884ed923 999 else {\r
1000 //\r
1001 // Not enough buffer space available\r
1002 //\r
1003 pSocket->errno = EAGAIN;\r
1004 Status = EFI_NOT_READY;\r
1005 }\r
3bdf9aae 1006 }\r
1007\r
1008 //\r
1009 // Return the operation status\r
1010 //\r
1011 DBG_EXIT_STATUS ( Status );\r
1012 return Status;\r
1013}\r
1014\r
1015\r
1016/**\r
1017 Process the transmit completion\r
1018\r
1019 This routine use ::EslSocketTxComplete to perform the transmit\r
1020 completion processing for data packets.\r
1021\r
1022 This routine is called by the UDPv4 network layer when a data\r
1023 transmit request completes.\r
1024\r
1025 @param [in] Event The normal transmit completion event\r
1026\r
1027 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1028\r
1029**/\r
1030VOID\r
1031EslUdp6TxComplete (\r
1032 IN EFI_EVENT Event,\r
1033 IN ESL_IO_MGMT * pIo\r
1034 )\r
1035{\r
1036 UINT32 LengthInBytes;\r
1037 ESL_PORT * pPort;\r
1038 ESL_PACKET * pPacket;\r
1039 ESL_SOCKET * pSocket;\r
1040 EFI_STATUS Status;\r
1041 \r
1042 DBG_ENTER ( );\r
1043 \r
1044 //\r
1045 // Locate the active transmit packet\r
1046 //\r
1047 pPacket = pIo->pPacket;\r
1048 pPort = pIo->pPort;\r
1049 pSocket = pPort->pSocket;\r
1050\r
1051 //\r
1052 // Get the transmit length and status\r
1053 //\r
1054 LengthInBytes = pPacket->Op.Udp6Tx.TxData.DataLength;\r
1055 pSocket->TxBytes -= LengthInBytes;\r
1056 Status = pIo->Token.Udp6Tx.Status;\r
1057\r
2dc09dd5
LL
1058 //\r
1059 // Ignore the transmit error\r
1060 //\r
1061 if ( EFI_ERROR ( Status )) {\r
1062 DEBUG (( DEBUG_TX,\r
1063 "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n",\r
1064 pPort,\r
1065 pPacket,\r
1066 Status ));\r
1067 Status = EFI_SUCCESS;\r
1068 }\r
1069\r
3bdf9aae 1070 //\r
1071 // Complete the transmit operation\r
1072 //\r
1073 EslSocketTxComplete ( pIo,\r
1074 LengthInBytes,\r
1075 Status,\r
1076 "UDP ",\r
1077 &pSocket->pTxPacketListHead,\r
1078 &pSocket->pTxPacketListTail,\r
1079 &pPort->pTxActive,\r
1080 &pPort->pTxFree );\r
1081 DBG_EXIT ( );\r
1082}\r
1083\r
1084\r
2dc09dd5
LL
1085/**\r
1086 Verify the adapter's IP address\r
1087\r
1088 This support routine is called by EslSocketBindTest.\r
1089\r
1090 @param [in] pPort Address of an ::ESL_PORT structure.\r
1091 @param [in] pConfigData Address of the configuration data\r
1092\r
1093 @retval EFI_SUCCESS - The IP address is valid\r
1094 @retval EFI_NOT_STARTED - The IP address is invalid\r
1095\r
1096 **/\r
1097EFI_STATUS\r
1098EslUdp6VerifyLocalIpAddress (\r
1099 IN ESL_PORT * pPort,\r
1100 IN EFI_UDP6_CONFIG_DATA * pConfigData\r
1101 )\r
1102{\r
1103 UINTN AddressCount;\r
1104 EFI_IP6_ADDRESS_INFO * pAddressInfo;\r
1105 UINTN DataSize;\r
1106 EFI_IP6_CONFIG_INTERFACE_INFO * pIpConfigData;\r
1107 EFI_IP6_CONFIG_PROTOCOL * pIpConfigProtocol;\r
1108 ESL_SERVICE * pService;\r
1109 EFI_STATUS Status;\r
1110\r
1111 DBG_ENTER ( );\r
1112\r
1113 //\r
1114 // Use break instead of goto\r
1115 //\r
1116 pIpConfigData = NULL;\r
1117 for ( ; ; ) {\r
1118 //\r
1119 // Determine if the IP address is specified\r
1120 //\r
1121 DEBUG (( DEBUG_BIND,\r
1122 "Requested IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
1123 pConfigData->StationAddress.Addr[0],\r
1124 pConfigData->StationAddress.Addr[1],\r
1125 pConfigData->StationAddress.Addr[2],\r
1126 pConfigData->StationAddress.Addr[3],\r
1127 pConfigData->StationAddress.Addr[4],\r
1128 pConfigData->StationAddress.Addr[5],\r
1129 pConfigData->StationAddress.Addr[6],\r
1130 pConfigData->StationAddress.Addr[7],\r
1131 pConfigData->StationAddress.Addr[8],\r
1132 pConfigData->StationAddress.Addr[9],\r
1133 pConfigData->StationAddress.Addr[10],\r
1134 pConfigData->StationAddress.Addr[11],\r
1135 pConfigData->StationAddress.Addr[12],\r
1136 pConfigData->StationAddress.Addr[13],\r
1137 pConfigData->StationAddress.Addr[14],\r
1138 pConfigData->StationAddress.Addr[15]));\r
1139 if (( 0 == pConfigData->StationAddress.Addr [ 0 ])\r
1140 && ( 0 == pConfigData->StationAddress.Addr [ 1 ])\r
1141 && ( 0 == pConfigData->StationAddress.Addr [ 2 ])\r
1142 && ( 0 == pConfigData->StationAddress.Addr [ 3 ])\r
1143 && ( 0 == pConfigData->StationAddress.Addr [ 4 ])\r
1144 && ( 0 == pConfigData->StationAddress.Addr [ 5 ])\r
1145 && ( 0 == pConfigData->StationAddress.Addr [ 6 ])\r
1146 && ( 0 == pConfigData->StationAddress.Addr [ 7 ])\r
1147 && ( 0 == pConfigData->StationAddress.Addr [ 8 ])\r
1148 && ( 0 == pConfigData->StationAddress.Addr [ 9 ])\r
1149 && ( 0 == pConfigData->StationAddress.Addr [ 10 ])\r
1150 && ( 0 == pConfigData->StationAddress.Addr [ 11 ])\r
1151 && ( 0 == pConfigData->StationAddress.Addr [ 12 ])\r
1152 && ( 0 == pConfigData->StationAddress.Addr [ 13 ])\r
1153 && ( 0 == pConfigData->StationAddress.Addr [ 14 ])\r
1154 && ( 0 == pConfigData->StationAddress.Addr [ 15 ]))\r
1155 {\r
1156 Status = EFI_SUCCESS;\r
1157 break;\r
1158 }\r
1159\r
1160 //\r
1161 // Open the configuration protocol\r
1162 //\r
1163 pService = pPort->pService;\r
1164 Status = gBS->OpenProtocol ( pService->Controller,\r
1165 &gEfiIp6ConfigProtocolGuid,\r
1166 (VOID **)&pIpConfigProtocol,\r
1167 NULL,\r
1168 NULL,\r
1169 EFI_OPEN_PROTOCOL_GET_PROTOCOL );\r
1170 if ( EFI_ERROR ( Status )) {\r
1171 DEBUG (( DEBUG_ERROR,\r
1172 "ERROR - IP Configuration Protocol not available, Status: %r\r\n",\r
1173 Status ));\r
1174 break;\r
1175 }\r
1176\r
1177 //\r
1178 // Get the IP configuration data size\r
1179 //\r
1180 DataSize = 0;\r
1181 Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
1182 Ip6ConfigDataTypeInterfaceInfo,\r
1183 &DataSize,\r
1184 NULL );\r
1185 if ( EFI_BUFFER_TOO_SMALL != Status ) {\r
1186 DEBUG (( DEBUG_ERROR,\r
1187 "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",\r
1188 Status ));\r
1189 break;\r
1190 }\r
1191\r
1192 //\r
1193 // Allocate the configuration data buffer\r
1194 //\r
1195 pIpConfigData = AllocatePool ( DataSize );\r
1196 if ( NULL == pIpConfigData ) {\r
1197 DEBUG (( DEBUG_ERROR,\r
1198 "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));\r
1199 Status = EFI_OUT_OF_RESOURCES;\r
1200 break;\r
1201 }\r
1202\r
1203 //\r
1204 // Get the IP configuration\r
1205 //\r
1206 Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
1207 Ip6ConfigDataTypeInterfaceInfo,\r
1208 &DataSize,\r
1209 pIpConfigData );\r
1210 if ( EFI_ERROR ( Status )) {\r
1211 DEBUG (( DEBUG_ERROR,\r
1212 "ERROR - Failed to return IP Configuration data, Status: %r\r\n",\r
1213 Status ));\r
1214 break;\r
1215 }\r
1216\r
1217 //\r
1218 // Display the current configuration\r
1219 //\r
1220 DEBUG (( DEBUG_BIND,\r
1221 "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
1222 pIpConfigData->HwAddress.Addr [ 0 ],\r
1223 pIpConfigData->HwAddress.Addr [ 1 ],\r
1224 pIpConfigData->HwAddress.Addr [ 2 ],\r
1225 pIpConfigData->HwAddress.Addr [ 3 ],\r
1226 pIpConfigData->HwAddress.Addr [ 4 ],\r
1227 pIpConfigData->HwAddress.Addr [ 5 ],\r
1228 pIpConfigData->HwAddress.Addr [ 6 ],\r
1229 pIpConfigData->HwAddress.Addr [ 7 ],\r
1230 pIpConfigData->HwAddress.Addr [ 8 ],\r
1231 pIpConfigData->HwAddress.Addr [ 9 ],\r
1232 pIpConfigData->HwAddress.Addr [ 10 ],\r
1233 pIpConfigData->HwAddress.Addr [ 11 ],\r
1234 pIpConfigData->HwAddress.Addr [ 12 ],\r
1235 pIpConfigData->HwAddress.Addr [ 13 ],\r
1236 pIpConfigData->HwAddress.Addr [ 14 ],\r
1237 pIpConfigData->HwAddress.Addr [ 15 ]));\r
1238\r
1239 //\r
1240 // Validate the hardware address\r
1241 //\r
1242 Status = EFI_SUCCESS;\r
1243 if (( 16 == pIpConfigData->HwAddressSize )\r
1244 && ( pConfigData->StationAddress.Addr [ 0 ] == pIpConfigData->HwAddress.Addr [ 0 ])\r
1245 && ( pConfigData->StationAddress.Addr [ 1 ] == pIpConfigData->HwAddress.Addr [ 1 ])\r
1246 && ( pConfigData->StationAddress.Addr [ 2 ] == pIpConfigData->HwAddress.Addr [ 2 ])\r
1247 && ( pConfigData->StationAddress.Addr [ 3 ] == pIpConfigData->HwAddress.Addr [ 3 ])\r
1248 && ( pConfigData->StationAddress.Addr [ 4 ] == pIpConfigData->HwAddress.Addr [ 4 ])\r
1249 && ( pConfigData->StationAddress.Addr [ 5 ] == pIpConfigData->HwAddress.Addr [ 5 ])\r
1250 && ( pConfigData->StationAddress.Addr [ 6 ] == pIpConfigData->HwAddress.Addr [ 6 ])\r
1251 && ( pConfigData->StationAddress.Addr [ 7 ] == pIpConfigData->HwAddress.Addr [ 7 ])\r
1252 && ( pConfigData->StationAddress.Addr [ 8 ] == pIpConfigData->HwAddress.Addr [ 8 ])\r
1253 && ( pConfigData->StationAddress.Addr [ 9 ] == pIpConfigData->HwAddress.Addr [ 9 ])\r
1254 && ( pConfigData->StationAddress.Addr [ 10 ] == pIpConfigData->HwAddress.Addr [ 10 ])\r
1255 && ( pConfigData->StationAddress.Addr [ 11 ] == pIpConfigData->HwAddress.Addr [ 11 ])\r
1256 && ( pConfigData->StationAddress.Addr [ 12 ] == pIpConfigData->HwAddress.Addr [ 12 ])\r
1257 && ( pConfigData->StationAddress.Addr [ 13 ] == pIpConfigData->HwAddress.Addr [ 13 ])\r
1258 && ( pConfigData->StationAddress.Addr [ 14 ] == pIpConfigData->HwAddress.Addr [ 14 ])\r
1259 && ( pConfigData->StationAddress.Addr [ 15 ] == pIpConfigData->HwAddress.Addr [ 15 ])) {\r
1260 break;\r
1261 }\r
1262\r
1263 //\r
1264 // Walk the list of other IP addresses assigned to this adapter\r
1265 //\r
1266 for ( AddressCount = 0; pIpConfigData->AddressInfoCount > AddressCount; AddressCount += 1 ) {\r
1267 pAddressInfo = &pIpConfigData->AddressInfo [ AddressCount ];\r
1268\r
1269 //\r
1270 // Display the IP address\r
1271 //\r
1272 DEBUG (( DEBUG_BIND,\r
1273 "Actual adapter IP address: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n",\r
1274 pAddressInfo->Address.Addr [ 0 ],\r
1275 pAddressInfo->Address.Addr [ 1 ],\r
1276 pAddressInfo->Address.Addr [ 2 ],\r
1277 pAddressInfo->Address.Addr [ 3 ],\r
1278 pAddressInfo->Address.Addr [ 4 ],\r
1279 pAddressInfo->Address.Addr [ 5 ],\r
1280 pAddressInfo->Address.Addr [ 6 ],\r
1281 pAddressInfo->Address.Addr [ 7 ],\r
1282 pAddressInfo->Address.Addr [ 8 ],\r
1283 pAddressInfo->Address.Addr [ 9 ],\r
1284 pAddressInfo->Address.Addr [ 10 ],\r
1285 pAddressInfo->Address.Addr [ 11 ],\r
1286 pAddressInfo->Address.Addr [ 12 ],\r
1287 pAddressInfo->Address.Addr [ 13 ],\r
1288 pAddressInfo->Address.Addr [ 14 ],\r
1289 pAddressInfo->Address.Addr [ 15 ]));\r
1290\r
1291 //\r
1292 // Validate the IP address\r
1293 //\r
1294 if (( pConfigData->StationAddress.Addr [ 0 ] == pAddressInfo->Address.Addr [ 0 ])\r
1295 && ( pConfigData->StationAddress.Addr [ 1 ] == pAddressInfo->Address.Addr [ 1 ])\r
1296 && ( pConfigData->StationAddress.Addr [ 2 ] == pAddressInfo->Address.Addr [ 2 ])\r
1297 && ( pConfigData->StationAddress.Addr [ 3 ] == pAddressInfo->Address.Addr [ 3 ])\r
1298 && ( pConfigData->StationAddress.Addr [ 4 ] == pAddressInfo->Address.Addr [ 4 ])\r
1299 && ( pConfigData->StationAddress.Addr [ 5 ] == pAddressInfo->Address.Addr [ 5 ])\r
1300 && ( pConfigData->StationAddress.Addr [ 6 ] == pAddressInfo->Address.Addr [ 6 ])\r
1301 && ( pConfigData->StationAddress.Addr [ 7 ] == pAddressInfo->Address.Addr [ 7 ])\r
1302 && ( pConfigData->StationAddress.Addr [ 8 ] == pAddressInfo->Address.Addr [ 8 ])\r
1303 && ( pConfigData->StationAddress.Addr [ 9 ] == pAddressInfo->Address.Addr [ 9 ])\r
1304 && ( pConfigData->StationAddress.Addr [ 10 ] == pAddressInfo->Address.Addr [ 10 ])\r
1305 && ( pConfigData->StationAddress.Addr [ 11 ] == pAddressInfo->Address.Addr [ 11 ])\r
1306 && ( pConfigData->StationAddress.Addr [ 12 ] == pAddressInfo->Address.Addr [ 12 ])\r
1307 && ( pConfigData->StationAddress.Addr [ 13 ] == pAddressInfo->Address.Addr [ 13 ])\r
1308 && ( pConfigData->StationAddress.Addr [ 14 ] == pAddressInfo->Address.Addr [ 14 ])\r
1309 && ( pConfigData->StationAddress.Addr [ 15 ] == pAddressInfo->Address.Addr [ 15 ])) {\r
1310 break;\r
1311 }\r
1312 }\r
1313 if ( pIpConfigData->AddressInfoCount > AddressCount ) {\r
1314 break;\r
1315 }\r
1316\r
1317 //\r
1318 // The IP address did not match\r
1319 //\r
1320 Status = EFI_NOT_STARTED;\r
1321 break;\r
1322 }\r
1323\r
1324 //\r
1325 // Free the buffer if necessary\r
1326 //\r
1327 if ( NULL != pIpConfigData ) {\r
1328 FreePool ( pIpConfigData );\r
1329 }\r
1330\r
1331 //\r
1332 // Return the IP address status\r
1333 //\r
1334 DBG_EXIT_STATUS ( Status );\r
1335 return Status;\r
1336}\r
1337\r
1338\r
3bdf9aae 1339/**\r
1340 Interface between the socket layer and the network specific\r
1341 code that supports SOCK_DGRAM sockets over UDPv4.\r
1342**/\r
1343CONST ESL_PROTOCOL_API cEslUdp6Api = {\r
1344 "UDPv6",\r
1345 IPPROTO_UDP,\r
1346 OFFSET_OF ( ESL_PORT, Context.Udp6.ConfigData ),\r
1347 OFFSET_OF ( ESL_LAYER, pUdp6List ),\r
1348 sizeof ( struct sockaddr_in6 ),\r
1349 sizeof ( struct sockaddr_in6 ),\r
1350 AF_INET6,\r
1351 sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),\r
1352 sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),\r
1353 OFFSET_OF ( ESL_IO_MGMT, Token.Udp6Rx.Packet.RxData ),\r
1354 FALSE,\r
1355 EADDRINUSE,\r
1356 NULL, // Accept\r
1357 NULL, // ConnectPoll\r
1358 NULL, // ConnectStart\r
1359 EslUdp6SocketIsConfigured,\r
1360 EslUdp6LocalAddressGet,\r
1361 EslUdp6LocalAddressSet,\r
1362 NULL, // Listen\r
1363 NULL, // OptionGet\r
1364 NULL, // OptionSet\r
1365 EslUdp6PacketFree,\r
1366 EslUdp6PortAllocate,\r
1367 NULL, // PortClose,\r
1368 NULL, // PortCloseOp\r
1369 TRUE,\r
1370 EslUdp6Receive,\r
1371 EslUdp6RemoteAddressGet,\r
1372 EslUdp6RemoteAddressSet,\r
1373 EslUdp6RxComplete,\r
1374 NULL, // RxStart\r
1375 EslUdp6TxBuffer,\r
1376 EslUdp6TxComplete,\r
2dc09dd5 1377 NULL, // TxOobComplete\r
a93b0f45 1378 (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslUdp6VerifyLocalIpAddress\r
3bdf9aae 1379};\r