Skip to content

[Silabs] Fixing the ipv4 build for the wifi devices #38830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
if (mWiFiStationState == kWiFiStationState_Connected)
{
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
haveIPv4Conn = WifiInterface::GetIstance().HasAnIPv4Address();
haveIPv4Conn = WifiInterface::GetInstance().HasAnIPv4Address();
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
haveIPv6Conn = WifiInterface::GetInstance().HasAnIPv6Address();
}
Expand Down
6 changes: 6 additions & 0 deletions src/platform/silabs/wifi/WifiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ class WifiInterface : public WifiStateProvider, public PowerSaveInterface
void NotifyIPv6Change(bool gotIPv6Addr);

#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
/**
* @brief Updates the IPv4 address in the Wi-Fi interface and notifies the application layer about the new IP address.
*
* @param[in] ip New IPv4 address
*/
void GotIPv4Address(uint32_t ip);
/**
* @brief Function notifies the PlatformManager that an IPv4 event occured on the WiFi interface.
*
Expand Down
24 changes: 0 additions & 24 deletions src/platform/silabs/wifi/lwip-support/dhcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
#define MAX_DHCP_TRIES (4)
#define NETIF_IPV4_ADDRESS(X, Y) (((X) >> (8 * Y)) & 0xFF)

/* Station IP address */
uint8_t sta_ip_addr0 = STA_IP_ADDR0_DEFAULT;
uint8_t sta_ip_addr1 = STA_IP_ADDR1_DEFAULT;
uint8_t sta_ip_addr2 = STA_IP_ADDR2_DEFAULT;
uint8_t sta_ip_addr3 = STA_IP_ADDR3_DEFAULT;
uint8_t sta_netmask_addr0 = STA_NETMASK_ADDR0_DEFAULT;
uint8_t sta_netmask_addr1 = STA_NETMASK_ADDR1_DEFAULT;
uint8_t sta_netmask_addr2 = STA_NETMASK_ADDR2_DEFAULT;
uint8_t sta_netmask_addr3 = STA_NETMASK_ADDR3_DEFAULT;
uint8_t sta_gw_addr0 = STA_GW_ADDR0_DEFAULT;
uint8_t sta_gw_addr1 = STA_GW_ADDR1_DEFAULT;
uint8_t sta_gw_addr2 = STA_GW_ADDR2_DEFAULT;
uint8_t sta_gw_addr3 = STA_GW_ADDR3_DEFAULT;

/// Current DHCP state machine state.
static volatile uint8_t dhcp_state = DHCP_OFF;

Expand Down Expand Up @@ -77,9 +63,6 @@ void dhcpclient_set_link_state(int link_up)
uint8_t dhcpclient_poll(void * arg)
{
struct netif * netif = (struct netif *) arg;
ip_addr_t ipaddr;
ip_addr_t netmask;
ip_addr_t gw;
struct dhcp * dhcp;

switch (dhcp_state)
Expand Down Expand Up @@ -110,13 +93,6 @@ uint8_t dhcpclient_poll(void * arg)
ChipLogProgress(DeviceLayer, "*ERR*DHCP: Failed");
/* Stop DHCP */
dhcp_stop(netif);

/* TODO - I am not sure that this is best */
/* Static address used */
IP_ADDR4(&ipaddr, sta_ip_addr0, sta_ip_addr1, sta_ip_addr2, sta_ip_addr3);
IP_ADDR4(&netmask, sta_netmask_addr0, sta_netmask_addr1, sta_netmask_addr2, sta_netmask_addr3);
IP_ADDR4(&gw, sta_gw_addr0, sta_gw_addr1, sta_gw_addr2, sta_gw_addr3);
netif_set_addr(netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw));
}
}
break;
Expand Down
35 changes: 16 additions & 19 deletions src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/silabs/wifi/WifiInterface.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inlcude should not have any impact since it is available through the WifiInterfaceImpl header.

#include <platform/silabs/wifi/lwip-support/dhcp_client.h>
#include <platform/silabs/wifi/lwip-support/ethernetif.h>
#include <platform/silabs/wifi/lwip-support/lwip_netif.h>
Expand Down Expand Up @@ -299,22 +300,6 @@ inline int16_t ConvertRcpiToRssi(uint32_t rcpi)
VerifyOrReturnValue(rssi >= std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::min());
return rssi;
}

#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
/**
* @brief Updates the IPv4 address in the Wi-Fi interface and notifies the application layer about the new IP address.
*
* @param[in] ip New IPv4 address
*/
void GotIPv4Address(uint32_t ip)
{
ChipLogDetail(DeviceLayer, "DHCP IP=%d.%d.%d.%d", (ip & 0xFF), (ip >> 8 & 0xFF), (ip >> 16 & 0xFF), (ip >> 24 & 0xFF));
sta_ip = ip;

NotifyIPv4Change(true);
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

} // namespace

/****************************************************************************
Expand Down Expand Up @@ -603,6 +588,16 @@ CHIP_ERROR WifiInterfaceImpl::InitWiFiStack()
return CHIP_NO_ERROR;
}

#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
void WifiInterface::GotIPv4Address(uint32_t ip)
{
ChipLogDetail(DeviceLayer, "DHCP IP=%ld.%ld.%ld.%ld", (ip & 0xFF), (ip >> 8 & 0xFF), (ip >> 16 & 0xFF), (ip >> 24 & 0xFF));
sta_ip = ip;

NotifyIPv4Change(true);
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

CHIP_ERROR WifiInterfaceImpl::GetMacAddress(sl_wfx_interface_t interface, MutableByteSpan & address)
{
VerifyOrReturnError(address.size() >= kWifiMacAddressLength, CHIP_ERROR_BUFFER_TOO_SMALL);
Expand Down Expand Up @@ -959,9 +954,11 @@ void WifiInterfaceImpl::ProcessEvents(void * arg)
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
uint8_t dhcp_state = dhcpclient_poll(sta_netif);

if ((dhcp_state == DHCP_ADDRESS_ASSIGNED) && !WifiInterfaceImpl::GetIstance().HasNotifiedIPv4())
if ((dhcp_state == DHCP_ADDRESS_ASSIGNED) && !WifiInterfaceImpl::GetInstance().HasNotifiedIPv4())
{
WifiInterface::GetInstance().GotIPv4Address((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
WifiInterfaceImpl::GetInstance().NotifyIPv4Change(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we notify that we lost the IPv4 address before notifying that have one?


WifiInterfaceImpl::GetInstance().GotIPv4Address((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
if (!hasNotifiedWifiConnectivity)
{
ChipLogProgress(DeviceLayer, "will notify WiFi connectivity");
Expand All @@ -971,7 +968,7 @@ void WifiInterfaceImpl::ProcessEvents(void * arg)
}
else if (dhcp_state == DHCP_OFF)
{
NotifyIPv4Change(false);
WifiInterfaceImpl::GetInstance().NotifyIPv4Change(false);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4
if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void WiseconnectWifiInterface::ResetConnectivityNotificationFlags(void)
}

#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
void WiseconnectWifiInterface::GotIPv4Address(uint32_t ip)
void WifiInterface::GotIPv4Address(uint32_t ip)
{
// Acquire the new IP address
for (int i = 0; i < 4; ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ class WiseconnectWifiInterface : public WifiInterface
*/
void NotifyConnectivity(void);

/**
* @brief Updates the IPv4 address in the Wi-Fi interface and notifies the application layer about the new IP address.
*
* @param[in] ip New IPv4 address
*/
void GotIPv4Address(uint32_t ip);

/**
* @brief Function resets the IP and connectiity flags and triggers the DHCP operation
*
Expand Down
Loading