Skip to content

Commit 8d8b636

Browse files
[TI]Use ip-acquired indication to trigger dns server (project-chip#21891)
* use ip-acquired indication to trigger dns server * Restyled by clang-format Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 9dbfa91 commit 8d8b636

File tree

6 files changed

+51
-33
lines changed

6 files changed

+51
-33
lines changed

examples/lock-app/cc32xx/main/AppTask.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ extern int WiFi_init();
4848
extern void DisplayBanner();
4949
}
5050

51-
/* Application Version and Naming*/
52-
5351
#define APP_TASK_STACK_SIZE (4096)
5452
#define APP_TASK_PRIORITY 4
5553
#define APP_EVENT_QUEUE_SIZE 10
@@ -172,9 +170,6 @@ int AppTask::Init()
172170
PLAT_LOG("Print Onboarding Codes");
173171
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kOnNetwork));
174172

175-
PLAT_LOG("Start DNS Server");
176-
chip::app::DnssdServer::Instance().StartServer();
177-
178173
return 0;
179174
}
180175

src/platform/cc32xx/CC32XXConfig.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ CHIP_ERROR CC32XXConfig::ReadConfigValue(Key key, bool & val)
342342
CHIP_ERROR ret;
343343
size_t ignore;
344344
uint8_t localVal;
345-
cc32xxLog("[%s]", __FUNCTION__);
345+
cc32xxLog("[%s] %s", __FUNCTION__, key.key);
346346

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

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

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

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

@@ -411,22 +411,25 @@ CHIP_ERROR CC32XXConfig::WriteConfigValueStr(Key key, const char * str, size_t s
411411
CHIP_ERROR CC32XXConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
412412
{
413413
cc32xxLog("[%s]", __FUNCTION__);
414+
414415
CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
415416
err = pList->AddEntryByKey(key.key, data, (uint16_t) dataLen);
416417
return err;
417418
}
418419

419420
CHIP_ERROR CC32XXConfig::ClearConfigValue(Key key)
420421
{
421-
cc32xxLog("[%s]", __FUNCTION__);
422+
cc32xxLog("[%s] %s", __FUNCTION__, key.key);
423+
422424
CHIP_ERROR err = CHIP_NO_ERROR;
423425
pList->DeleteEntryByKey(key.key);
424426
return err;
425427
}
426428

427429
bool CC32XXConfig::ConfigValueExists(Key key)
428430
{
429-
cc32xxLog("[%s]", __FUNCTION__);
431+
cc32xxLog("[%s] %s", __FUNCTION__, key.key);
432+
430433
bool ret = false;
431434
CC32XXKVSEntry * pEntry = pList->GetEntryByKey(key.key);
432435
if (pEntry)
@@ -436,7 +439,8 @@ bool CC32XXConfig::ConfigValueExists(Key key)
436439

437440
CHIP_ERROR CC32XXConfig::FactoryResetConfig()
438441
{
439-
cc32xxLog("[%s]", __FUNCTION__);
442+
cc32xxLog("[%s] ", __FUNCTION__);
443+
440444
while (1)
441445
;
442446
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -445,7 +449,8 @@ CHIP_ERROR CC32XXConfig::FactoryResetConfig()
445449

446450
void CC32XXConfig::RunConfigUnitTest()
447451
{
448-
cc32xxLog("[%s]", __FUNCTION__);
452+
cc32xxLog("[%s] ", __FUNCTION__);
453+
449454
// Run common unit test.
450455
::chip::DeviceLayer::Internal::RunConfigUnitTest<CC32XXConfig>();
451456
}

src/platform/cc32xx/ConnectivityManagerImpl.cpp

+32-16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <platform/cc32xx/CC32XXConfig.h>
3939

40+
#include <app/server/Dnssd.h>
4041
#include <lwip/dns.h>
4142
#include <lwip/ip_addr.h>
4243
#include <lwip/nd6.h>
@@ -46,10 +47,8 @@
4647

4748
extern "C" {
4849
#include <ti/net/slnetconn.h>
49-
5050
#define SLNETCONN_TIMEOUT 0xffff // "infinite" Timeout
5151

52-
extern int LWIP_IF_start();
5352
extern void SlNetConnEventHandler(uint32_t ifID, SlNetConnStatus_e netStatus, void * data);
5453
}
5554

@@ -67,6 +66,7 @@ using namespace ::chip::System;
6766
using namespace ::chip::TLV;
6867

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

7171
namespace chip {
7272
namespace DeviceLayer {
@@ -141,22 +141,26 @@ CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWifiStatsCounters(void)
141141

142142
CHIP_ERROR ConnectivityManagerImpl::_Init()
143143
{
144-
145-
cc32xxLog("ConnectivityManagerImpl::_Init()\n\r");
146-
147144
int rc;
148-
cc32xxLog("Start Wi-Fi\r\n");
149-
/* Try to connect to AP and go through provisioning (if needed) */
150-
rc = SlNetConn_start(SLNETCONN_SERVICE_LVL_MAC, SlNetConnEventHandler, SLNETCONN_TIMEOUT, 0);
151-
assert(rc == 0);
152-
153-
cc32xxLog("Start LWIP IF\n\r");
154-
rc = LWIP_IF_start();
155-
if (rc != 0)
145+
cc32xxLog("Start LWIP");
146+
rc = LWIP_IF_init(_OnLwipEvent, false);
147+
if (rc == 0)
156148
{
157-
cc32xxLog("LWIP IF not started, error = ", rc);
149+
m_pNetIf = LWIP_IF_addInterface();
158150
}
151+
if (m_pNetIf == NULL)
152+
{
153+
cc32xxLog("LWIP IF not started, error = %d", rc);
154+
}
155+
else
156+
{
157+
cc32xxLog("Start Wi-Fi");
158+
/* Try to connect to AP and go through provisioning (if needed) */
159+
rc = SlNetConn_start(SLNETCONN_SERVICE_LVL_MAC, SlNetConnEventHandler, SLNETCONN_TIMEOUT, 0);
160+
assert(rc == 0);
159161

162+
LWIP_IF_setLinkUp(m_pNetIf);
163+
}
160164
return CHIP_NO_ERROR;
161165
}
162166

@@ -189,10 +193,22 @@ void ConnectivityManagerImpl::_OnWiFiStationProvisionChange()
189193
}
190194

191195
// ==================== ConnectivityManager Private Methods ====================
196+
void ConnectivityManagerImpl::_OnLwipEvent(struct netif * pNetIf, NetIfStatus_e status, void * pParams)
197+
{
198+
switch (status)
199+
{
200+
case E_NETIF_STATUS_IP_ACQUIRED:
201+
PlatformMgr().ScheduleWork(_OnIpAcquired);
202+
break;
203+
default:
204+
break;
205+
}
206+
}
192207

193-
void ConnectivityManagerImpl::DriveStationState()
208+
void ConnectivityManagerImpl::_OnIpAcquired(intptr_t arg)
194209
{
195-
cc32xxLog("ConnectivityManagerImpl::DriveStationState()\n\r");
210+
cc32xxLog("ConnectivityManagerImpl::OnIpAcquired() : Start DNS Server");
211+
chip::app::DnssdServer::Instance().StartServer();
196212
}
197213

198214
void ConnectivityManagerImpl::OnStationConnected()

src/platform/cc32xx/ConnectivityManagerImpl.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#endif
4040
#include <platform/internal/GenericConnectivityManagerImpl_NoThread.h>
4141

42+
extern "C" {
43+
#include "lwip_if.h"
44+
}
45+
4246
namespace chip {
4347
namespace Inet {
4448

@@ -122,16 +126,14 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
122126
uint32_t mWiFiAPIdleTimeoutMS;
123127
uint16_t mFlags;
124128

125-
void DriveStationState(void);
126129
void OnStationConnected(void);
127130
void OnStationDisconnected(void);
128131
void ChangeWiFiStationState(WiFiStationState newState);
129-
// static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState, ::chip::System::Error aError);
130132

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

136138
void UpdateInternetConnectivityState(void);
137139
void OnStationIPv4AddressAvailable();

src/platform/cc32xx/InetPlatformConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#endif // INET_CONFIG_NUM_TCP_ENDPOINTS
4646

4747
#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS
48-
#define INET_CONFIG_NUM_UDP_ENDPOINTS 4
48+
#define INET_CONFIG_NUM_UDP_ENDPOINTS 8
4949
#endif // INET_CONFIG_NUM_UDP_ENDPOINTS
5050

5151
#endif // INET_PLATFORM_CONFIG_H

0 commit comments

Comments
 (0)