@@ -20,6 +20,10 @@ extern "C"
2020#include < lwip/apps/sntp.h>
2121}
2222
23+ #if defined(PLATFORM_ESP32)
24+ #include " NF_ESP32_Network.h"
25+ #endif
26+
2327int errorCode;
2428
2529// --//
@@ -1288,6 +1292,7 @@ struct dhcp_client_id
12881292 uint8_t clientId[6 ];
12891293};
12901294
1295+ #if !defined(PLATFORM_ESP32)
12911296HRESULT LWIP_SOCKETS_Driver::UpdateAdapterConfiguration (
12921297 uint32_t interfaceIndex,
12931298 uint32_t updateFlags,
@@ -1389,6 +1394,135 @@ HRESULT LWIP_SOCKETS_Driver::UpdateAdapterConfiguration(
13891394
13901395 return S_OK;
13911396}
1397+ #else
1398+ HRESULT LWIP_SOCKETS_Driver::UpdateAdapterConfiguration (
1399+ uint32_t interfaceIndex,
1400+ uint32_t updateFlags,
1401+ HAL_Configuration_NetworkInterface *config)
1402+ {
1403+ NATIVE_PROFILE_PAL_NETWORK ();
1404+ bool enableDHCP = (config->StartupAddressMode == AddressMode_DHCP);
1405+
1406+ struct netif *networkInterface =
1407+ netif_find_interface (g_LWIP_SOCKETS_Driver.m_interfaces [interfaceIndex].m_interfaceNumber );
1408+ if (NULL == networkInterface)
1409+ {
1410+ return CLR_E_FAIL;
1411+ }
1412+
1413+ esp_netif_t *espNetif = NF_ESP32_GetEspNetif (networkInterface);
1414+ if (NULL == espNetif)
1415+ {
1416+ return CLR_E_FAIL;
1417+ }
1418+
1419+ #if LWIP_DNS
1420+ // when using DHCP do not use the static settings
1421+ if (0 != (updateFlags & NetworkInterface_UpdateOperation_Dns))
1422+ {
1423+ if (config->AutomaticDNS == 0 )
1424+ {
1425+ // user defined DNS addresses
1426+ if (config->IPv4DNSAddress1 != 0 )
1427+ {
1428+ esp_netif_dns_info_t dnsServer;
1429+ dnsServer.ip .u_addr .ip4 .addr = config->IPv4DNSAddress1 ;
1430+ dnsServer.ip .type = IPADDR_TYPE_V4;
1431+
1432+ esp_netif_set_dns_info (espNetif, ESP_NETIF_DNS_MAIN, &dnsServer);
1433+ }
1434+ if (config->IPv4DNSAddress2 != 0 )
1435+ {
1436+ // need to convert this first
1437+ esp_netif_dns_info_t dnsServer;
1438+ dnsServer.ip .u_addr .ip4 .addr = config->IPv4DNSAddress2 ;
1439+ dnsServer.ip .type = IPADDR_TYPE_V4;
1440+
1441+ esp_netif_set_dns_info (espNetif, ESP_NETIF_DNS_FALLBACK, &dnsServer);
1442+ }
1443+ }
1444+ }
1445+ #endif
1446+
1447+ #if LWIP_DHCP
1448+ if (0 != (updateFlags & NetworkInterface_UpdateOperation_Dhcp))
1449+ {
1450+ if (enableDHCP)
1451+ {
1452+ // Make sure DHCP option is enabled for esp_netif
1453+ espNetif->flags = (esp_netif_flags_t )(espNetif->flags | ESP_NETIF_DHCP_CLIENT);
1454+
1455+ // Reset IP address on interface before enabling DHCP
1456+ ip_addr_t ipAddress, mask, gateway;
1457+ #if LWIP_IPV6
1458+ ipAddress.u_addr .ip4 .addr = 0 ;
1459+ mask.u_addr .ip4 .addr = 0 ;
1460+ gateway.u_addr .ip4 .addr = 0 ;
1461+ #else
1462+ ipAddress.addr = 0 ;
1463+ mask.addr = 0 ;
1464+ gateway.addr = 0 ;
1465+ #endif
1466+
1467+ netif_set_addr (
1468+ networkInterface,
1469+ (const ip4_addr_t *)&ipAddress,
1470+ (const ip4_addr_t *)&mask,
1471+ (const ip4_addr_t *)&gateway);
1472+
1473+ // Need to start DHCP
1474+ // No need to check for return value, even if it fails, it will retry
1475+ esp_netif_dhcpc_start (espNetif);
1476+ }
1477+ else
1478+ {
1479+ // stop DHCP, ignore errors
1480+ esp_netif_dhcpc_stop (espNetif);
1481+
1482+ // Get static IPV4 address from config
1483+ esp_netif_ip_info_t ip_info;
1484+ ip_info.ip .addr = config->IPv4Address ;
1485+ ip_info.gw .addr = config->IPv4GatewayAddress ;
1486+ ip_info.netmask .addr = config->IPv4NetMask ;
1487+
1488+ // set interface with our static IP configs, ignore error
1489+ esp_netif_set_ip_info (espNetif, &ip_info);
1490+
1491+ // Make sure DHCP client is disabled in esp_netif
1492+ espNetif->flags = (esp_netif_flags_t )(espNetif->flags & ~ESP_NETIF_DHCP_CLIENT);
1493+
1494+ // Inform DHCP server of change
1495+ dhcp_inform (networkInterface);
1496+ }
1497+ }
1498+
1499+ if (enableDHCP)
1500+ {
1501+ if (0 != (updateFlags & NetworkInterface_UpdateOperation_DhcpRelease))
1502+ {
1503+ esp_netif_dhcpc_stop (espNetif);
1504+ }
1505+ else if (0 != (updateFlags & NetworkInterface_UpdateOperation_DhcpRenew))
1506+ {
1507+ esp_netif_dhcpc_stop (espNetif);
1508+ esp_netif_dhcpc_start (espNetif);
1509+ }
1510+ }
1511+ #endif
1512+
1513+ if (0 != (updateFlags & NetworkInterface_UpdateOperation_Mac))
1514+ {
1515+ memcpy (networkInterface->hwaddr , config->MacAddress , NETIF_MAX_HWADDR_LEN);
1516+ networkInterface->hwaddr_len = NETIF_MAX_HWADDR_LEN;
1517+
1518+ // mac address requires stack re-init
1519+ Network_Interface_Close (interfaceIndex);
1520+ g_LWIP_SOCKETS_Driver.m_interfaces [interfaceIndex].m_interfaceNumber = Network_Interface_Open (interfaceIndex);
1521+ }
1522+
1523+ return S_OK;
1524+ }
1525+ #endif
13921526
13931527int LWIP_SOCKETS_Driver::GetNativeTcpOption (int optname)
13941528{
0 commit comments