]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/EfiSocketLib/Udp6.c
Refine get default language logic for command "drivers".
[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
588 if ( NULL == pSocket->pPortList ) {\r
589 ZeroMem ( &LocalAddress, sizeof ( LocalAddress ));\r
590 LocalAddress.sin6_len = sizeof ( LocalAddress );\r
591 LocalAddress.sin6_family = AF_INET6;\r
592 Status = EslSocketBind ( &pSocket->SocketProtocol,\r
593 (struct sockaddr *)&LocalAddress,\r
594 LocalAddress.sin6_len,\r
595 &pSocket->errno );\r
596 }\r
597\r
598 //\r
599 // Walk the port list\r
600 //\r
601 pPort = pSocket->pPortList;\r
602 while ( NULL != pPort ) {\r
603 //\r
604 // Attempt to configure the port\r
605 //\r
606 pNextPort = pPort->pLinkSocket;\r
607 pUdp6 = &pPort->Context.Udp6;\r
608 pUdp6Protocol = pPort->pProtocol.UDPv6;\r
609 pConfigData = &pUdp6->ConfigData;\r
610 DEBUG (( DEBUG_TX,\r
611 "0x%08x: pPort Configuring for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
612 pPort,\r
613 pConfigData->StationAddress.Addr[0],\r
614 pConfigData->StationAddress.Addr[1],\r
615 pConfigData->StationAddress.Addr[2],\r
616 pConfigData->StationAddress.Addr[3],\r
617 pConfigData->StationAddress.Addr[4],\r
618 pConfigData->StationAddress.Addr[5],\r
619 pConfigData->StationAddress.Addr[6],\r
620 pConfigData->StationAddress.Addr[7],\r
621 pConfigData->StationAddress.Addr[8],\r
622 pConfigData->StationAddress.Addr[9],\r
623 pConfigData->StationAddress.Addr[10],\r
624 pConfigData->StationAddress.Addr[11],\r
625 pConfigData->StationAddress.Addr[12],\r
626 pConfigData->StationAddress.Addr[13],\r
627 pConfigData->StationAddress.Addr[14],\r
628 pConfigData->StationAddress.Addr[15],\r
629 pConfigData->StationPort,\r
630 pConfigData->RemoteAddress.Addr[0],\r
631 pConfigData->RemoteAddress.Addr[1],\r
632 pConfigData->RemoteAddress.Addr[2],\r
633 pConfigData->RemoteAddress.Addr[3],\r
634 pConfigData->RemoteAddress.Addr[4],\r
635 pConfigData->RemoteAddress.Addr[5],\r
636 pConfigData->RemoteAddress.Addr[6],\r
637 pConfigData->RemoteAddress.Addr[7],\r
638 pConfigData->RemoteAddress.Addr[8],\r
639 pConfigData->RemoteAddress.Addr[9],\r
640 pConfigData->RemoteAddress.Addr[10],\r
641 pConfigData->RemoteAddress.Addr[11],\r
642 pConfigData->RemoteAddress.Addr[12],\r
643 pConfigData->RemoteAddress.Addr[13],\r
644 pConfigData->RemoteAddress.Addr[14],\r
645 pConfigData->RemoteAddress.Addr[15],\r
646 pConfigData->RemotePort ));\r
647 Status = pUdp6Protocol->Configure ( pUdp6Protocol,\r
648 pConfigData );\r
649 if ( !EFI_ERROR ( Status )) {\r
650 //\r
651 // Update the configuration data\r
652 //\r
653 Status = pUdp6Protocol->GetModeData ( pUdp6Protocol,\r
654 pConfigData,\r
655 NULL,\r
656 NULL,\r
657 NULL );\r
658 }\r
659 if ( EFI_ERROR ( Status )) {\r
660 DEBUG (( DEBUG_LISTEN,\r
661 "ERROR - Failed to configure the Udp6 port, Status: %r\r\n",\r
662 Status ));\r
663 switch ( Status ) {\r
664 case EFI_ACCESS_DENIED:\r
665 pSocket->errno = EACCES;\r
666 break;\r
667\r
668 default:\r
669 case EFI_DEVICE_ERROR:\r
670 pSocket->errno = EIO;\r
671 break;\r
672\r
673 case EFI_INVALID_PARAMETER:\r
674 pSocket->errno = EADDRNOTAVAIL;\r
675 break;\r
676\r
677 case EFI_NO_MAPPING:\r
678 pSocket->errno = EAFNOSUPPORT;\r
679 break;\r
680\r
681 case EFI_OUT_OF_RESOURCES:\r
682 pSocket->errno = ENOBUFS;\r
683 break;\r
684\r
685 case EFI_UNSUPPORTED:\r
686 pSocket->errno = EOPNOTSUPP;\r
687 break;\r
688 }\r
689 }\r
690 else {\r
691 DEBUG (( DEBUG_TX,\r
692 "0x%08x: pPort Configured for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
693 pPort,\r
694 pConfigData->StationAddress.Addr[0],\r
695 pConfigData->StationAddress.Addr[1],\r
696 pConfigData->StationAddress.Addr[2],\r
697 pConfigData->StationAddress.Addr[3],\r
698 pConfigData->StationAddress.Addr[4],\r
699 pConfigData->StationAddress.Addr[5],\r
700 pConfigData->StationAddress.Addr[6],\r
701 pConfigData->StationAddress.Addr[7],\r
702 pConfigData->StationAddress.Addr[8],\r
703 pConfigData->StationAddress.Addr[9],\r
704 pConfigData->StationAddress.Addr[10],\r
705 pConfigData->StationAddress.Addr[11],\r
706 pConfigData->StationAddress.Addr[12],\r
707 pConfigData->StationAddress.Addr[13],\r
708 pConfigData->StationAddress.Addr[14],\r
709 pConfigData->StationAddress.Addr[15],\r
710 pConfigData->StationPort,\r
711 pConfigData->RemoteAddress.Addr[0],\r
712 pConfigData->RemoteAddress.Addr[1],\r
713 pConfigData->RemoteAddress.Addr[2],\r
714 pConfigData->RemoteAddress.Addr[3],\r
715 pConfigData->RemoteAddress.Addr[4],\r
716 pConfigData->RemoteAddress.Addr[5],\r
717 pConfigData->RemoteAddress.Addr[6],\r
718 pConfigData->RemoteAddress.Addr[7],\r
719 pConfigData->RemoteAddress.Addr[8],\r
720 pConfigData->RemoteAddress.Addr[9],\r
721 pConfigData->RemoteAddress.Addr[10],\r
722 pConfigData->RemoteAddress.Addr[11],\r
723 pConfigData->RemoteAddress.Addr[12],\r
724 pConfigData->RemoteAddress.Addr[13],\r
725 pConfigData->RemoteAddress.Addr[14],\r
726 pConfigData->RemoteAddress.Addr[15],\r
727 pConfigData->RemotePort ));\r
728 pPort->bConfigured = TRUE;\r
729\r
730 //\r
731 // Start the first read on the port\r
732 //\r
733 EslSocketRxStart ( pPort );\r
734\r
735 //\r
736 // The socket is connected\r
737 //\r
738 pSocket->State = SOCKET_STATE_CONNECTED;\r
739 }\r
740\r
741 //\r
742 // Set the next port\r
743 //\r
744 pPort = pNextPort;\r
745 }\r
746\r
747 //\r
748 // Determine the configuration status\r
749 //\r
750 if ( NULL != pSocket->pPortList ) {\r
751 pSocket->bConfigured = TRUE;\r
752 }\r
753 }\r
754\r
755 //\r
756 // Determine the socket configuration status\r
757 //\r
758 if ( !EFI_ERROR ( Status )) {\r
759 Status = pSocket->bConfigured ? EFI_SUCCESS : EFI_NOT_STARTED;\r
760 }\r
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
842 // Locate the port\r
843 //\r
844 pPort = pSocket->pPortList;\r
845 if ( NULL != pPort ) {\r
846 //\r
847 // Determine the queue head\r
848 //\r
849 pUdp6 = &pPort->Context.Udp6;\r
850 pTxBytes = &pSocket->TxBytes;\r
851\r
852 //\r
853 // Verify that there is enough room to buffer another\r
854 // transmit operation\r
855 //\r
856 if ( pSocket->MaxTxBuf > *pTxBytes ) {\r
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
911 // Stop transmission after an error\r
912 //\r
913 if ( !EFI_ERROR ( pSocket->TxError )) {\r
914 //\r
915 // Display the request\r
916 //\r
917 DEBUG (( DEBUG_TX,\r
918 "Send %d %s bytes from 0x%08x\r\n",\r
919 BufferLength,\r
920 pBuffer ));\r
921\r
922 //\r
923 // Queue the data for transmission\r
924 //\r
925 pPacket->pNext = NULL;\r
926 pPreviousPacket = pSocket->pTxPacketListTail;\r
927 if ( NULL == pPreviousPacket ) {\r
928 pSocket->pTxPacketListHead = pPacket;\r
929 }\r
930 else {\r
931 pPreviousPacket->pNext = pPacket;\r
932 }\r
933 pSocket->pTxPacketListTail = pPacket;\r
934 DEBUG (( DEBUG_TX,\r
935 "0x%08x: Packet on transmit list\r\n",\r
936 pPacket ));\r
937\r
938 //\r
939 // Account for the buffered data\r
940 //\r
941 *pTxBytes += BufferLength;\r
942 *pDataLength = BufferLength;\r
943\r
944 //\r
945 // Start the transmit engine if it is idle\r
946 //\r
947 if ( NULL != pPort->pTxFree ) {\r
948 EslSocketTxStart ( pPort,\r
949 &pSocket->pTxPacketListHead,\r
950 &pSocket->pTxPacketListTail,\r
951 &pPort->pTxActive,\r
952 &pPort->pTxFree );\r
953 }\r
954 }\r
955 else {\r
956 //\r
957 // Previous transmit error\r
958 // Stop transmission\r
959 //\r
960 Status = pSocket->TxError;\r
961 pSocket->errno = EIO;\r
962\r
963 //\r
964 // Free the packet\r
965 //\r
966 EslSocketPacketFree ( pPacket, DEBUG_TX );\r
967 }\r
968\r
969 //\r
970 // Release the socket layer synchronization\r
971 //\r
972 RESTORE_TPL ( TplPrevious );\r
973 }\r
974 else {\r
975 //\r
976 // Packet allocation failed\r
977 //\r
978 pSocket->errno = ENOMEM;\r
979 }\r
980 }\r
981 else {\r
982 //\r
983 // Not enough buffer space available\r
984 //\r
985 pSocket->errno = EAGAIN;\r
986 Status = EFI_NOT_READY;\r
987 }\r
988 }\r
989 }\r
990\r
991 //\r
992 // Return the operation status\r
993 //\r
994 DBG_EXIT_STATUS ( Status );\r
995 return Status;\r
996}\r
997\r
998\r
999/**\r
1000 Process the transmit completion\r
1001\r
1002 This routine use ::EslSocketTxComplete to perform the transmit\r
1003 completion processing for data packets.\r
1004\r
1005 This routine is called by the UDPv4 network layer when a data\r
1006 transmit request completes.\r
1007\r
1008 @param [in] Event The normal transmit completion event\r
1009\r
1010 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1011\r
1012**/\r
1013VOID\r
1014EslUdp6TxComplete (\r
1015 IN EFI_EVENT Event,\r
1016 IN ESL_IO_MGMT * pIo\r
1017 )\r
1018{\r
1019 UINT32 LengthInBytes;\r
1020 ESL_PORT * pPort;\r
1021 ESL_PACKET * pPacket;\r
1022 ESL_SOCKET * pSocket;\r
1023 EFI_STATUS Status;\r
1024 \r
1025 DBG_ENTER ( );\r
1026 \r
1027 //\r
1028 // Locate the active transmit packet\r
1029 //\r
1030 pPacket = pIo->pPacket;\r
1031 pPort = pIo->pPort;\r
1032 pSocket = pPort->pSocket;\r
1033\r
1034 //\r
1035 // Get the transmit length and status\r
1036 //\r
1037 LengthInBytes = pPacket->Op.Udp6Tx.TxData.DataLength;\r
1038 pSocket->TxBytes -= LengthInBytes;\r
1039 Status = pIo->Token.Udp6Tx.Status;\r
1040\r
1041 //\r
1042 // Complete the transmit operation\r
1043 //\r
1044 EslSocketTxComplete ( pIo,\r
1045 LengthInBytes,\r
1046 Status,\r
1047 "UDP ",\r
1048 &pSocket->pTxPacketListHead,\r
1049 &pSocket->pTxPacketListTail,\r
1050 &pPort->pTxActive,\r
1051 &pPort->pTxFree );\r
1052 DBG_EXIT ( );\r
1053}\r
1054\r
1055\r
1056/**\r
1057 Interface between the socket layer and the network specific\r
1058 code that supports SOCK_DGRAM sockets over UDPv4.\r
1059**/\r
1060CONST ESL_PROTOCOL_API cEslUdp6Api = {\r
1061 "UDPv6",\r
1062 IPPROTO_UDP,\r
1063 OFFSET_OF ( ESL_PORT, Context.Udp6.ConfigData ),\r
1064 OFFSET_OF ( ESL_LAYER, pUdp6List ),\r
1065 sizeof ( struct sockaddr_in6 ),\r
1066 sizeof ( struct sockaddr_in6 ),\r
1067 AF_INET6,\r
1068 sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),\r
1069 sizeof (((ESL_PACKET *)0 )->Op.Udp6Rx ),\r
1070 OFFSET_OF ( ESL_IO_MGMT, Token.Udp6Rx.Packet.RxData ),\r
1071 FALSE,\r
1072 EADDRINUSE,\r
1073 NULL, // Accept\r
1074 NULL, // ConnectPoll\r
1075 NULL, // ConnectStart\r
1076 EslUdp6SocketIsConfigured,\r
1077 EslUdp6LocalAddressGet,\r
1078 EslUdp6LocalAddressSet,\r
1079 NULL, // Listen\r
1080 NULL, // OptionGet\r
1081 NULL, // OptionSet\r
1082 EslUdp6PacketFree,\r
1083 EslUdp6PortAllocate,\r
1084 NULL, // PortClose,\r
1085 NULL, // PortCloseOp\r
1086 TRUE,\r
1087 EslUdp6Receive,\r
1088 EslUdp6RemoteAddressGet,\r
1089 EslUdp6RemoteAddressSet,\r
1090 EslUdp6RxComplete,\r
1091 NULL, // RxStart\r
1092 EslUdp6TxBuffer,\r
1093 EslUdp6TxComplete,\r
1094 NULL // TxOobComplete\r
1095};\r