diff --git a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp index d9dd83c923cd57..ddd7682625ef94 100644 --- a/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp @@ -50,7 +50,10 @@ CHIP_ERROR BLWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid), &ssidLen); SuccessOrExit(err); - + if(credentialsLen==1) + { + credentialsLen=0; + } mSavedNetwork.credentialsLen = credentialsLen; mSavedNetwork.ssidLen = ssidLen; @@ -79,8 +82,17 @@ CHIP_ERROR BLWiFiDriver::CommitConfiguration() ChipLogProgress(NetworkProvisioning, "BLWiFiDriver::CommitConfiguration"); ReturnErrorOnFailure( PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiSSID, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, + if(mStagingNetwork.credentialsLen==0) + { + mStagingNetwork.credentialsLen=1; + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, + mStagingNetwork.credentialsLen)); + } + else + { + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, mStagingNetwork.credentialsLen)); + } mSavedNetwork = mStagingNetwork; return CHIP_NO_ERROR; } @@ -106,9 +118,11 @@ Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mut VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); + memset(mStagingNetwork.credentials, 0, sizeof(mStagingNetwork.credentials)); memcpy(mStagingNetwork.credentials, credentials.data(), credentials.size()); mStagingNetwork.credentialsLen = static_cast(credentials.size()); + memset(mStagingNetwork.ssid, 0, sizeof(mStagingNetwork.ssid)); memcpy(mStagingNetwork.ssid, ssid.data(), ssid.size()); mStagingNetwork.ssidLen = static_cast(ssid.size()); @@ -157,10 +171,20 @@ CHIP_ERROR BLWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, } memcpy(wifi_ssid, ssid, ssidLen); - memcpy(passwd, key, keyLen); + if(keyLen!=0) + { + 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!=0) + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, passwd, NULL, NULL, 0, 0); + } + else + { + wifi_mgmr_sta_connect(&wifi_interface, wifi_ssid, NULL, NULL, NULL, 0, 0); + } return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp index 6087fce9d94f66..11feda10a0ebc9 100644 --- a/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp +++ b/src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp @@ -39,7 +39,10 @@ CHIP_ERROR BLWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeC err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, mSavedNetwork.credentials, sizeof(mSavedNetwork.credentials), &credentialsLen); SuccessOrExit(err); - + if(credentialsLen==1) + { + credentialsLen=0; + } mSavedNetwork.credentialsLen = credentialsLen; mSavedNetwork.ssidLen = ssidLen; mSavedNetwork.credentials[mSavedNetwork.credentialsLen] = '\0'; @@ -73,8 +76,18 @@ CHIP_ERROR BLWiFiDriver::CommitConfiguration() ChipLogProgress(NetworkProvisioning, "BLWiFiDriver::CommitConfiguration"); ReturnErrorOnFailure( PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiSSID, mStagingNetwork.ssid, mStagingNetwork.ssidLen)); - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, + if(mStagingNetwork.credentialsLen==0) + { + mStagingNetwork.credentialsLen=1; + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, + mStagingNetwork.credentialsLen)); + } + else + { + ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(BLConfig::kConfigKey_WiFiPassword, mStagingNetwork.credentials, mStagingNetwork.credentialsLen)); + } + mSavedNetwork = mStagingNetwork; return CHIP_NO_ERROR; } @@ -100,9 +113,11 @@ Status BLWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mut VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); + memset(mStagingNetwork.credentials, 0, sizeof(mStagingNetwork.credentials)); memcpy(mStagingNetwork.credentials, credentials.data(), credentials.size()); mStagingNetwork.credentialsLen = static_cast(credentials.size()); + memset(mStagingNetwork.ssid, 0, sizeof(mStagingNetwork.ssid)); memcpy(mStagingNetwork.ssid, ssid.data(), ssid.size()); mStagingNetwork.ssidLen = static_cast(ssid.size()); @@ -132,7 +147,14 @@ 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); + if(keyLen==0) + { + wifiInterface_connect((char *) ssid, NULL); + } + else + { + wifiInterface_connect((char *) ssid, (char *) key); + } ConnectivityMgrImpl().ChangeWiFiStationState(ConnectivityManager::kWiFiStationState_Connecting); return CHIP_NO_ERROR; } diff --git a/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp b/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp index a74cf5dd1cf686..92b3839759787d 100644 --- a/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp +++ b/src/platform/bouffalolab/common/ConnectivityManagerImpl.cpp @@ -172,7 +172,10 @@ CHIP_ERROR ConnectivityManagerImpl::ConnectProvisionedWiFiNetwork(void) ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, (void *) ssid, 64, &ssidLen, 0)); ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiPassword, (void *) psk, 64, &pskLen, 0)); - + if(pskLen==1) + { + pskLen=0; + } NetworkCommissioning::BLWiFiDriver::GetInstance().ConnectWiFiNetwork(ssid, ssidLen, psk, pskLen); return CHIP_NO_ERROR;