Skip to content

Commit

Permalink
[Telink] Commissioning using WiFi. (#34581)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-bilynskyy authored Jul 29, 2024
1 parent a49cd50 commit 37fc757
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
4 changes: 2 additions & 2 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ config NET_IPV6_NBR_CACHE
default n

config NET_MAX_CONN
default 1
default 1 if !WIFI

config NET_MAX_CONTEXTS
default 1
default 1 if !WIFI

config NET_CONFIG_INIT_TIMEOUT
default 0
Expand Down
29 changes: 10 additions & 19 deletions src/platform/telink/wifi/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <zephyr/net/net_event.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_stats.h>
#include <zephyr/posix/arpa/inet.h>

namespace chip {
namespace DeviceLayer {
Expand Down Expand Up @@ -399,21 +400,6 @@ void WiFiManager::ScanDoneHandler(Platform::UniquePtr<uint8_t> data, size_t leng
}
}

void WiFiManager::SendRouterSolicitation(System::Layer * layer, void * param)
{
net_if_start_rs(Instance().mNetIf);
Instance().mRouterSolicitationCounter++;
if (Instance().mRouterSolicitationCounter < kRouterSolicitationMaxCount)
{
DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kRouterSolicitationIntervalMs), SendRouterSolicitation,
nullptr);
}
else
{
Instance().mRouterSolicitationCounter = 0;
}
}

void WiFiManager::ConnectHandler(Platform::UniquePtr<uint8_t> data, size_t length)
{
// Validate that input data size matches the expected one.
Expand All @@ -436,10 +422,8 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr<uint8_t> data, size_t lengt
}
else // The connection has been established successfully.
{
// Workaround needed until sending Router Solicitation after connect will be done by the driver.
DeviceLayer::SystemLayer().StartTimer(
System::Clock::Milliseconds32(chip::Crypto::GetRandU16() % kMaxInitialRouterSolicitationDelayMs),
SendRouterSolicitation, nullptr);
// Now we can send/receive data via WiFi
net_if_up(InetUtils::GetWiFiInterface());

ChipLogProgress(DeviceLayer, "Connected to WiFi network");
Instance().mWiFiState = WIFI_STATE_COMPLETED;
Expand Down Expand Up @@ -491,6 +475,9 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr<uint8_t> data, size_t le
void WiFiManager::IPv6AddressChangeHandler(const void * data)
{
const in6_addr * addr = reinterpret_cast<const in6_addr *>(data);
char buf[INET6_ADDRSTRLEN];

ChipLogProgress(DeviceLayer, "IP6 address %s", inet_ntop(AF_INET6, addr, buf, INET6_ADDRSTRLEN));

// Filter out link-local addresses that are not routable outside of a local network.
if (!net_ipv6_is_ll_addr(addr))
Expand All @@ -504,6 +491,10 @@ void WiFiManager::IPv6AddressChangeHandler(const void * data)
{
ChipLogError(DeviceLayer, "Cannot post event: %" CHIP_ERROR_FORMAT, error.Format());
}
else
{
ChipLogProgress(DeviceLayer, "kDnssdRestartNeeded");
}
}
}

Expand Down

0 comments on commit 37fc757

Please sign in to comment.