From 79f85996847fbb407bb5e46187fad9652da3aca6 Mon Sep 17 00:00:00 2001 From: Thirsrin <108743108+Thirsrin@users.noreply.github.com> Date: Thu, 15 Dec 2022 20:06:36 +0530 Subject: [PATCH] wifi provisioning for efr32 in build command (#24036) --- .../light-switch-app/silabs/efr32/BUILD.gn | 21 ++++++++++++++++++- examples/lighting-app/silabs/efr32/BUILD.gn | 21 ++++++++++++++++++- examples/lock-app/silabs/efr32/BUILD.gn | 21 ++++++++++++++++++- examples/thermostat/efr32/BUILD.gn | 21 ++++++++++++++++++- examples/window-app/silabs/efr32/BUILD.gn | 21 ++++++++++++++++++- .../silabs/NetworkCommissioningWiFiDriver.cpp | 12 ++++++++++- 6 files changed, 111 insertions(+), 6 deletions(-) diff --git a/examples/light-switch-app/silabs/efr32/BUILD.gn b/examples/light-switch-app/silabs/efr32/BUILD.gn index 76bf05664cc7f1..823f733273b9eb 100644 --- a/examples/light-switch-app/silabs/efr32/BUILD.gn +++ b/examples/light-switch-app/silabs/efr32/BUILD.gn @@ -63,6 +63,12 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" } declare_args() { @@ -90,8 +96,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || disable_lcd = true } +defines = [] + # WiFi settings if (chip_enable_wifi) { + if (chip_default_wifi_ssid != "") { + defines += [ + "CHIP_ONNETWORK_PAIRING=1", + "CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] if (lwip_ipv4) { @@ -140,7 +159,7 @@ efr32_sdk("sdk") { "${examples_common_plat_dir}", ] - defines = [ + defines += [ "BOARD_ID=${silabs_board}", "OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}", ] diff --git a/examples/lighting-app/silabs/efr32/BUILD.gn b/examples/lighting-app/silabs/efr32/BUILD.gn index d2f68f8b44541e..4c2341288f3e3d 100644 --- a/examples/lighting-app/silabs/efr32/BUILD.gn +++ b/examples/lighting-app/silabs/efr32/BUILD.gn @@ -63,6 +63,12 @@ declare_args() { # Argument to force enable WPA3 security on rs91x rs91x_wpa3_only = false + + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" } declare_args() { @@ -90,6 +96,8 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || disable_lcd = true } +defines = [] + # WiFi settings if (chip_enable_wifi) { # disabling LCD for MG24 for wifi @@ -97,6 +105,17 @@ if (chip_enable_wifi) { show_qr_code = false disable_lcd = true } + if (chip_default_wifi_ssid != "") { + defines += [ + "CHIP_ONNETWORK_PAIRING=1", + "CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] if (lwip_ipv4) { @@ -145,7 +164,7 @@ efr32_sdk("sdk") { "${examples_common_plat_dir}", ] - defines = [ + defines += [ "BOARD_ID=${silabs_board}", "OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}", ] diff --git a/examples/lock-app/silabs/efr32/BUILD.gn b/examples/lock-app/silabs/efr32/BUILD.gn index 4d783ee2674c04..f07593e26bdc1f 100644 --- a/examples/lock-app/silabs/efr32/BUILD.gn +++ b/examples/lock-app/silabs/efr32/BUILD.gn @@ -63,6 +63,12 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" } declare_args() { @@ -90,8 +96,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || disable_lcd = true } +defines = [] + # WiFi settings if (chip_enable_wifi) { + if (chip_default_wifi_ssid != "") { + defines += [ + "CHIP_ONNETWORK_PAIRING=1", + "CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] if (lwip_ipv4) { @@ -140,7 +159,7 @@ efr32_sdk("sdk") { "${examples_common_plat_dir}", ] - defines = [ + defines += [ "BOARD_ID=${silabs_board}", "OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}", ] diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 2322a2ae887ded..5d058cc2e43cf6 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -61,6 +61,12 @@ declare_args() { # Argument to Disable IPv4 for wifi(rs911) chip_enable_wifi_ipv4 = false + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" + # Enable the temperature sensor # Some boards do not have a temperature sensor use_temp_sensor = silabs_board != "BRD2703A" && silabs_board != "BRD4319A" @@ -91,8 +97,21 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || disable_lcd = true } +defines = [] + # WiFi settings if (chip_enable_wifi) { + if (chip_default_wifi_ssid != "") { + defines += [ + "CHIP_ONNETWORK_PAIRING=1", + "CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] if (lwip_ipv4) { @@ -141,7 +160,7 @@ efr32_sdk("sdk") { "${examples_common_plat_dir}", ] - defines = [ + defines += [ "BOARD_ID=${silabs_board}", "OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}", ] diff --git a/examples/window-app/silabs/efr32/BUILD.gn b/examples/window-app/silabs/efr32/BUILD.gn index aa8c78f355f82c..930d7254239415 100644 --- a/examples/window-app/silabs/efr32/BUILD.gn +++ b/examples/window-app/silabs/efr32/BUILD.gn @@ -57,6 +57,12 @@ declare_args() { # Argument to force enable WPA3 security rs91x_wpa3_only = false + + #default WiFi SSID + chip_default_wifi_ssid = "" + + #default Wifi Password + chip_default_wifi_psk = "" } declare_args() { @@ -84,6 +90,8 @@ if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" || disable_lcd = true } +defines = [] + # WiFi settings if (chip_enable_wifi) { # disabling LCD for MG24 for wifi @@ -91,6 +99,17 @@ if (chip_enable_wifi) { show_qr_code = false disable_lcd = true } + if (chip_default_wifi_ssid != "") { + defines += [ + "CHIP_ONNETWORK_PAIRING=1", + "CHIP_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "CHIP_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } wifi_sdk_dir = "${chip_root}/src/platform/silabs/EFR32/wifi" efr32_lwip_defs = [ "LWIP_NETIF_API=1" ] if (lwip_ipv4) { @@ -139,7 +158,7 @@ efr32_sdk("sdk") { "${examples_common_plat_dir}", ] - defines = [ + defines += [ "BOARD_ID=${silabs_board}", "OTA_PERIODIC_TIMEOUT=${OTA_periodic_query_timeout}", ] diff --git a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp index 61c95f7f52954c..b63d617befcec8 100644 --- a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp @@ -43,6 +43,16 @@ CHIP_ERROR SlWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC mpScanCallback = nullptr; mpConnectCallback = nullptr; +#ifdef CHIP_ONNETWORK_PAIRING + memcpy(&mSavedNetwork.ssid[0], CHIP_WIFI_SSID, sizeof(CHIP_WIFI_SSID)); + memcpy(&mSavedNetwork.credentials[0], CHIP_WIFI_PSK, sizeof(CHIP_WIFI_PSK)); + credentialsLen = sizeof(CHIP_WIFI_PSK); + ssidLen = sizeof(CHIP_WIFI_SSID); + mSavedNetwork.credentialsLen = credentialsLen; + mSavedNetwork.ssidLen = ssidLen; + mStagingNetwork = mSavedNetwork; + err = CHIP_NO_ERROR; +#else // If reading fails, wifi is not provisioned, no need to go further. err = SILABSConfig::ReadConfigValueStr(SILABSConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), ssidLen); @@ -55,7 +65,7 @@ CHIP_ERROR SlWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC mSavedNetwork.credentialsLen = credentialsLen; mSavedNetwork.ssidLen = ssidLen; mStagingNetwork = mSavedNetwork; - +#endif ConnectWiFiNetwork(mSavedNetwork.ssid, ssidLen, mSavedNetwork.credentials, credentialsLen); return err; }