From 0ee7743dbef6a5af16dbfa65f712143b1e08de81 Mon Sep 17 00:00:00 2001 From: Jong Wook Kim Date: Wed, 8 Aug 2018 18:57:26 -0700 Subject: [PATCH] Add Wifi HAL to get factory MAC address Add getFactoryMacAddress method to retrieve the factory MAC of Sta interface. Bug: 111634904 Test: Manual Verification Test: run vts with command "mma -j64 && adb sync data && adb shell data/nativetest64/VtsHalWifiV1_3TargetTest/VtsHalWifiV1_3TargetTest" Change-Id: I82b47366d3576201ef54a4e89a3f864c31fff42c --- wifi/1.3/IWifiStaIface.hal | 12 ++++ wifi/1.3/default/wifi_sta_iface.cpp | 14 +++++ wifi/1.3/default/wifi_sta_iface.h | 4 ++ wifi/1.3/vts/functional/Android.bp | 1 + .../functional/VtsHalWifiV1_3TargetTest.cpp | 2 + .../functional/wifi_sta_iface_hidl_test.cpp | 63 +++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 wifi/1.3/vts/functional/wifi_sta_iface_hidl_test.cpp diff --git a/wifi/1.3/IWifiStaIface.hal b/wifi/1.3/IWifiStaIface.hal index 0dc6128564..81c0c3869b 100644 --- a/wifi/1.3/IWifiStaIface.hal +++ b/wifi/1.3/IWifiStaIface.hal @@ -17,6 +17,7 @@ package android.hardware.wifi@1.3; import @1.0::WifiStatus; +import @1.0::MacAddress; import @1.2::IWifiStaIface; /** @@ -41,4 +42,15 @@ interface IWifiStaIface extends @1.2::IWifiStaIface { * @return stats Instance of |LinkLayerStats|. */ getLinkLayerStats_1_3() generates (WifiStatus status, StaLinkLayerStats stats); + + /** + * Gets the factory MAC address of the Sta Interface + * @return status WifiStatus of the operation + * Possible status codes: + * |WifiStatusCode.SUCCESS|, + * |WifiStatusCode.ERROR_WIFI_IFACE_INVALID|, + * |WifiStatusCode.ERROR_UNKNOWN| + * @return mac Factory MAC address of the Sta Interface + */ + getFactoryMacAddress() generates (WifiStatus status, MacAddress mac); }; diff --git a/wifi/1.3/default/wifi_sta_iface.cpp b/wifi/1.3/default/wifi_sta_iface.cpp index b0fa1aef6b..f7157a34af 100644 --- a/wifi/1.3/default/wifi_sta_iface.cpp +++ b/wifi/1.3/default/wifi_sta_iface.cpp @@ -255,6 +255,13 @@ Return WifiStaIface::setMacAddress(const hidl_array& mac, mac); } +Return WifiStaIface::getFactoryMacAddress( + getFactoryMacAddress_cb hidl_status_cb) { + return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, + &WifiStaIface::getFactoryMacAddressInternal, + hidl_status_cb); +} + std::pair WifiStaIface::getNameInternal() { return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; } @@ -633,6 +640,13 @@ WifiStatus WifiStaIface::setMacAddressInternal( return createWifiStatus(WifiStatusCode::SUCCESS); } +std::pair> +WifiStaIface::getFactoryMacAddressInternal() { + std::array mac = + iface_tool_.GetFactoryMacAddress(ifname_.c_str()); + return {createWifiStatus(WifiStatusCode::SUCCESS), mac}; +} + } // namespace implementation } // namespace V1_3 } // namespace wifi diff --git a/wifi/1.3/default/wifi_sta_iface.h b/wifi/1.3/default/wifi_sta_iface.h index bc3090f241..69cb82a79f 100644 --- a/wifi/1.3/default/wifi_sta_iface.h +++ b/wifi/1.3/default/wifi_sta_iface.h @@ -109,6 +109,8 @@ class WifiStaIface : public V1_3::IWifiStaIface { getDebugRxPacketFates_cb hidl_status_cb) override; Return setMacAddress(const hidl_array& mac, setMacAddress_cb hidl_status_cb) override; + Return getFactoryMacAddress( + getFactoryMacAddress_cb hidl_status_cb) override; private: // Corresponding worker functions for the HIDL methods. @@ -155,6 +157,8 @@ class WifiStaIface : public V1_3::IWifiStaIface { std::pair> getDebugRxPacketFatesInternal(); WifiStatus setMacAddressInternal(const std::array& mac); + std::pair> + getFactoryMacAddressInternal(); std::string ifname_; std::weak_ptr legacy_hal_; diff --git a/wifi/1.3/vts/functional/Android.bp b/wifi/1.3/vts/functional/Android.bp index f5a0999f45..53c8f08516 100644 --- a/wifi/1.3/vts/functional/Android.bp +++ b/wifi/1.3/vts/functional/Android.bp @@ -20,6 +20,7 @@ cc_test { srcs: [ "VtsHalWifiV1_3TargetTest.cpp", "wifi_chip_hidl_test.cpp", + "wifi_sta_iface_hidl_test.cpp", ], static_libs: [ "VtsHalWifiV1_0TargetTestUtil", diff --git a/wifi/1.3/vts/functional/VtsHalWifiV1_3TargetTest.cpp b/wifi/1.3/vts/functional/VtsHalWifiV1_3TargetTest.cpp index b410a4813f..faf426e999 100644 --- a/wifi/1.3/vts/functional/VtsHalWifiV1_3TargetTest.cpp +++ b/wifi/1.3/vts/functional/VtsHalWifiV1_3TargetTest.cpp @@ -19,6 +19,8 @@ #include "wifi_hidl_test_utils.h" +using ::android::hardware::wifi::V1_3::IWifi; + // Test environment for Wifi HIDL HAL. class WifiHidlEnvironment_1_3 : public WifiHidlEnvironment { public: diff --git a/wifi/1.3/vts/functional/wifi_sta_iface_hidl_test.cpp b/wifi/1.3/vts/functional/wifi_sta_iface_hidl_test.cpp new file mode 100644 index 0000000000..e195adeaa2 --- /dev/null +++ b/wifi/1.3/vts/functional/wifi_sta_iface_hidl_test.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Staache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#include + +#include + +#include "wifi_hidl_call_util.h" +#include "wifi_hidl_test_utils.h" + +using ::android::sp; +using ::android::hardware::wifi::V1_0::WifiStatusCode; +using ::android::hardware::wifi::V1_3::IWifiStaIface; + +/** + * Fixture to use for all STA Iface HIDL interface tests. + */ +class WifiStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { + public: + virtual void SetUp() override { + wifi_sta_iface_ = IWifiStaIface::castFrom(getWifiStaIface()); + ASSERT_NE(nullptr, wifi_sta_iface_.get()); + } + + virtual void TearDown() override { stopWifi(); } + + protected: + sp wifi_sta_iface_; +}; + +/* + * GetFactoryMacAddress: + * Ensures that calls to get factory MAC address will retrieve a non-zero MAC + * and return a success status code. + */ +TEST_F(WifiStaIfaceHidlTest, GetFactoryMacAddress) { + const auto& status_and_mac = + HIDL_INVOKE(wifi_sta_iface_, getFactoryMacAddress); + EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_mac.first.code); + const int num_elements = sizeof(status_and_mac.second) / sizeof(uint8_t); + EXPECT_EQ(6, num_elements); + for (int i = 0; i < num_elements; i++) { + EXPECT_NE(0, status_and_mac.second[i]); + } +}