Skip to content

Commit

Permalink
[Tizen] Fix ConnectivityManager::GetWiFiBssId implementation (project…
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq authored Sep 20, 2024
1 parent cc29cab commit 7b8467b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
12 changes: 1 addition & 11 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,7 @@ bool ConnectivityManagerImpl::IsWiFiManagementStarted()

CHIP_ERROR ConnectivityManagerImpl::GetWiFiBssId(MutableByteSpan & value)
{
constexpr size_t bssIdSize = 6;
VerifyOrReturnError(value.size() >= bssIdSize, CHIP_ERROR_BUFFER_TOO_SMALL);

uint8_t * bssId = nullptr;
CHIP_ERROR err = Internal::WiFiMgr().GetBssId(bssId);
ReturnErrorOnFailure(err);

memcpy(value.data(), bssId, bssIdSize);
value.reduce_size(bssIdSize);

return CHIP_NO_ERROR;
return Internal::WiFiMgr().GetBssId(value);
}

CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(SecurityTypeEnum & securityType)
Expand Down
37 changes: 14 additions & 23 deletions src/platform/Tizen/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include <lib/support/logging/CHIPLogging.h>
#include <platform/GLibTypeDeleter.h>
#include <platform/PlatformManager.h>
#include <platform/Tizen/NetworkCommissioningDriver.h>

#include "ErrorUtils.h"
#include "NetworkCommissioningDriver.h"

using namespace ::chip::DeviceLayer::NetworkCommissioning;

Expand Down Expand Up @@ -1095,34 +1097,23 @@ CHIP_ERROR WiFiManager::GetConnectionState(wifi_manager_connection_state_e * con
return err;
}

CHIP_ERROR WiFiManager::GetBssId(uint8_t * bssId)
CHIP_ERROR WiFiManager::GetBssId(MutableByteSpan & value)
{
VerifyOrReturnError(bssId != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

char * bssIdStr = nullptr;
std::unique_ptr<char, decltype(&::free)> _{ bssIdStr, &::free };
VerifyOrReturnError(value.size() >= kWiFiBSSIDLength, CHIP_ERROR_BUFFER_TOO_SMALL);

wifi_manager_ap_h connectedAp = _WiFiGetConnectedAP();
if (connectedAp == nullptr)
{
return CHIP_ERROR_INCORRECT_STATE;
}
VerifyOrReturnError(connectedAp != nullptr, CHIP_ERROR_INCORRECT_STATE);

int wifiErr = wifi_manager_ap_get_bssid(connectedAp, &bssIdStr);
if (wifiErr != WIFI_MANAGER_ERROR_NONE)
{
ChipLogError(DeviceLayer, "FAIL: get bssid [%s]", get_error_message(wifiErr));
return CHIP_ERROR_READ_FAILED;
}
GAutoPtr<char> bssIdStr;
int wifiErr = wifi_manager_ap_get_bssid(connectedAp, &bssIdStr.GetReceiver());
VerifyOrReturnError(wifiErr == WIFI_MANAGER_ERROR_NONE, TizenToChipError(wifiErr),
ChipLogError(DeviceLayer, "FAIL: Get AP BSSID: %s", get_error_message(wifiErr)));

if (sscanf(bssIdStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mWiFiBSSID[0], &mWiFiBSSID[1], &mWiFiBSSID[2], &mWiFiBSSID[3],
&mWiFiBSSID[4], &mWiFiBSSID[5]) != 6)
{
ChipLogError(DeviceLayer, "FAIL: parse bssid");
return CHIP_ERROR_READ_FAILED;
}
uint8_t * data = value.data();
int rv = sscanf(bssIdStr.get(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
VerifyOrReturnError(rv == kWiFiBSSIDLength, CHIP_ERROR_READ_FAILED, ChipLogError(DeviceLayer, "FAIL: Parse AP BSSID"));

bssId = mWiFiBSSID;
value.reduce_size(kWiFiBSSIDLength);
return CHIP_NO_ERROR;
}

Expand Down
3 changes: 1 addition & 2 deletions src/platform/Tizen/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WiFiManager
CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState);
CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState);
CHIP_ERROR GetConnectionState(wifi_manager_connection_state_e * connectionState);
CHIP_ERROR GetBssId(uint8_t * bssId);
CHIP_ERROR GetBssId(MutableByteSpan & value);
CHIP_ERROR GetSecurityType(wifi_manager_security_type_e * securityType);
CHIP_ERROR GetConfiguredNetwork(NetworkCommissioning::Network & network);
bool IsWiFiStationConnected();
Expand Down Expand Up @@ -105,7 +105,6 @@ class WiFiManager
wifi_manager_module_state_e mModuleState;
wifi_manager_connection_state_e mConnectionState;

uint8_t mWiFiBSSID[kWiFiBSSIDLength];
char mWiFiSSID[kMaxWiFiSSIDLength + 1];
char mWiFiKey[kMaxWiFiKeyLength + 1];
char mInterestedSSID[kMaxWiFiSSIDLength + 1];
Expand Down

0 comments on commit 7b8467b

Please sign in to comment.