|
18 | 18 | #include <platform/CHIPDeviceLayer.h>
|
19 | 19 |
|
20 | 20 | #if CHIP_DEVICE_CONFIG_ENABLE_WIFI
|
| 21 | +#include <memory> |
| 22 | +#include <wifi-manager.h> |
| 23 | + |
21 | 24 | #include "MainLoop.h"
|
22 | 25 | #include "WiFiManager.h"
|
23 | 26 |
|
@@ -749,6 +752,37 @@ CHIP_ERROR WiFiManager::RemoveAllConfigs(void)
|
749 | 752 | return err;
|
750 | 753 | }
|
751 | 754 |
|
| 755 | +CHIP_ERROR WiFiManager::GetDeviceMACAddress(uint8_t * macAddress, size_t macAddressLen) |
| 756 | +{ |
| 757 | + VerifyOrReturnError(macAddress != nullptr, CHIP_ERROR_INVALID_ARGUMENT); |
| 758 | + VerifyOrReturnError(macAddressLen >= 6, CHIP_ERROR_INVALID_ARGUMENT); |
| 759 | + |
| 760 | + char * macAddrStr = nullptr; |
| 761 | + // Make sure that string allocated by wifi_manager_get_mac_address() will be freed |
| 762 | + std::unique_ptr<char, decltype(&::free)> _{ macAddrStr, &::free }; |
| 763 | + |
| 764 | + int wifiErr = wifi_manager_get_mac_address(sInstance.mWiFiManagerHandle, &macAddrStr); |
| 765 | + if (wifiErr == WIFI_MANAGER_ERROR_NOT_SUPPORTED) |
| 766 | + { |
| 767 | + return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; |
| 768 | + } |
| 769 | + if (wifiErr != WIFI_MANAGER_ERROR_NONE) |
| 770 | + { |
| 771 | + ChipLogError(DeviceLayer, "FAIL: get MAC address [%s]", get_error_message(wifiErr)); |
| 772 | + return CHIP_ERROR_INCORRECT_STATE; |
| 773 | + } |
| 774 | + |
| 775 | + // Parse MAC address |
| 776 | + if (sscanf(macAddrStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macAddress[0], &macAddress[1], &macAddress[2], &macAddress[3], |
| 777 | + &macAddress[4], &macAddress[5]) != 6) |
| 778 | + { |
| 779 | + ChipLogError(DeviceLayer, "FAIL: parse MAC address"); |
| 780 | + return CHIP_ERROR_INCORRECT_STATE; |
| 781 | + } |
| 782 | + |
| 783 | + return CHIP_NO_ERROR; |
| 784 | +} |
| 785 | + |
752 | 786 | CHIP_ERROR WiFiManager::GetDeviceState(wifi_manager_device_state_e * deviceState)
|
753 | 787 | {
|
754 | 788 | *deviceState = sInstance.mDeviceState;
|
|
0 commit comments