Skip to content

Commit

Permalink
Disable WiFi/BT for qemu_esp32 (#11395)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and pull[bot] committed Nov 22, 2021
1 parent 4a1080f commit 5c956a8
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 92 deletions.
23 changes: 23 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,16 @@ menu "CHIP Device Layer"

menu "WiFi Station Options"

config ENABLE_WIFI_STATION
bool "Enable CHIP WIFI STATION"
default y
help
Enables WiFi station for CHIP.

config DEFAULT_WIFI_SSID
string "Default WiFi SSID"
default ""
depends on ENABLE_WIFI_STATION
help
The SSID of network to connect to if no WiFi station configuration exists in NV storage
at the time the device boots.
Expand All @@ -443,6 +450,7 @@ menu "CHIP Device Layer"
config DEFAULT_WIFI_PASSWORD
string "Default WiFi Password"
default ""
depends on ENABLE_WIFI_STATION
help
The password for the default WiFi network.

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

config MAX_SCAN_NETWORKS_RESULTS
int "Max ScanNetworks Results"
range 0 65535
default 10
depends on ENABLE_WIFI_STATION
help
The maximum number of networks to return as a result of a CHIP NetworkProvisioning:ScanNetworks request.

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

menu "WiFi AP Options"

config ENABLE_WIFI_AP
bool "Enable CHIP WIFI AP"
default y
help
Enables WiFi AP for CHIP.

config WIFI_AP_SSID_PREFIX
string "WiFi AP SSID Prefix"
default "MATTER-"
depends on ENABLE_WIFI_AP
help
A prefix string used in forming the WiFi soft-AP SSID. The remainder of the SSID
consists of the final two bytes of the device's primary WiFi MAC address in hex.
Expand All @@ -493,27 +512,31 @@ menu "CHIP Device Layer"
int "WiFi AP Channel"
range 1 14
default 1
depends on ENABLE_WIFI_AP
help
The WiFi channel number to be used by the soft-AP.

config WIFI_AP_MAX_STATIONS
int "WiFi AP Max Allowed Stations"
range 1 10
default 4
depends on ENABLE_WIFI_AP
help
The maximum number of stations allowed to connect to the soft-AP.

config WIFI_AP_BEACON_INTERVAL
int "WiFi AP Beacon Interval (ms)"
range 100 60000
default 100
depends on ENABLE_WIFI_AP
help
The beacon interval (in milliseconds) for the WiFi soft-AP.

config WIFI_AP_IDLE_TIMEOUT
int "WiFi AP Idle Timeout (ms)"
range 0 600000
default 120000
depends on ENABLE_WIFI_AP
help
The amount of time (in milliseconds) after which the CHIP platform will deactivate the soft-AP
if it has been idle.
Expand Down
6 changes: 4 additions & 2 deletions src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,10 @@ inline CHIP_ERROR PlatformManager::StopEventLoopTask()
*/
inline CHIP_ERROR PlatformManager::Shutdown()
{
mInitialized = false;
return static_cast<ImplClass *>(this)->_Shutdown();
CHIP_ERROR err = static_cast<ImplClass *>(this)->_Shutdown();
if (err == CHIP_NO_ERROR)
mInitialized = false;
return err;
}

inline void PlatformManager::LockChipStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::PostEventFromISR(const Chip
template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_Shutdown(void)
{
VerifyOrDieWithMsg(false, DeviceLayer, "Shutdown is not implemented");
return CHIP_ERROR_NOT_IMPLEMENTED;
}

Expand Down
12 changes: 12 additions & 0 deletions src/platform/ESP32/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,15 @@
#define CHIP_CONFIG_ENABLE_CASE_INITIATOR CONFIG_ENABLE_CASE_INITIATOR
#define CHIP_CONFIG_ENABLE_CASE_RESPONDER CONFIG_ENABLE_CASE_RESPONDER
#define CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT

#ifdef CONFIG_ENABLE_WIFI_STATION
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1
#else
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
#endif

#ifdef CONFIG_ENABLE_WIFI_AP
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1
#else
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
#endif
10 changes: 5 additions & 5 deletions src/platform/ESP32/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate);
CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount);

// ===== Members for internal use by the following friends.

friend ConnectivityManager & ConnectivityMgr(void);
friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);

// ===== Private members reserved for use by this class only.

System::Clock::Timestamp mLastStationConnectFailTime;
Expand Down Expand Up @@ -162,6 +157,11 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

// ===== Members for internal use by the following friends.

friend ConnectivityManager & ConnectivityMgr(void);
friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);

static ConnectivityManagerImpl sInstance;
};

Expand Down
51 changes: 27 additions & 24 deletions src/platform/ESP32/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
// Arrange for CHIP-encapsulated ESP32 errors to be translated to text
Internal::ESP32Utils::RegisterESP32ErrorFormatter();

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
wifi_init_config_t cfg;
uint8_t ap_mac[6];
wifi_mode_t mode;
// Make sure the LwIP core lock has been initialized
ReturnErrorOnFailure(Internal::InitLwIPCoreLock());

err = esp_netif_init();
if (err != ESP_OK)
{
goto exit;
}
#endif

// Arrange for the ESP event loop to deliver events into the CHIP Device layer.
err = esp_event_loop_create_default();
if (err != ESP_OK)
Expand All @@ -81,32 +78,38 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
esp_netif_create_default_wifi_ap();
esp_netif_create_default_wifi_sta();
{
wifi_init_config_t cfg;
uint8_t ap_mac[6];
wifi_mode_t mode;

esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
mStartTime = System::SystemClock().GetMonotonicTimestamp();
esp_netif_create_default_wifi_ap();
esp_netif_create_default_wifi_sta();

// Initialize the ESP WiFi layer.
cfg = WIFI_INIT_CONFIG_DEFAULT();
err = esp_wifi_init(&cfg);
if (err != ESP_OK)
{
goto exit;
}
esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
mStartTime = System::SystemClock().GetMonotonicTimestamp();

esp_wifi_get_mode(&mode);
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA))
{
esp_fill_random(ap_mac, sizeof(ap_mac));
/* Bit 0 of the first octet of MAC Address should always be 0 */
ap_mac[0] &= (uint8_t) ~0x01;
err = esp_wifi_set_mac(WIFI_IF_AP, ap_mac);
// Initialize the ESP WiFi layer.
cfg = WIFI_INIT_CONFIG_DEFAULT();
err = esp_wifi_init(&cfg);
if (err != ESP_OK)
{
goto exit;
}

esp_wifi_get_mode(&mode);
if ((mode == WIFI_MODE_AP) || (mode == WIFI_MODE_APSTA))
{
esp_fill_random(ap_mac, sizeof(ap_mac));
/* Bit 0 of the first octet of MAC Address should always be 0 */
ap_mac[0] &= (uint8_t) ~0x01;
err = esp_wifi_set_mac(WIFI_IF_AP, ap_mac);
if (err != ESP_OK)
{
goto exit;
}
}
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

Expand Down
12 changes: 12 additions & 0 deletions src/platform/Zephyr/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,17 @@ inline PlatformManager & PlatformMgr(void)
{
return PlatformManagerImpl::sInstance;
}

/**
* Returns the platform-specific implementation of the PlatformManager singleton object.
*
* chip applications can use this to gain access to features of the PlatformManager
* that are specific to the ESP32 platform.
*/
inline PlatformManagerImpl & PlatformMgrImpl()
{
return PlatformManagerImpl::sInstance;
}

} // namespace DeviceLayer
} // namespace chip
10 changes: 10 additions & 0 deletions src/system/tests/TestSystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>
#include <platform/CHIPDeviceLayer.h>
#include <system/SystemPacketBuffer.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
Expand Down Expand Up @@ -214,6 +215,10 @@ PacketBufferTest::PacketBufferTest(TestContext * context) : mContext(context)
int PacketBufferTest::TestSetup(void * inContext)
{
chip::Platform::MemoryInit();

if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR)
return FAILURE;

TestContext * const theContext = reinterpret_cast<TestContext *>(inContext);
theContext->test = new PacketBufferTest(theContext);
if (theContext->test == nullptr)
Expand All @@ -225,6 +230,11 @@ int PacketBufferTest::TestSetup(void * inContext)

int PacketBufferTest::TestTeardown(void * inContext)
{
CHIP_ERROR err = chip::DeviceLayer::PlatformMgr().Shutdown();
// RTOS shutdown is not implemented, ignore CHIP_ERROR_NOT_IMPLEMENTED
if (err != CHIP_NO_ERROR && err != CHIP_ERROR_NOT_IMPLEMENTED)
return FAILURE;

return SUCCESS;
}

Expand Down
60 changes: 1 addition & 59 deletions src/test_driver/esp32/main/main_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ using namespace ::chip::DeviceLayer;

const char * TAG = "CHIP-tests";

static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen)
{
esp_fill_random(output, len);
*olen = len;
return 0;
}

static void tester_task(void * pvParameters)
{
ESP_LOGI(TAG, "Starting CHIP tests!");
Expand Down Expand Up @@ -74,56 +67,5 @@ extern "C" void app_main()
exit(err);
}

// Initialize the LwIP core lock. This must be done before the ESP
// tcpip_adapter layer is initialized.
CHIP_ERROR error = PlatformMgrImpl().InitLwIPCoreLock();
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "PlatformMgr().InitLocks() failed: %s", ErrorStr(error));
exit(1);
}

err = esp_netif_init();
if (err != ESP_OK)
{
ESP_LOGE(TAG, "esp_netif_init() failed: %s", esp_err_to_name(err));
exit(err);
}

// Arrange for the ESP event loop to deliver events into the CHIP Device layer.
err = esp_event_loop_create_default();
if (err != ESP_OK)
{
ESP_LOGE(TAG, "esp_event_loop_create_default() failed: %s", esp_err_to_name(err));
exit(err);
}
esp_netif_create_default_wifi_ap();
esp_netif_create_default_wifi_sta();

err = esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "esp_event_handler_register() failed for WIFI_EVENT: %s", esp_err_to_name(err));
exit(err);
}
err = esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent, NULL);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "esp_event_handler_register() failed for IP_EVENT: %s", esp_err_to_name(err));
exit(err);
}

error = Crypto::add_entropy_source(app_entropy_source, NULL, 16);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "add_entropy_source() failed: %s", ErrorStr(error));
exit(error.AsInteger());
}

xTaskCreate(tester_task, "tester", 12288, (void *) NULL, tskIDLE_PRIORITY + 10, NULL);

while (1)
{
vTaskDelay(50 / portTICK_PERIOD_MS);
}
tester_task(nullptr);
}
6 changes: 5 additions & 1 deletion src/test_driver/esp32/sdkconfig_qemu.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ CONFIG_ESP32_PANIC_PRINT_REBOOT=y
CONFIG_ESP32_PANIC_PRINT_HALT=n

# enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_ENABLED=n

# disable WiFi
CONFIG_ENABLE_WIFI_STATION=n
CONFIG_ENABLE_WIFI_AP=n

# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
Expand Down

0 comments on commit 5c956a8

Please sign in to comment.