From b937a322e5c8a5c90610d00a67998e711ad6b262 Mon Sep 17 00:00:00 2001 From: shchen-Lab Date: Tue, 5 Sep 2023 15:42:30 +0800 Subject: [PATCH 01/11] BL702&BL602 Support OpenNetWork --- .../BL602/NetworkCommissioningDriver.cpp | 14 ++++++--- src/platform/bouffalolab/common/BLConfig.cpp | 31 ++++++++++++++++--- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index d9dd83c923cd57..37fd652a1d5e4f 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -44,10 +44,10 @@ CHIP_ERROR BLWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC size_t ssidLen = 0; size_t credentialsLen = 0; - err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, mSavedNetwork.credentials, + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, mSavedNetwork.credentials, sizeof(mSavedNetwork.credentials), &credentialsLen); SuccessOrExit(err); - err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, mSavedNetwork.ssid, + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), &ssidLen); SuccessOrExit(err); @@ -160,8 +160,14 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, memcpy(passwd, key, keyLen); wifi_interface_t wifi_interface; wifi_interface = wifi_mgmr_sta_enable(); - wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); - + if(keyLen < 8 && keyLen != 5) + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); + } + else + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); + } return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/common/BLConfig.cpp b/src/platform/bouffalolab/common/BLConfig.cpp index de1cc24d139508..3b92f989431d42 100644 --- a/src/platform/bouffalolab/common/BLConfig.cpp +++ b/src/platform/bouffalolab/common/BLConfig.cpp @@ -111,9 +111,20 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si ef_port_env_lock(); - if (size && val) + + if (size) + { + if (val) { + ret = ef_set_env_blob(key, val, size); + } + else { + ret = EF_ENV_ARG_ERR; + } + } + else { - ret = ef_set_env_blob(key, val, size); + uint8_t value_null = 0; + ret = ef_set_env_blob(key, &value_null, size); } ef_port_env_unlock(); @@ -240,11 +251,21 @@ CHIP_ERROR BLConfig::WriteKVS(const char * key, const void * value, size_t value ef_port_env_lock(); - if (value && value_size) + + if (value_size) { - ret = ef_set_env_blob(key, value, value_size); + if (value) { + ret = ef_set_env_blob(key, value, value_size); + } + else { + ret = EF_ENV_ARG_ERR; + } + } + else + { + uint32_t value_null = 0; + ret = ef_set_env_blob(key, &value_null, value_size); } - ef_port_env_unlock(); if (ret == EF_NO_ERR) From 76c8689c6ef662f2873f1409c7c00e11b310cb4f Mon Sep 17 00:00:00 2001 From: wyhong Date: Tue, 5 Sep 2023 16:57:36 +0800 Subject: [PATCH 02/11] update sdk to support open network on bl706-wifi --- third_party/bouffalolab/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/bouffalolab/repo b/third_party/bouffalolab/repo index dbca8b07013852..0c5772fb31ad08 160000 --- a/third_party/bouffalolab/repo +++ b/third_party/bouffalolab/repo @@ -1 +1 @@ -Subproject commit dbca8b07013852985a8bcea9cc56f486f53c77bd +Subproject commit 0c5772fb31ad083cafdedc9a9de578d3abd5a234 From 14dbdacbb11f4efaba8eed808b3b751ccd8e52c3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 5 Sep 2023 09:00:50 +0000 Subject: [PATCH 03/11] Restyled by whitespace --- .../BL602/NetworkCommissioningDriver.cpp | 6 ++--- src/platform/bouffalolab/common/BLConfig.cpp | 24 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index 37fd652a1d5e4f..d3483a4040f5bb 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -47,8 +47,8 @@ CHIP_ERROR BLWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, mSavedNetwork.credentials, sizeof(mSavedNetwork.credentials), &credentialsLen); SuccessOrExit(err); - err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, - sizeof(mSavedNetwork.ssid), &ssidLen); + err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), + &ssidLen); SuccessOrExit(err); mSavedNetwork.credentialsLen = credentialsLen; @@ -160,7 +160,7 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, memcpy(passwd, key, keyLen); wifi_interface_t wifi_interface; wifi_interface = wifi_mgmr_sta_enable(); - if(keyLen < 8 && keyLen != 5) + if (keyLen < 8 && keyLen != 5) { wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); } diff --git a/src/platform/bouffalolab/common/BLConfig.cpp b/src/platform/bouffalolab/common/BLConfig.cpp index 3b92f989431d42..ee6c3e28d8320e 100644 --- a/src/platform/bouffalolab/common/BLConfig.cpp +++ b/src/platform/bouffalolab/common/BLConfig.cpp @@ -111,20 +111,21 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si ef_port_env_lock(); - if (size) { - if (val) { + if (val) + { ret = ef_set_env_blob(key, val, size); } - else { + else + { ret = EF_ENV_ARG_ERR; } } - else + else { uint8_t value_null = 0; - ret = ef_set_env_blob(key, &value_null, size); + ret = ef_set_env_blob(key, &value_null, size); } ef_port_env_unlock(); @@ -251,20 +252,21 @@ CHIP_ERROR BLConfig::WriteKVS(const char * key, const void * value, size_t value ef_port_env_lock(); - - if (value_size) + if (value_size) { - if (value) { + if (value) + { ret = ef_set_env_blob(key, value, value_size); } - else { + else + { ret = EF_ENV_ARG_ERR; } } - else + else { uint32_t value_null = 0; - ret = ef_set_env_blob(key, &value_null, value_size); + ret = ef_set_env_blob(key, &value_null, value_size); } ef_port_env_unlock(); From 39a5f32bd4a6ef61f673286f3875bca06e0475bb Mon Sep 17 00:00:00 2001 From: shchen-Lab Date: Tue, 5 Sep 2023 18:14:30 +0800 Subject: [PATCH 04/11] BLCONFIG Bytes alignment --- src/platform/bouffalolab/common/BLConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/bouffalolab/common/BLConfig.cpp b/src/platform/bouffalolab/common/BLConfig.cpp index ee6c3e28d8320e..a9ab1e5cc322b1 100644 --- a/src/platform/bouffalolab/common/BLConfig.cpp +++ b/src/platform/bouffalolab/common/BLConfig.cpp @@ -124,7 +124,7 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si } else { - uint8_t value_null = 0; + uint32_t value_null = 0; ret = ef_set_env_blob(key, &value_null, size); } From 5f4050fd762c4c79ff4e104571e1e6a6a3d6f543 Mon Sep 17 00:00:00 2001 From: shchen-Lab Date: Tue, 5 Sep 2023 18:33:33 +0800 Subject: [PATCH 05/11] remove repo openthread misc --- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 2 +- third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index d6b5ac30fff066..6b9bedf5dec336 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -693,7 +693,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", ] diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 89d35bc98bb1a5..546ec161c38335 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -565,7 +565,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", From 8d2ded38af4a6faa8fd3ef5e9ef6e30cdf4ed8e8 Mon Sep 17 00:00:00 2001 From: shchen-Lab Date: Tue, 5 Sep 2023 18:48:47 +0800 Subject: [PATCH 06/11] code style --- src/platform/bouffalolab/common/BLConfig.cpp | 2 +- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 1 + third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/bouffalolab/common/BLConfig.cpp b/src/platform/bouffalolab/common/BLConfig.cpp index a9ab1e5cc322b1..ff03eb662a1bb7 100644 --- a/src/platform/bouffalolab/common/BLConfig.cpp +++ b/src/platform/bouffalolab/common/BLConfig.cpp @@ -125,7 +125,7 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si else { uint32_t value_null = 0; - ret = ef_set_env_blob(key, &value_null, size); + ret = ef_set_env_blob(key, &value_null, size); } ef_port_env_unlock(); diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 6b9bedf5dec336..8627dec0263114 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -693,6 +693,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 546ec161c38335..0aed83116893dd 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -565,6 +565,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", From 70f5d97d6e3ebe1fccf92d22688b56ca4fd618a7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 5 Sep 2023 10:49:22 +0000 Subject: [PATCH 07/11] Restyled by gn --- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 2 +- third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 8627dec0263114..0c07d55fcda50f 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -693,7 +693,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 0aed83116893dd..291f66d77d9710 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -565,7 +565,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - + #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", From e28b1b0c847c6dd08d1fa1d70c30684c95ed3420 Mon Sep 17 00:00:00 2001 From: wyhong Date: Wed, 6 Sep 2023 14:01:51 +0800 Subject: [PATCH 08/11] remove otPlatCAlloc/otPlatFree --- .../bouffalolab/BL702/ThreadStackManagerImpl.cpp | 10 ---------- .../bouffalolab/BL702L/ThreadStackManagerImpl.cpp | 10 ---------- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 2 +- third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 2 +- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp index c4981afe84a656..94932a9febb8c8 100644 --- a/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp @@ -103,16 +103,6 @@ extern "C" otInstance * otrGetInstance() return ThreadStackMgrImpl().OTInstance(); } -extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize) -{ - return calloc(aNum, aSize); -} - -extern "C" void otPlatFree(void * aPtr) -{ - free(aPtr); -} - extern "C" uint32_t otrEnterCrit(void) { if (xPortIsInsideInterrupt()) diff --git a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp index 1b1ebf197e006f..f2996526e84445 100644 --- a/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp +++ b/src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp @@ -106,16 +106,6 @@ extern "C" otInstance * otrGetInstance() return ThreadStackMgrImpl().OTInstance(); } -extern "C" void * otPlatCAlloc(size_t aNum, size_t aSize) -{ - return calloc(aNum, aSize); -} - -extern "C" void otPlatFree(void * aPtr) -{ - free(aPtr); -} - extern "C" ot_system_event_t otrGetNotifyEvent(void) { ot_system_event_t sevent = OT_SYSTEM_EVENT_NONE; diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 0c07d55fcda50f..620b13e884461c 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -694,7 +694,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", ] diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index 291f66d77d9710..bdb89cd034ac76 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -566,7 +566,7 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - #"${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", + "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", From 234d3f748c19c7465c18462a24b828487e28b744 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 6 Sep 2023 08:15:14 +0000 Subject: [PATCH 09/11] Restyled by gn --- third_party/bouffalolab/bl702/bl_iot_sdk.gni | 1 - third_party/bouffalolab/bl702l/bl_iot_sdk.gni | 1 - 2 files changed, 2 deletions(-) diff --git a/third_party/bouffalolab/bl702/bl_iot_sdk.gni b/third_party/bouffalolab/bl702/bl_iot_sdk.gni index 620b13e884461c..d6b5ac30fff066 100644 --- a/third_party/bouffalolab/bl702/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702/bl_iot_sdk.gni @@ -693,7 +693,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", diff --git a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni index bdb89cd034ac76..89d35bc98bb1a5 100644 --- a/third_party/bouffalolab/bl702l/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl702l/bl_iot_sdk.gni @@ -565,7 +565,6 @@ template("bl_iot_sdk") { "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_entropy.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_linkmetric.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_logging.c", - "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_misc.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_radio.c", "${bl_iot_sdk_root}/components/network/thread/openthread_port/ot_settings.c", From aea5246336e6312c1997036bf3fa0388436f3f3d Mon Sep 17 00:00:00 2001 From: shchen-Lab Date: Thu, 7 Sep 2023 10:07:07 +0800 Subject: [PATCH 10/11] add comment and check credentials length --- .../BL602/NetworkCommissioningDriver.cpp | 27 +++++++++++++++-- .../BL602/NetworkCommissioningDriver.h | 9 +++++- .../BL702/NetworkCommissioningDriver.cpp | 29 ++++++++++++++++++- .../BL702/NetworkCommissioningDriver.h | 9 +++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index d3483a4040f5bb..47b64d3db73755 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -160,14 +160,35 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, memcpy(passwd, key, keyLen); wifi_interface_t wifi_interface; wifi_interface = wifi_mgmr_sta_enable(); - if (keyLen < 8 && keyLen != 5) + // Valid Credentials length are: + // - 0 bytes: Unsecured (open) connection + // - 5 bytes: WEP-64 passphrase + // - 10 hexadecimal ASCII characters: WEP-64 40-bit hex raw PSK + // - 13 bytes: WEP-128 passphrase + // - 26 hexadecimal ASCII characters: WEP-128 104-bit hex raw PSK + // - 8..63 bytes: WPA/WPA2/WPA3 passphrase + // - 64 bytes: WPA/WPA2/WPA3 raw hex PSK + // Note 10 hex WEP64 and 13 bytes / 26 hex WEP128 passphrase are covered by 8~63 bytes WPA passphrase, so we don't check WEP64 + // hex and WEP128 passphrase. + if (keyLen ==BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || + (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && + keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) { - wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); + + if (keyLen==BLWiFiDriver::WiFiCredentialLength::kOpen) + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); + } + else + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); + } } else { - wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); + return CHIP_ERROR_INVALID_STRING_LENGTH; } + return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h index 7e0fd1b30727a1..83416a534988ac 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h @@ -86,6 +86,14 @@ class BLWiFiDriver final : public WiFiDriver char credentials[DeviceLayer::Internal::kMaxWiFiKeyLength]; uint8_t credentialsLen = 0; }; + enum WiFiCredentialLength + { + kOpen = 0, + kWEP64 = 5, + kMinWPAPSK = 8, + kMaxWPAPSK = 63, + kWPAPSKHex = 64, + }; // BaseDriver NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); } @@ -116,7 +124,6 @@ class BLWiFiDriver final : public WiFiDriver CHIP_ERROR SetLastDisconnectReason(const ChipDeviceEvent * event); int32_t GetLastDisconnectReason(); - static BLWiFiDriver & GetInstance() { static BLWiFiDriver instance; diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp index 6087fce9d94f66..2764220505ce87 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp @@ -132,7 +132,34 @@ Status BLWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCh CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen) { ChipLogProgress(NetworkProvisioning, "ConnectWiFiNetwork"); - wifiInterface_connect((char *) ssid, (char *) key); + // Valid Credentials length are: + // - 0 bytes: Unsecured (open) connection + // - 5 bytes: WEP-64 passphrase + // - 10 hexadecimal ASCII characters: WEP-64 40-bit hex raw PSK + // - 13 bytes: WEP-128 passphrase + // - 26 hexadecimal ASCII characters: WEP-128 104-bit hex raw PSK + // - 8..63 bytes: WPA/WPA2/WPA3 passphrase + // - 64 bytes: WPA/WPA2/WPA3 raw hex PSK + // Note 10 hex WEP64 and 13 bytes / 26 hex WEP128 passphrase are covered by 8~63 bytes WPA passphrase, so we don't check WEP64 + // hex and WEP128 passphrase. + if (keyLen ==BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || + (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && + keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) + { + + if (keyLen==BLWiFiDriver::WiFiCredentialLength::kOpen) + { + wifiInterface_connect((char *) ssid, NULL); + } + else + { + wifiInterface_connect((char *) ssid, (char *) key); + } + } + else + { + return CHIP_ERROR_INVALID_STRING_LENGTH; + } ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManager::kWiFiStationState_Connecting); return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h index 48bf7d098c869f..caa071ddd467b2 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h @@ -78,7 +78,14 @@ class BLWiFiDriver final : public WiFiDriver char credentials[DeviceLayer::Internal::kMaxWiFiKeyLength + 1]; uint8_t credentialsLen = 0; }; - + enum WiFiCredentialLength + { + kOpen = 0, + kWEP64 = 5, + kMinWPAPSK = 8, + kMaxWPAPSK = 63, + kWPAPSKHex = 64, + }; // BaseDriver NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); } CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) override; From 21a2b7bb22b38326c45ae2c59954a76d26675f4f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 7 Sep 2023 02:07:36 +0000 Subject: [PATCH 11/11] Restyled by clang-format --- .../bouffalolab/BL602/NetworkCommissioningDriver.cpp | 7 +++---- .../bouffalolab/BL702/NetworkCommissioningDriver.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index 47b64d3db73755..b051a44a44a0d5 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -170,12 +170,11 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, // - 64 bytes: WPA/WPA2/WPA3 raw hex PSK // Note 10 hex WEP64 and 13 bytes / 26 hex WEP128 passphrase are covered by 8~63 bytes WPA passphrase, so we don't check WEP64 // hex and WEP128 passphrase. - if (keyLen ==BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || - (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && - keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) + if (keyLen == BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || + (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) { - if (keyLen==BLWiFiDriver::WiFiCredentialLength::kOpen) + if (keyLen == BLWiFiDriver::WiFiCredentialLength::kOpen) { wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); } diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp index 2764220505ce87..252a1eba7f2475 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp @@ -142,12 +142,11 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, // - 64 bytes: WPA/WPA2/WPA3 raw hex PSK // Note 10 hex WEP64 and 13 bytes / 26 hex WEP128 passphrase are covered by 8~63 bytes WPA passphrase, so we don't check WEP64 // hex and WEP128 passphrase. - if (keyLen ==BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || - (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && - keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) + if (keyLen == BLWiFiDriver::WiFiCredentialLength::kOpen || keyLen == BLWiFiDriver::WiFiCredentialLength::kWEP64 || + (keyLen >= BLWiFiDriver::WiFiCredentialLength::kMinWPAPSK && keyLen <= BLWiFiDriver::WiFiCredentialLength::kMaxWPAPSK)) { - if (keyLen==BLWiFiDriver::WiFiCredentialLength::kOpen) + if (keyLen == BLWiFiDriver::WiFiCredentialLength::kOpen) { wifiInterface_connect((char *) ssid, NULL); }