|
31 | 31 | #include <lib/support/logging/CHIPLogging.h>
|
32 | 32 | #include <platform/GLibTypeDeleter.h>
|
33 | 33 | #include <platform/PlatformManager.h>
|
34 |
| -#include <platform/Tizen/NetworkCommissioningDriver.h> |
| 34 | + |
| 35 | +#include "ErrorUtils.h" |
| 36 | +#include "NetworkCommissioningDriver.h" |
35 | 37 |
|
36 | 38 | using namespace ::chip::DeviceLayer::NetworkCommissioning;
|
37 | 39 |
|
@@ -1095,34 +1097,23 @@ CHIP_ERROR WiFiManager::GetConnectionState(wifi_manager_connection_state_e * con
|
1095 | 1097 | return err;
|
1096 | 1098 | }
|
1097 | 1099 |
|
1098 |
| -CHIP_ERROR WiFiManager::GetBssId(uint8_t * bssId) |
| 1100 | +CHIP_ERROR WiFiManager::GetBssId(MutableByteSpan & value) |
1099 | 1101 | {
|
1100 |
| - VerifyOrReturnError(bssId != nullptr, CHIP_ERROR_INVALID_ARGUMENT); |
1101 |
| - |
1102 |
| - char * bssIdStr = nullptr; |
1103 |
| - std::unique_ptr<char, decltype(&::free)> _{ bssIdStr, &::free }; |
| 1102 | + VerifyOrReturnError(value.size() >= kWiFiBSSIDLength, CHIP_ERROR_BUFFER_TOO_SMALL); |
1104 | 1103 |
|
1105 | 1104 | wifi_manager_ap_h connectedAp = _WiFiGetConnectedAP();
|
1106 |
| - if (connectedAp == nullptr) |
1107 |
| - { |
1108 |
| - return CHIP_ERROR_INCORRECT_STATE; |
1109 |
| - } |
| 1105 | + VerifyOrReturnError(connectedAp != nullptr, CHIP_ERROR_INCORRECT_STATE); |
1110 | 1106 |
|
1111 |
| - int wifiErr = wifi_manager_ap_get_bssid(connectedAp, &bssIdStr); |
1112 |
| - if (wifiErr != WIFI_MANAGER_ERROR_NONE) |
1113 |
| - { |
1114 |
| - ChipLogError(DeviceLayer, "FAIL: get bssid [%s]", get_error_message(wifiErr)); |
1115 |
| - return CHIP_ERROR_READ_FAILED; |
1116 |
| - } |
| 1107 | + GAutoPtr<char> bssIdStr; |
| 1108 | + int wifiErr = wifi_manager_ap_get_bssid(connectedAp, &bssIdStr.GetReceiver()); |
| 1109 | + VerifyOrReturnError(wifiErr == WIFI_MANAGER_ERROR_NONE, TizenToChipError(wifiErr), |
| 1110 | + ChipLogError(DeviceLayer, "FAIL: Get AP BSSID: %s", get_error_message(wifiErr))); |
1117 | 1111 |
|
1118 |
| - if (sscanf(bssIdStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mWiFiBSSID[0], &mWiFiBSSID[1], &mWiFiBSSID[2], &mWiFiBSSID[3], |
1119 |
| - &mWiFiBSSID[4], &mWiFiBSSID[5]) != 6) |
1120 |
| - { |
1121 |
| - ChipLogError(DeviceLayer, "FAIL: parse bssid"); |
1122 |
| - return CHIP_ERROR_READ_FAILED; |
1123 |
| - } |
| 1112 | + uint8_t * data = value.data(); |
| 1113 | + int rv = sscanf(bssIdStr.get(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]); |
| 1114 | + VerifyOrReturnError(rv == kWiFiBSSIDLength, CHIP_ERROR_READ_FAILED, ChipLogError(DeviceLayer, "FAIL: Parse AP BSSID")); |
1124 | 1115 |
|
1125 |
| - bssId = mWiFiBSSID; |
| 1116 | + value.reduce_size(kWiFiBSSIDLength); |
1126 | 1117 | return CHIP_NO_ERROR;
|
1127 | 1118 | }
|
1128 | 1119 |
|
|
0 commit comments