Skip to content

Commit

Permalink
[wifi] combine ipv4 and ipv6 event so that dns server will start only…
Browse files Browse the repository at this point in the history
… when ipv6 is ready (#27884)
  • Loading branch information
pankore authored and pull[bot] committed Aug 8, 2023
1 parent 08fa1c9 commit 1444414
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
63 changes: 22 additions & 41 deletions src/platform/Ameba/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,53 +758,23 @@ void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
}
}

void ConnectivityManagerImpl::OnStationIPv4AddressAvailable(void)
void ConnectivityManagerImpl::OnStationIPv4v6AddressAvailable(void)
{
uint8_t * ip = LwIP_GetIP(&xnetif[0]);
uint8_t * gw = LwIP_GetGW(&xnetif[0]);
uint8_t * msk = LwIP_GetMASK(&xnetif[0]);
#if CHIP_PROGRESS_LOGGING
{
ChipLogProgress(DeviceLayer, "\n\r\tIP => %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
ChipLogProgress(DeviceLayer, "\n\r\tGW => %d.%d.%d.%d\n\r", gw[0], gw[1], gw[2], gw[3]);
ChipLogProgress(DeviceLayer, "\n\r\tmsk => %d.%d.%d.%d\n\r", msk[0], msk[1], msk[2], msk[3]);
}
#endif // CHIP_PROGRESS_LOGGING

RefreshMessageLayer();

UpdateInternetConnectivityState();

ChipDeviceEvent event;
event.Type = DeviceEventType::kInterfaceIpAddressChanged;
event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Assigned;
PlatformMgr().PostEventOrDie(&event);
}

void ConnectivityManagerImpl::OnStationIPv4AddressLost(void)
{
ChipLogProgress(DeviceLayer, "IPv4 address lost on WiFi station interface");

RefreshMessageLayer();

UpdateInternetConnectivityState();

ChipDeviceEvent event;
event.Type = DeviceEventType::kInterfaceIpAddressChanged;
event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Lost;
PlatformMgr().PostEventOrDie(&event);
}

void ConnectivityManagerImpl::OnIPv6AddressAvailable(void)
{
#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0
#if LWIP_IPV6
uint8_t * ipv6_0 = LwIP_GetIPv6_linklocal(&xnetif[0]);
uint8_t * ipv6_1 = LwIP_GetIPv6_global(&xnetif[0]);
#endif
#endif // LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0

#if CHIP_PROGRESS_LOGGING
{
ChipLogProgress(DeviceLayer, "\n\r\tIP => %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
ChipLogProgress(DeviceLayer, "\n\r\tGW => %d.%d.%d.%d\n\r", gw[0], gw[1], gw[2], gw[3]);
ChipLogProgress(DeviceLayer, "\n\r\tmsk => %d.%d.%d.%d\n\r", msk[0], msk[1], msk[2], msk[3]);
#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0
#if LWIP_IPV6
ChipLogProgress(DeviceLayer,
Expand All @@ -830,6 +800,20 @@ void ConnectivityManagerImpl::OnIPv6AddressAvailable(void)
PlatformMgr().PostEventOrDie(&event);
}

void ConnectivityManagerImpl::OnStationIPv4v6AddressLost(void)
{
ChipLogProgress(DeviceLayer, "IPv4 address lost on WiFi station interface");

RefreshMessageLayer();

UpdateInternetConnectivityState();

ChipDeviceEvent event;
event.Type = DeviceEventType::kInterfaceIpAddressChanged;
event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Lost;
PlatformMgr().PostEventOrDie(&event);
}

void ConnectivityManagerImpl::RefreshMessageLayer(void) {}

void ConnectivityManagerImpl::RtkWiFiStationConnectedHandler(char * buf, int buf_len, int flags, void * userdata)
Expand Down Expand Up @@ -859,17 +843,14 @@ void ConnectivityManagerImpl::RtkWiFiScanCompletedHandler(void)
void ConnectivityManagerImpl::DHCPProcessThread(void * param)
{
matter_lwip_dhcp();
PlatformMgr().LockChipStack();
sInstance.OnStationIPv4AddressAvailable();
PlatformMgr().UnlockChipStack();
#if LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0
#if LWIP_IPV6
matter_lwip_dhcp6();
PlatformMgr().LockChipStack();
sInstance.OnIPv6AddressAvailable();
PlatformMgr().UnlockChipStack();
#endif
#endif // LWIP_VERSION_MAJOR > 2 || LWIP_VERSION_MINOR > 0
PlatformMgr().LockChipStack();
sInstance.OnStationIPv4v6AddressAvailable();
PlatformMgr().UnlockChipStack();
vTaskDelete(NULL);
}

Expand Down
5 changes: 2 additions & 3 deletions src/platform/Ameba/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState);

void UpdateInternetConnectivityState(void);
void OnStationIPv4AddressAvailable(void);
void OnStationIPv4AddressLost(void);
void OnIPv6AddressAvailable(void);
void OnStationIPv4v6AddressAvailable(void);
void OnStationIPv4v6AddressLost(void);

#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

Expand Down

0 comments on commit 1444414

Please sign in to comment.