Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BouffaloLab]update sdk to support open network #29070

Merged
merged 13 commits into from
Sep 7, 2023
34 changes: 30 additions & 4 deletions src/platform/bouffalolab/BL602/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ 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,
sizeof(mSavedNetwork.ssid), &ssidLen);
err = PersistedStorage::KeyValueStoreMgr().Get(BLConfig::kConfigKey_WiFiSSID, mSavedNetwork.ssid, sizeof(mSavedNetwork.ssid),
&ssidLen);
SuccessOrExit(err);

mSavedNetwork.credentialsLen = credentialsLen;
Expand Down Expand Up @@ -160,7 +160,33 @@ 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);
// 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)
{
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
{
return CHIP_ERROR_INVALID_STRING_LENGTH;
}

return CHIP_NO_ERROR;
}
Expand Down
9 changes: 8 additions & 1 deletion src/platform/bouffalolab/BL602/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -116,7 +124,6 @@ class BLWiFiDriver final : public WiFiDriver

CHIP_ERROR SetLastDisconnectReason(const ChipDeviceEvent * event);
int32_t GetLastDisconnectReason();

static BLWiFiDriver & GetInstance()
{
static BLWiFiDriver instance;
Expand Down
28 changes: 27 additions & 1 deletion src/platform/bouffalolab/BL702/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,33 @@ 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;
}
Expand Down
9 changes: 8 additions & 1 deletion src/platform/bouffalolab/BL702/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 0 additions & 10 deletions src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 28 additions & 5 deletions src/platform/bouffalolab/common/BLConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si

ef_port_env_lock();

if (size && val)
if (size)
{
ret = ef_set_env_blob(key, val, size);
if (val)
{
ret = ef_set_env_blob(key, val, size);
}
else
{
ret = EF_ENV_ARG_ERR;
}
}
else
{
uint32_t value_null = 0;
ret = ef_set_env_blob(key, &value_null, size);
}

ef_port_env_unlock();
Expand Down Expand Up @@ -240,11 +252,22 @@ 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)
Expand Down
2 changes: 1 addition & 1 deletion third_party/bouffalolab/repo
Submodule repo updated 2 files
+1 −1 components
+1 −1 customer_app