Skip to content

Commit 2796099

Browse files
arkqpull[bot]
authored andcommitted
[Tizen] Implement functionality to get WiFi MAC (#18896)
* Implement GetPrimaryWiFiMACAddress for Tizen platform * VSCode C++ configuration for Tizen platform
1 parent f92cd6c commit 2796099

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.vscode/c_cpp_properties.json

+11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
"path": ["${workspaceFolder}/out/debug/"],
8383
"limitSymbolsToIncludedHeaders": true
8484
}
85+
},
86+
{
87+
"name": "Tizen examples debug (GN)",
88+
"cStandard": "c11",
89+
"cppStandard": "gnu++14",
90+
"intelliSenseMode": "gcc-arm",
91+
"compilerPath": "/opt/tizen-sdk/tools/arm-linux-gnueabi-gcc-9.2/bin/arm-linux-gnueabi-gcc",
92+
"browse": {
93+
"path": ["${workspaceFolder}/out/debug/"],
94+
"limitSymbolsToIncludedHeaders": true
95+
}
8596
}
8697
],
8798
"version": 4

examples/lighting-app/tizen/tizen-manifest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<privileges>
88
<privilege>http://tizen.org/privilege/bluetooth</privilege>
99
<privilege>http://tizen.org/privilege/internet</privilege>
10+
<privilege>http://tizen.org/privilege/network.get</privilege>
1011
</privileges>
1112
<feature name="http://tizen.org/feature/network.bluetooth.le.gatt.server">true</feature>
13+
<feature name="http://tizen.org/feature/network.wifi">true</feature>
1214
</manifest>

src/platform/Tizen/ConfigurationManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <platform/CHIPDeviceConfig.h>
3232
#include <platform/ConfigurationManager.h>
3333
#include <platform/Tizen/PosixConfig.h>
34+
#include <platform/Tizen/WiFiManager.h>
3435
#include <platform/internal/GenericConfigurationManagerImpl.ipp>
3536

3637
namespace chip {
@@ -91,7 +92,12 @@ CHIP_ERROR ConfigurationManagerImpl::StoreProductId(uint16_t productId)
9192

9293
CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf)
9394
{
95+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
96+
constexpr size_t kExpectedBufSize = ConfigurationManager::kPrimaryMACAddressLength;
97+
return WiFiMgr().GetDeviceMACAddress(buf, kExpectedBufSize);
98+
#else
9499
return CHIP_ERROR_NOT_IMPLEMENTED;
100+
#endif
95101
}
96102

97103
bool ConfigurationManagerImpl::CanFactoryReset(void)

src/platform/Tizen/WiFiManager.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <platform/CHIPDeviceLayer.h>
1919

2020
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
21+
#include <memory>
22+
#include <wifi-manager.h>
23+
2124
#include "MainLoop.h"
2225
#include "WiFiManager.h"
2326

@@ -749,6 +752,37 @@ CHIP_ERROR WiFiManager::RemoveAllConfigs(void)
749752
return err;
750753
}
751754

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+
752786
CHIP_ERROR WiFiManager::GetDeviceState(wifi_manager_device_state_e * deviceState)
753787
{
754788
*deviceState = sInstance.mDeviceState;

src/platform/Tizen/WiFiManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class WiFiManager
4545
CHIP_ERROR Disconnect(const char * ssid);
4646
CHIP_ERROR RemoveAllConfigs(void);
4747

48+
CHIP_ERROR GetDeviceMACAddress(uint8_t * macAddress, size_t macAddressLen);
4849
CHIP_ERROR GetDeviceState(wifi_manager_device_state_e * deviceState);
4950
CHIP_ERROR SetDeviceState(wifi_manager_device_state_e deviceState);
5051
CHIP_ERROR GetModuleState(wifi_manager_module_state_e * moduleState);

0 commit comments

Comments
 (0)