Skip to content

Commit 1111216

Browse files
kghostpull[bot]
authored andcommitted
Disable WiFi/BT for qemu_esp32 (#11395)
1 parent 8925c9d commit 1111216

File tree

10 files changed

+99
-92
lines changed

10 files changed

+99
-92
lines changed

config/esp32/components/chip/Kconfig

+23
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,16 @@ menu "CHIP Device Layer"
431431

432432
menu "WiFi Station Options"
433433

434+
config ENABLE_WIFI_STATION
435+
bool "Enable CHIP WIFI STATION"
436+
default y
437+
help
438+
Enables WiFi station for CHIP.
439+
434440
config DEFAULT_WIFI_SSID
435441
string "Default WiFi SSID"
436442
default ""
443+
depends on ENABLE_WIFI_STATION
437444
help
438445
The SSID of network to connect to if no WiFi station configuration exists in NV storage
439446
at the time the device boots.
@@ -443,6 +450,7 @@ menu "CHIP Device Layer"
443450
config DEFAULT_WIFI_PASSWORD
444451
string "Default WiFi Password"
445452
default ""
453+
depends on ENABLE_WIFI_STATION
446454
help
447455
The password for the default WiFi network.
448456

@@ -452,20 +460,23 @@ menu "CHIP Device Layer"
452460
int "WiFi Station Interface Reconnect Interval (ms)"
453461
range 0 65535
454462
default 5000
463+
depends on ENABLE_WIFI_STATION
455464
help
456465
The interval at which the CHIP platform will attempt to reconnect to the configured WiFi network (in milliseconds).
457466

458467
config MAX_SCAN_NETWORKS_RESULTS
459468
int "Max ScanNetworks Results"
460469
range 0 65535
461470
default 10
471+
depends on ENABLE_WIFI_STATION
462472
help
463473
The maximum number of networks to return as a result of a CHIP NetworkProvisioning:ScanNetworks request.
464474

465475
config WIFI_SCAN_COMPLETION_TIMEOUT
466476
int "WiFi Scan Completion Timeout (ms)"
467477
range 0 65535
468478
default 10000
479+
depends on ENABLE_WIFI_STATION
469480
help
470481
The amount of time (in milliseconds) after which the CHIP platform will timeout a WiFi scan
471482
operation that hasn't completed. A value of 0 will disable the timeout logic.
@@ -474,6 +485,7 @@ menu "CHIP Device Layer"
474485
int "WiFi Connectivity Timeout (ms)"
475486
range 0 65535
476487
default 30000
488+
depends on ENABLE_WIFI_STATION
477489
help
478490
The amount of time (in milliseconds) to wait for Internet connectivity to be established on
479491
the device's WiFi station interface during a Network Provisioning TestConnectivity operation.
@@ -482,9 +494,16 @@ menu "CHIP Device Layer"
482494

483495
menu "WiFi AP Options"
484496

497+
config ENABLE_WIFI_AP
498+
bool "Enable CHIP WIFI AP"
499+
default y
500+
help
501+
Enables WiFi AP for CHIP.
502+
485503
config WIFI_AP_SSID_PREFIX
486504
string "WiFi AP SSID Prefix"
487505
default "MATTER-"
506+
depends on ENABLE_WIFI_AP
488507
help
489508
A prefix string used in forming the WiFi soft-AP SSID. The remainder of the SSID
490509
consists of the final two bytes of the device's primary WiFi MAC address in hex.
@@ -493,27 +512,31 @@ menu "CHIP Device Layer"
493512
int "WiFi AP Channel"
494513
range 1 14
495514
default 1
515+
depends on ENABLE_WIFI_AP
496516
help
497517
The WiFi channel number to be used by the soft-AP.
498518

499519
config WIFI_AP_MAX_STATIONS
500520
int "WiFi AP Max Allowed Stations"
501521
range 1 10
502522
default 4
523+
depends on ENABLE_WIFI_AP
503524
help
504525
The maximum number of stations allowed to connect to the soft-AP.
505526

506527
config WIFI_AP_BEACON_INTERVAL
507528
int "WiFi AP Beacon Interval (ms)"
508529
range 100 60000
509530
default 100
531+
depends on ENABLE_WIFI_AP
510532
help
511533
The beacon interval (in milliseconds) for the WiFi soft-AP.
512534

513535
config WIFI_AP_IDLE_TIMEOUT
514536
int "WiFi AP Idle Timeout (ms)"
515537
range 0 600000
516538
default 120000
539+
depends on ENABLE_WIFI_AP
517540
help
518541
The amount of time (in milliseconds) after which the CHIP platform will deactivate the soft-AP
519542
if it has been idle.

src/include/platform/PlatformManager.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ inline CHIP_ERROR PlatformManager::StopEventLoopTask()
393393
*/
394394
inline CHIP_ERROR PlatformManager::Shutdown()
395395
{
396-
mInitialized = false;
397-
return static_cast<ImplClass *>(this)->_Shutdown();
396+
CHIP_ERROR err = static_cast<ImplClass *>(this)->_Shutdown();
397+
if (err == CHIP_NO_ERROR)
398+
mInitialized = false;
399+
return err;
398400
}
399401

400402
inline void PlatformManager::LockChipStack()

src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::PostEventFromISR(const Chip
245245
template <class ImplClass>
246246
CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_Shutdown(void)
247247
{
248-
VerifyOrDieWithMsg(false, DeviceLayer, "Shutdown is not implemented");
249248
return CHIP_ERROR_NOT_IMPLEMENTED;
250249
}
251250

src/platform/ESP32/CHIPPlatformConfig.h

+12
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@
9696
#define CHIP_CONFIG_ENABLE_CASE_INITIATOR CONFIG_ENABLE_CASE_INITIATOR
9797
#define CHIP_CONFIG_ENABLE_CASE_RESPONDER CONFIG_ENABLE_CASE_RESPONDER
9898
#define CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT
99+
100+
#ifdef CONFIG_ENABLE_WIFI_STATION
101+
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1
102+
#else
103+
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
104+
#endif
105+
106+
#ifdef CONFIG_ENABLE_WIFI_AP
107+
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1
108+
#else
109+
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
110+
#endif

src/platform/ESP32/ConnectivityManagerImpl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
124124
CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate);
125125
CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount);
126126

127-
// ===== Members for internal use by the following friends.
128-
129-
friend ConnectivityManager & ConnectivityMgr(void);
130-
friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);
131-
132127
// ===== Private members reserved for use by this class only.
133128

134129
System::Clock::Timestamp mLastStationConnectFailTime;
@@ -162,6 +157,11 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
162157

163158
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
164159

160+
// ===== Members for internal use by the following friends.
161+
162+
friend ConnectivityManager & ConnectivityMgr(void);
163+
friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);
164+
165165
static ConnectivityManagerImpl sInstance;
166166
};
167167

src/platform/ESP32/PlatformManagerImpl.cpp

+27-24
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
6161
// Arrange for CHIP-encapsulated ESP32 errors to be translated to text
6262
Internal::ESP32Utils::RegisterESP32ErrorFormatter();
6363

64-
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
65-
wifi_init_config_t cfg;
66-
uint8_t ap_mac[6];
67-
wifi_mode_t mode;
6864
// Make sure the LwIP core lock has been initialized
6965
ReturnErrorOnFailure(Internal::InitLwIPCoreLock());
66+
7067
err = esp_netif_init();
7168
if (err != ESP_OK)
7269
{
7370
goto exit;
7471
}
75-
#endif
72+
7673
// Arrange for the ESP event loop to deliver events into the CHIP Device layer.
7774
err = esp_event_loop_create_default();
7875
if (err != ESP_OK)
@@ -81,32 +78,38 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
8178
}
8279

8380
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
84-
esp_netif_create_default_wifi_ap();
85-
esp_netif_create_default_wifi_sta();
81+
{
82+
wifi_init_config_t cfg;
83+
uint8_t ap_mac[6];
84+
wifi_mode_t mode;
8685

87-
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
88-
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
89-
mStartTime = System::SystemClock().GetMonotonicTimestamp();
86+
esp_netif_create_default_wifi_ap();
87+
esp_netif_create_default_wifi_sta();
9088

91-
// Initialize the ESP WiFi layer.
92-
cfg = WIFI_INIT_CONFIG_DEFAULT();
93-
err = esp_wifi_init(&cfg);
94-
if (err != ESP_OK)
95-
{
96-
goto exit;
97-
}
89+
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
90+
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
91+
mStartTime = System::SystemClock().GetMonotonicTimestamp();
9892

99-
esp_wifi_get_mode(&mode);
100-
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA))
101-
{
102-
esp_fill_random(ap_mac, sizeof(ap_mac));
103-
/* Bit 0 of the first octet of MAC Address should always be 0 */
104-
ap_mac[0] &= (uint8_t) ~0x01;
105-
err = esp_wifi_set_mac(WIFI_IF_AP, ap_mac);
93+
// Initialize the ESP WiFi layer.
94+
cfg = WIFI_INIT_CONFIG_DEFAULT();
95+
err = esp_wifi_init(&cfg);
10696
if (err != ESP_OK)
10797
{
10898
goto exit;
10999
}
100+
101+
esp_wifi_get_mode(&mode);
102+
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA))
103+
{
104+
esp_fill_random(ap_mac, sizeof(ap_mac));
105+
/* Bit 0 of the first octet of MAC Address should always be 0 */
106+
ap_mac[0] &= (uint8_t) ~0x01;
107+
err = esp_wifi_set_mac(WIFI_IF_AP, ap_mac);
108+
if (err != ESP_OK)
109+
{
110+
goto exit;
111+
}
112+
}
110113
}
111114
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
112115

src/platform/Zephyr/PlatformManagerImpl.h

+12
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,17 @@ inline PlatformManager & PlatformMgr(void)
7777
{
7878
return PlatformManagerImpl::sInstance;
7979
}
80+
81+
/**
82+
* Returns the platform-specific implementation of the PlatformManager singleton object.
83+
*
84+
* chip applications can use this to gain access to features of the PlatformManager
85+
* that are specific to the ESP32 platform.
86+
*/
87+
inline PlatformManagerImpl & PlatformMgrImpl()
88+
{
89+
return PlatformManagerImpl::sInstance;
90+
}
91+
8092
} // namespace DeviceLayer
8193
} // namespace chip

src/system/tests/TestSystemPacketBuffer.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <lib/support/CHIPMem.h>
3838
#include <lib/support/CodeUtils.h>
3939
#include <lib/support/UnitTestRegistration.h>
40+
#include <platform/CHIPDeviceLayer.h>
4041
#include <system/SystemPacketBuffer.h>
4142

4243
#if CHIP_SYSTEM_CONFIG_USE_LWIP
@@ -214,6 +215,10 @@ PacketBufferTest::PacketBufferTest(TestContext * context) : mContext(context)
214215
int PacketBufferTest::TestSetup(void * inContext)
215216
{
216217
chip::Platform::MemoryInit();
218+
219+
if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR)
220+
return FAILURE;
221+
217222
TestContext * const theContext = reinterpret_cast<TestContext *>(inContext);
218223
theContext->test = new PacketBufferTest(theContext);
219224
if (theContext->test == nullptr)
@@ -225,6 +230,11 @@ int PacketBufferTest::TestSetup(void * inContext)
225230

226231
int PacketBufferTest::TestTeardown(void * inContext)
227232
{
233+
CHIP_ERROR err = chip::DeviceLayer::PlatformMgr().Shutdown();
234+
// RTOS shutdown is not implemented, ignore CHIP_ERROR_NOT_IMPLEMENTED
235+
if (err != CHIP_NO_ERROR && err != CHIP_ERROR_NOT_IMPLEMENTED)
236+
return FAILURE;
237+
228238
return SUCCESS;
229239
}
230240

src/test_driver/esp32/main/main_app.cpp

+1-59
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ using namespace ::chip::DeviceLayer;
3838

3939
const char * TAG = "CHIP-tests";
4040

41-
static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen)
42-
{
43-
esp_fill_random(output, len);
44-
*olen = len;
45-
return 0;
46-
}
47-
4841
static void tester_task(void * pvParameters)
4942
{
5043
ESP_LOGI(TAG, "Starting CHIP tests!");
@@ -74,56 +67,5 @@ extern "C" void app_main()
7467
exit(err);
7568
}
7669

77-
// Initialize the LwIP core lock. This must be done before the ESP
78-
// tcpip_adapter layer is initialized.
79-
CHIP_ERROR error = PlatformMgrImpl().InitLwIPCoreLock();
80-
if (error != CHIP_NO_ERROR)
81-
{
82-
ESP_LOGE(TAG, "PlatformMgr().InitLocks() failed: %s", ErrorStr(error));
83-
exit(1);
84-
}
85-
86-
err = esp_netif_init();
87-
if (err != ESP_OK)
88-
{
89-
ESP_LOGE(TAG, "esp_netif_init() failed: %s", esp_err_to_name(err));
90-
exit(err);
91-
}
92-
93-
// Arrange for the ESP event loop to deliver events into the CHIP Device layer.
94-
err = esp_event_loop_create_default();
95-
if (err != ESP_OK)
96-
{
97-
ESP_LOGE(TAG, "esp_event_loop_create_default() failed: %s", esp_err_to_name(err));
98-
exit(err);
99-
}
100-
esp_netif_create_default_wifi_ap();
101-
esp_netif_create_default_wifi_sta();
102-
103-
err = esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
104-
if (err != ESP_OK)
105-
{
106-
ESP_LOGE(TAG, "esp_event_handler_register() failed for WIFI_EVENT: %s", esp_err_to_name(err));
107-
exit(err);
108-
}
109-
err = esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
110-
if (err != ESP_OK)
111-
{
112-
ESP_LOGE(TAG, "esp_event_handler_register() failed for IP_EVENT: %s", esp_err_to_name(err));
113-
exit(err);
114-
}
115-
116-
error = Crypto::add_entropy_source(app_entropy_source, NULL, 16);
117-
if (error != CHIP_NO_ERROR)
118-
{
119-
ESP_LOGE(TAG, "add_entropy_source() failed: %s", ErrorStr(error));
120-
exit(error.AsInteger());
121-
}
122-
123-
xTaskCreate(tester_task, "tester", 12288, (void *) NULL, tskIDLE_PRIORITY + 10, NULL);
124-
125-
while (1)
126-
{
127-
vTaskDelay(50 / portTICK_PERIOD_MS);
128-
}
70+
tester_task(nullptr);
12971
}

src/test_driver/esp32/sdkconfig_qemu.defaults

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ CONFIG_ESP32_PANIC_PRINT_REBOOT=y
3535
CONFIG_ESP32_PANIC_PRINT_HALT=n
3636

3737
# enable BT
38-
CONFIG_BT_ENABLED=y
38+
CONFIG_BT_ENABLED=n
39+
40+
# disable WiFi
41+
CONFIG_ENABLE_WIFI_STATION=n
42+
CONFIG_ENABLE_WIFI_AP=n
3943

4044
# Use a custom partition table
4145
CONFIG_PARTITION_TABLE_CUSTOM=y

0 commit comments

Comments
 (0)