Skip to content

Commit

Permalink
[Tizen] Implement functionality to get WiFi MAC (#18896)
Browse files Browse the repository at this point in the history
* Implement GetPrimaryWiFiMACAddress for Tizen platform

* VSCode C++ configuration for Tizen platform
  • Loading branch information
arkq authored and pull[bot] committed Oct 25, 2023
1 parent f92cd6c commit 2796099
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Tizen examples debug (GN)",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm",
"compilerPath": "/opt/tizen-sdk/tools/arm-linux-gnueabi-gcc-9.2/bin/arm-linux-gnueabi-gcc",
"browse": {
"path": ["${workspaceFolder}/out/debug/"],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<privileges>
<privilege>http://tizen.org/privilege/bluetooth</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
</privileges>
<feature name="http://tizen.org/feature/network.bluetooth.le.gatt.server">true</feature>
<feature name="http://tizen.org/feature/network.wifi">true</feature>
</manifest>
6 changes: 6 additions & 0 deletions src/platform/Tizen/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <platform/CHIPDeviceConfig.h>
#include <platform/ConfigurationManager.h>
#include <platform/Tizen/PosixConfig.h>
#include <platform/Tizen/WiFiManager.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

namespace chip {
Expand Down Expand Up @@ -91,7 +92,12 @@ CHIP_ERROR ConfigurationManagerImpl::StoreProductId(uint16_t productId)

CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
{
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
constexpr size_t kExpectedBufSize = ConfigurationManager::kPrimaryMACAddressLength;
return WiFiMgr().GetDeviceMACAddress(buf, kExpectedBufSize);
#else
return CHIP_ERROR_NOT_IMPLEMENTED;
#endif
}

bool ConfigurationManagerImpl::CanFactoryReset(void)
Expand Down
34 changes: 34 additions & 0 deletions src/platform/Tizen/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <platform/CHIPDeviceLayer.h>

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
#include <memory>
#include <wifi-manager.h>

#include "MainLoop.h"
#include "WiFiManager.h"

Expand Down Expand Up @@ -749,6 +752,37 @@ CHIP_ERROR WiFiManager::RemoveAllConfigs(void)
return err;
}

CHIP_ERROR WiFiManager::GetDeviceMACAddress(uint8_t * macAddress, size_t macAddressLen)
{
VerifyOrReturnError(macAddress != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(macAddressLen >= 6, CHIP_ERROR_INVALID_ARGUMENT);

char * macAddrStr = nullptr;
// Make sure that string allocated by wifi_manager_get_mac_address() will be freed
std::unique_ptr<char, decltype(&::free)> _{ macAddrStr, &::free };

int wifiErr = wifi_manager_get_mac_address(sInstance.mWiFiManagerHandle, &macAddrStr);
if (wifiErr == WIFI_MANAGER_ERROR_NOT_SUPPORTED)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
if (wifiErr != WIFI_MANAGER_ERROR_NONE)
{
ChipLogError(DeviceLayer, "FAIL: get MAC address [%s]", get_error_message(wifiErr));
return CHIP_ERROR_INCORRECT_STATE;
}

// Parse MAC address
if (sscanf(macAddrStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macAddress[0], &macAddress[1], &macAddress[2], &macAddress[3],
&macAddress[4], &macAddress[5]) != 6)
{
ChipLogError(DeviceLayer, "FAIL: parse MAC address");
return CHIP_ERROR_INCORRECT_STATE;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR WiFiManager::GetDeviceState(wifi_manager_device_state_e * deviceState)
{
*deviceState = sInstance.mDeviceState;
Expand Down
1 change: 1 addition & 0 deletions src/platform/Tizen/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WiFiManager
CHIP_ERROR Disconnect(const char * ssid);
CHIP_ERROR RemoveAllConfigs(void);

CHIP_ERROR GetDeviceMACAddress(uint8_t * macAddress, size_t macAddressLen);
CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState);
CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState);
CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState);
Expand Down

0 comments on commit 2796099

Please sign in to comment.