]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/Tcp4.c
Ignore transmit errors for UDPv4, UDPv6 and IPv4.
[mirror_edk2.git] / StdLib / EfiSocketLib / Tcp4.c
index 34e60e2a7f7a951a3b4ee02a084e2f7af9f74938..1e1d62a7d1c42fa3cf71720194f38193b4bac8a3 100644 (file)
@@ -2225,6 +2225,159 @@ EslTcp4TxOobComplete (
 }\r
 \r
 \r
+/**\r
+  Verify the adapter's IP address\r
+\r
+  This support routine is called by EslSocketBindTest.\r
+\r
+  @param [in] pPort       Address of an ::ESL_PORT structure.\r
+  @param [in] pConfigData Address of the configuration data\r
+\r
+  @retval EFI_SUCCESS - The IP address is valid\r
+  @retval EFI_NOT_STARTED - The IP address is invalid\r
+\r
+ **/\r
+EFI_STATUS\r
+EslTcp4VerifyLocalIpAddress (\r
+  IN ESL_PORT * pPort,\r
+  IN EFI_TCP4_CONFIG_DATA * pConfigData\r
+  )\r
+{\r
+  UINTN DataSize;\r
+  EFI_TCP4_ACCESS_POINT * pAccess;\r
+  EFI_IP4_IPCONFIG_DATA * pIpConfigData;\r
+  EFI_IP4_CONFIG_PROTOCOL * pIpConfigProtocol;\r
+  ESL_SERVICE * pService;\r
+  EFI_STATUS Status;\r
+\r
+  DBG_ENTER ( );\r
+\r
+  //\r
+  //  Use break instead of goto\r
+  //\r
+  pIpConfigData = NULL;\r
+  for ( ; ; ) {\r
+    //\r
+    //  Determine if the IP address is specified\r
+    //\r
+    pAccess = &pConfigData->AccessPoint;\r
+    DEBUG (( DEBUG_BIND,\r
+              "UseDefaultAddress: %s\r\n",\r
+              pAccess->UseDefaultAddress ? L"TRUE" : L"FALSE" ));\r
+    DEBUG (( DEBUG_BIND,\r
+              "Requested IP address: %d.%d.%d.%d\r\n",\r
+              pAccess->StationAddress.Addr [ 0 ],\r
+              pAccess->StationAddress.Addr [ 1 ],\r
+              pAccess->StationAddress.Addr [ 2 ],\r
+              pAccess->StationAddress.Addr [ 3 ]));\r
+    if ( pAccess->UseDefaultAddress\r
+      || (( 0 == pAccess->StationAddress.Addr [ 0 ])\r
+      && ( 0 == pAccess->StationAddress.Addr [ 1 ])\r
+      && ( 0 == pAccess->StationAddress.Addr [ 2 ])\r
+      && ( 0 == pAccess->StationAddress.Addr [ 3 ])))\r
+    {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Open the configuration protocol\r
+    //\r
+    pService = pPort->pService;\r
+    Status = gBS->OpenProtocol ( pService->Controller,\r
+                                 &gEfiIp4ConfigProtocolGuid,\r
+                                 (VOID **)&pIpConfigProtocol,\r
+                                 NULL,\r
+                                 NULL,\r
+                                 EFI_OPEN_PROTOCOL_GET_PROTOCOL );\r
+    if ( EFI_ERROR ( Status )) {\r
+      DEBUG (( DEBUG_ERROR,\r
+                "ERROR - IP Configuration Protocol not available, Status: %r\r\n",\r
+                Status ));\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Get the IP configuration data size\r
+    //\r
+    DataSize = 0;\r
+    Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
+                                          &DataSize,\r
+                                          NULL );\r
+    if ( EFI_BUFFER_TOO_SMALL != Status ) {\r
+      DEBUG (( DEBUG_ERROR,\r
+                "ERROR - Failed to get IP Configuration data size, Status: %r\r\n",\r
+                Status ));\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Allocate the configuration data buffer\r
+    //\r
+    pIpConfigData = AllocatePool ( DataSize );\r
+    if ( NULL == pIpConfigData ) {\r
+      DEBUG (( DEBUG_ERROR,\r
+                "ERROR - Not enough memory to allocate IP Configuration data!\r\n" ));\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Get the IP configuration\r
+    //\r
+    Status = pIpConfigProtocol->GetData ( pIpConfigProtocol,\r
+                                          &DataSize,\r
+                                          pIpConfigData );\r
+    if ( EFI_ERROR ( Status )) {\r
+      DEBUG (( DEBUG_ERROR,\r
+                "ERROR - Failed to return IP Configuration data, Status: %r\r\n",\r
+                Status ));\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Display the current configuration\r
+    //\r
+    DEBUG (( DEBUG_BIND,\r
+              "Actual adapter IP address: %d.%d.%d.%d\r\n",\r
+              pIpConfigData->StationAddress.Addr [ 0 ],\r
+              pIpConfigData->StationAddress.Addr [ 1 ],\r
+              pIpConfigData->StationAddress.Addr [ 2 ],\r
+              pIpConfigData->StationAddress.Addr [ 3 ]));\r
+\r
+    //\r
+    //  Assume the port is not configured\r
+    //\r
+    Status = EFI_SUCCESS;\r
+    if (( pAccess->StationAddress.Addr [ 0 ] == pIpConfigData->StationAddress.Addr [ 0 ])\r
+      && ( pAccess->StationAddress.Addr [ 1 ] == pIpConfigData->StationAddress.Addr [ 1 ])\r
+      && ( pAccess->StationAddress.Addr [ 2 ] == pIpConfigData->StationAddress.Addr [ 2 ])\r
+      && ( pAccess->StationAddress.Addr [ 3 ] == pIpConfigData->StationAddress.Addr [ 3 ])) {\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  The IP address did not match\r
+    //\r
+    Status = EFI_NOT_STARTED;\r
+    break;\r
+  }\r
+\r
+  //\r
+  //  Free the buffer if necessary\r
+  //\r
+  if ( NULL != pIpConfigData ) {\r
+    FreePool ( pIpConfigData );\r
+  }\r
+\r
+  //\r
+  //  Return the IP address status\r
+  //\r
+  DBG_EXIT_STATUS ( Status );\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Interface between the socket layer and the network specific\r
   code that supports SOCK_STREAM and SOCK_SEQPACKET sockets\r
@@ -2264,5 +2417,6 @@ CONST ESL_PROTOCOL_API cEslTcp4Api = {
   EslTcp4RxStart,\r
   EslTcp4TxBuffer,\r
   EslTcp4TxComplete,\r
-  EslTcp4TxOobComplete\r
+  EslTcp4TxOobComplete,\r
+  EslTcp4VerifyLocalIpAddress\r
 };\r