summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorJong Wook Kim2018-03-16 18:21:49 -0500
committerJong Wook Kim2018-03-27 17:37:30 -0500
commitb9f0ff9fa6c4a8e5557c339ef0f06b3d597deb98 (patch)
treefca5c16156b5dc81220d2fd3cbd648ed550c2bb0 /wifi
parentc7d15e9f51288fef54a1f669db4b45085d7d5879 (diff)
downloadplatform-hardware-interfaces-b9f0ff9fa6c4a8e5557c339ef0f06b3d597deb98.tar.gz
platform-hardware-interfaces-b9f0ff9fa6c4a8e5557c339ef0f06b3d597deb98.tar.xz
platform-hardware-interfaces-b9f0ff9fa6c4a8e5557c339ef0f06b3d597deb98.zip
SetMacAddress in Vendor HAL
Add a Wifi HAL interface to set MAC address. The default implementation is to bring the interface down, change the MAC address, and then bring the interface back up. Bug: 74347653 Test: vts, manual testing Change-Id: Ic740d94ec2fcb37e6743d0f3e967f3f4b6afb57d
Diffstat (limited to 'wifi')
-rw-r--r--wifi/1.2/IWifiStaIface.hal14
-rw-r--r--wifi/1.2/default/wifi_sta_iface.cpp27
-rw-r--r--wifi/1.2/default/wifi_sta_iface.h6
-rw-r--r--wifi/1.2/vts/functional/Android.bp1
-rw-r--r--wifi/1.2/vts/functional/wifi_sta_iface_hidl_test.cpp56
5 files changed, 104 insertions, 0 deletions
diff --git a/wifi/1.2/IWifiStaIface.hal b/wifi/1.2/IWifiStaIface.hal
index be4e5376..3a7f7772 100644
--- a/wifi/1.2/IWifiStaIface.hal
+++ b/wifi/1.2/IWifiStaIface.hal
@@ -17,6 +17,7 @@
17package android.hardware.wifi@1.2; 17package android.hardware.wifi@1.2;
18 18
19import @1.0::WifiStatus; 19import @1.0::WifiStatus;
20import @1.0::MacAddress;
20import @1.0::IWifiStaIface; 21import @1.0::IWifiStaIface;
21 22
22/** 23/**
@@ -51,4 +52,17 @@ interface IWifiStaIface extends @1.0::IWifiStaIface {
51 * @see installApfPacketFilter() 52 * @see installApfPacketFilter()
52 */ 53 */
53 readApfPacketFilterData() generates (WifiStatus status, vec<uint8_t> data); 54 readApfPacketFilterData() generates (WifiStatus status, vec<uint8_t> data);
55
56 /**
57 * Changes the MAC address of the Sta Interface to the given
58 * MAC address.
59 *
60 * @param mac MAC address to change into.
61 * @return status WifiStatus of the operation.
62 * Possible status codes:
63 * |WifiStatusCode.SUCCESS|,
64 * |WifiStatusCode.ERROR_WIFI_IFACE_INVALID|,
65 * |WifiStatusCode.ERROR_UNKNOWN|
66 */
67 setMacAddress(MacAddress mac) generates (WifiStatus status);
54}; 68};
diff --git a/wifi/1.2/default/wifi_sta_iface.cpp b/wifi/1.2/default/wifi_sta_iface.cpp
index ab99daa2..daa56101 100644
--- a/wifi/1.2/default/wifi_sta_iface.cpp
+++ b/wifi/1.2/default/wifi_sta_iface.cpp
@@ -241,6 +241,13 @@ Return<void> WifiStaIface::getDebugRxPacketFates(
241 hidl_status_cb); 241 hidl_status_cb);
242} 242}
243 243
244Return<void> WifiStaIface::setMacAddress(const hidl_array<uint8_t, 6>& mac,
245 setMacAddress_cb hidl_status_cb) {
246 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
247 &WifiStaIface::setMacAddressInternal, hidl_status_cb,
248 mac);
249}
250
244std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() { 251std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() {
245 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; 252 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
246} 253}
@@ -594,6 +601,26 @@ WifiStaIface::getDebugRxPacketFatesInternal() {
594 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; 601 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates};
595} 602}
596 603
604WifiStatus WifiStaIface::setMacAddressInternal(
605 const std::array<uint8_t, 6>& mac) {
606 if (!iface_tool_.SetWifiUpState(false)) {
607 LOG(ERROR) << "SetWifiUpState(false) failed.";
608 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
609 }
610
611 if (!iface_tool_.SetMacAddress(ifname_.c_str(), mac)) {
612 LOG(ERROR) << "SetMacAddress failed.";
613 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
614 }
615
616 if (!iface_tool_.SetWifiUpState(true)) {
617 LOG(ERROR) << "SetWifiUpState(true) failed.";
618 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
619 }
620 LOG(DEBUG) << "Successfully SetMacAddress.";
621 return createWifiStatus(WifiStatusCode::SUCCESS);
622}
623
597} // namespace implementation 624} // namespace implementation
598} // namespace V1_2 625} // namespace V1_2
599} // namespace wifi 626} // namespace wifi
diff --git a/wifi/1.2/default/wifi_sta_iface.h b/wifi/1.2/default/wifi_sta_iface.h
index a2128882..71cd17d3 100644
--- a/wifi/1.2/default/wifi_sta_iface.h
+++ b/wifi/1.2/default/wifi_sta_iface.h
@@ -21,6 +21,8 @@
21#include <android/hardware/wifi/1.0/IWifiStaIfaceEventCallback.h> 21#include <android/hardware/wifi/1.0/IWifiStaIfaceEventCallback.h>
22#include <android/hardware/wifi/1.2/IWifiStaIface.h> 22#include <android/hardware/wifi/1.2/IWifiStaIface.h>
23 23
24#include <wifi_system/interface_tool.h>
25
24#include "hidl_callback_util.h" 26#include "hidl_callback_util.h"
25#include "wifi_legacy_hal.h" 27#include "wifi_legacy_hal.h"
26 28
@@ -103,6 +105,8 @@ class WifiStaIface : public V1_2::IWifiStaIface {
103 getDebugTxPacketFates_cb hidl_status_cb) override; 105 getDebugTxPacketFates_cb hidl_status_cb) override;
104 Return<void> getDebugRxPacketFates( 106 Return<void> getDebugRxPacketFates(
105 getDebugRxPacketFates_cb hidl_status_cb) override; 107 getDebugRxPacketFates_cb hidl_status_cb) override;
108 Return<void> setMacAddress(const hidl_array<uint8_t, 6>& mac,
109 setMacAddress_cb hidl_status_cb) override;
106 110
107 private: 111 private:
108 // Corresponding worker functions for the HIDL methods. 112 // Corresponding worker functions for the HIDL methods.
@@ -146,12 +150,14 @@ class WifiStaIface : public V1_2::IWifiStaIface {
146 getDebugTxPacketFatesInternal(); 150 getDebugTxPacketFatesInternal();
147 std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> 151 std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>>
148 getDebugRxPacketFatesInternal(); 152 getDebugRxPacketFatesInternal();
153 WifiStatus setMacAddressInternal(const std::array<uint8_t, 6>& mac);
149 154
150 std::string ifname_; 155 std::string ifname_;
151 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; 156 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
152 bool is_valid_; 157 bool is_valid_;
153 hidl_callback_util::HidlCallbackHandler<IWifiStaIfaceEventCallback> 158 hidl_callback_util::HidlCallbackHandler<IWifiStaIfaceEventCallback>
154 event_cb_handler_; 159 event_cb_handler_;
160 wifi_system::InterfaceTool iface_tool_;
155 161
156 DISALLOW_COPY_AND_ASSIGN(WifiStaIface); 162 DISALLOW_COPY_AND_ASSIGN(WifiStaIface);
157}; 163};
diff --git a/wifi/1.2/vts/functional/Android.bp b/wifi/1.2/vts/functional/Android.bp
index d85d42ec..918e4a45 100644
--- a/wifi/1.2/vts/functional/Android.bp
+++ b/wifi/1.2/vts/functional/Android.bp
@@ -20,6 +20,7 @@ cc_test {
20 srcs: [ 20 srcs: [
21 "VtsHalWifiV1_2TargetTest.cpp", 21 "VtsHalWifiV1_2TargetTest.cpp",
22 "wifi_chip_hidl_test.cpp", 22 "wifi_chip_hidl_test.cpp",
23 "wifi_sta_iface_hidl_test.cpp",
23 ], 24 ],
24 static_libs: [ 25 static_libs: [
25 "VtsHalWifiV1_0TargetTestUtil", 26 "VtsHalWifiV1_0TargetTestUtil",
diff --git a/wifi/1.2/vts/functional/wifi_sta_iface_hidl_test.cpp b/wifi/1.2/vts/functional/wifi_sta_iface_hidl_test.cpp
new file mode 100644
index 00000000..fd4a671c
--- /dev/null
+++ b/wifi/1.2/vts/functional/wifi_sta_iface_hidl_test.cpp
@@ -0,0 +1,56 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Staache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android-base/logging.h>
18
19#include <android/hardware/wifi/1.2/IWifiStaIface.h>
20
21#include <VtsHalHidlTargetTestBase.h>
22
23#include "wifi_hidl_call_util.h"
24#include "wifi_hidl_test_utils.h"
25
26using ::android::sp;
27using ::android::hardware::wifi::V1_2::IWifiStaIface;
28using ::android::hardware::wifi::V1_0::WifiStatusCode;
29
30/**
31 * Fixture to use for all STA Iface HIDL interface tests.
32 */
33class WifiStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
34 public:
35 virtual void SetUp() override {
36 wifi_sta_iface_ = IWifiStaIface::castFrom(getWifiStaIface());
37 ASSERT_NE(nullptr, wifi_sta_iface_.get());
38 }
39
40 virtual void TearDown() override { stopWifi(); }
41
42 protected:
43 sp<IWifiStaIface> wifi_sta_iface_;
44};
45
46/*
47 * SetMacAddress:
48 * Ensures that calls to set MAC address will return a success status
49 * code.
50 */
51TEST_F(WifiStaIfaceHidlTest, SetMacAddress) {
52 const android::hardware::hidl_array<uint8_t, 6> kMac{
53 std::array<uint8_t, 6>{{0x12, 0x22, 0x33, 0x52, 0x10, 0x41}}};
54 EXPECT_EQ(WifiStatusCode::SUCCESS,
55 HIDL_INVOKE(wifi_sta_iface_, setMacAddress, kMac).code);
56}