Skip to content

Commit

Permalink
[TI]Use ip-acquired indication to trigger dns server (project-chip#21891
Browse files Browse the repository at this point in the history
)

* use ip-acquired indication to trigger dns server

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and isiu-apple committed Sep 16, 2022
1 parent 5d547c5 commit 2a490f4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
5 changes: 0 additions & 5 deletions examples/lock-app/cc32xx/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ extern int WiFi_init();
extern void DisplayBanner();
}

/* Application Version and Naming*/

#define APP_TASK_STACK_SIZE (4096)
#define APP_TASK_PRIORITY 4
#define APP_EVENT_QUEUE_SIZE 10
Expand Down Expand Up @@ -172,9 +170,6 @@ int AppTask::Init()
PLAT_LOG("Print Onboarding Codes");
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kOnNetwork));

PLAT_LOG("Start DNS Server");
chip::app::DnssdServer::Instance().StartServer();

return 0;
}

Expand Down
17 changes: 11 additions & 6 deletions src/platform/cc32xx/CC32XXConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ CHIP_ERROR CC32XXConfig::ReadConfigValue(Key key, bool & val)
CHIP_ERROR ret;
size_t ignore;
uint8_t localVal;
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] %s", __FUNCTION__, key.key);

ret = ReadConfigValueBin(key, &localVal, sizeof(localVal), ignore);

Expand Down Expand Up @@ -371,7 +371,7 @@ CHIP_ERROR CC32XXConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize,

CHIP_ERROR CC32XXConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
{
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] %s", __FUNCTION__, key.key);

CC32XXKVSEntry * pEntry = pList->GetEntryByKey(key.key);

Expand Down Expand Up @@ -411,22 +411,25 @@ CHIP_ERROR CC32XXConfig::WriteConfigValueStr(Key key, const char * str, size_t s
CHIP_ERROR CC32XXConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
{
cc32xxLog("[%s]", __FUNCTION__);

CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
err = pList->AddEntryByKey(key.key, data, (uint16_t) dataLen);
return err;
}

CHIP_ERROR CC32XXConfig::ClearConfigValue(Key key)
{
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] %s", __FUNCTION__, key.key);

CHIP_ERROR err = CHIP_NO_ERROR;
pList->DeleteEntryByKey(key.key);
return err;
}

bool CC32XXConfig::ConfigValueExists(Key key)
{
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] %s", __FUNCTION__, key.key);

bool ret = false;
CC32XXKVSEntry * pEntry = pList->GetEntryByKey(key.key);
if (pEntry)
Expand All @@ -436,7 +439,8 @@ bool CC32XXConfig::ConfigValueExists(Key key)

CHIP_ERROR CC32XXConfig::FactoryResetConfig()
{
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] ", __FUNCTION__);

while (1)
;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -445,7 +449,8 @@ CHIP_ERROR CC32XXConfig::FactoryResetConfig()

void CC32XXConfig::RunConfigUnitTest()
{
cc32xxLog("[%s]", __FUNCTION__);
cc32xxLog("[%s] ", __FUNCTION__);

// Run common unit test.
::chip::DeviceLayer::Internal::RunConfigUnitTest<CC32XXConfig>();
}
Expand Down
48 changes: 32 additions & 16 deletions src/platform/cc32xx/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <platform/cc32xx/CC32XXConfig.h>

#include <app/server/Dnssd.h>
#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#include <lwip/nd6.h>
Expand All @@ -46,10 +47,8 @@

extern "C" {
#include <ti/net/slnetconn.h>

#define SLNETCONN_TIMEOUT 0xffff // "infinite" Timeout

extern int LWIP_IF_start();
extern void SlNetConnEventHandler(uint32_t ifID, SlNetConnStatus_e netStatus, void * data);
}

Expand All @@ -67,6 +66,7 @@ using namespace ::chip::System;
using namespace ::chip::TLV;

extern "C" void cc32xxLog(const char * aFormat, ...);
static struct netif * m_pNetIf = NULL;

namespace chip {
namespace DeviceLayer {
Expand Down Expand Up @@ -141,22 +141,26 @@ CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWifiStatsCounters(void)

CHIP_ERROR ConnectivityManagerImpl::_Init()
{

cc32xxLog("ConnectivityManagerImpl::_Init()\n\r");

int rc;
cc32xxLog("Start Wi-Fi\r\n");
/* Try to connect to AP and go through provisioning (if needed) */
rc = SlNetConn_start(SLNETCONN_SERVICE_LVL_MAC, SlNetConnEventHandler, SLNETCONN_TIMEOUT, 0);
assert(rc == 0);

cc32xxLog("Start LWIP IF\n\r");
rc = LWIP_IF_start();
if (rc != 0)
cc32xxLog("Start LWIP");
rc = LWIP_IF_init(_OnLwipEvent, false);
if (rc == 0)
{
cc32xxLog("LWIP IF not started, error = ", rc);
m_pNetIf = LWIP_IF_addInterface();
}
if (m_pNetIf == NULL)
{
cc32xxLog("LWIP IF not started, error = %d", rc);
}
else
{
cc32xxLog("Start Wi-Fi");
/* Try to connect to AP and go through provisioning (if needed) */
rc = SlNetConn_start(SLNETCONN_SERVICE_LVL_MAC, SlNetConnEventHandler, SLNETCONN_TIMEOUT, 0);
assert(rc == 0);

LWIP_IF_setLinkUp(m_pNetIf);
}
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -189,10 +193,22 @@ void ConnectivityManagerImpl::_OnWiFiStationProvisionChange()
}

// ==================== ConnectivityManager Private Methods ====================
void ConnectivityManagerImpl::_OnLwipEvent(struct netif * pNetIf, NetIfStatus_e status, void * pParams)
{
switch (status)
{
case E_NETIF_STATUS_IP_ACQUIRED:
PlatformMgr().ScheduleWork(_OnIpAcquired);
break;
default:
break;
}
}

void ConnectivityManagerImpl::DriveStationState()
void ConnectivityManagerImpl::_OnIpAcquired(intptr_t arg)
{
cc32xxLog("ConnectivityManagerImpl::DriveStationState()\n\r");
cc32xxLog("ConnectivityManagerImpl::OnIpAcquired() : Start DNS Server");
chip::app::DnssdServer::Instance().StartServer();
}

void ConnectivityManagerImpl::OnStationConnected()
Expand Down
10 changes: 6 additions & 4 deletions src/platform/cc32xx/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#endif
#include <platform/internal/GenericConnectivityManagerImpl_NoThread.h>

extern "C" {
#include "lwip_if.h"
}

namespace chip {
namespace Inet {

Expand Down Expand Up @@ -122,16 +126,14 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
uint32_t mWiFiAPIdleTimeoutMS;
uint16_t mFlags;

void DriveStationState(void);
void OnStationConnected(void);
void OnStationDisconnected(void);
void ChangeWiFiStationState(WiFiStationState newState);
// static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError);

void DriveAPState(void);
static void _OnLwipEvent(struct netif * pNetIf, NetIfStatus_e status, void * pParams);
static void _OnIpAcquired(intptr_t arg);
CHIP_ERROR ConfigureWiFiAP(void);
void ChangeWiFiAPState(WiFiAPState newState);
// static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError);

void UpdateInternetConnectivityState(void);
void OnStationIPv4AddressAvailable();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/cc32xx/InetPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#endif // INET_CONFIG_NUM_TCP_ENDPOINTS

#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS
#define INET_CONFIG_NUM_UDP_ENDPOINTS 4
#define INET_CONFIG_NUM_UDP_ENDPOINTS 8
#endif // INET_CONFIG_NUM_UDP_ENDPOINTS

#endif // INET_PLATFORM_CONFIG_H

0 comments on commit 2a490f4

Please sign in to comment.