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 <numeric> 18 #include <vector> 19 20 #include <android-base/logging.h> 21 22 #include <android/hardware/wifi/1.2/IWifiStaIface.h> 23 24 #include <VtsHalHidlTargetTestBase.h> 25 26 #include "wifi_hidl_call_util.h" 27 #include "wifi_hidl_test_utils.h" 28 29 using ::android::sp; 30 using ::android::hardware::wifi::V1_0::CommandId; 31 using ::android::hardware::wifi::V1_0::WifiStatusCode; 32 using ::android::hardware::wifi::V1_2::IWifiStaIface; 33 34 /** 35 * Fixture to use for all STA Iface HIDL interface tests. 36 */ 37 class WifiStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { 38 public: 39 virtual void SetUp() override { 40 wifi_sta_iface_ = IWifiStaIface::castFrom(getWifiStaIface()); 41 ASSERT_NE(nullptr, wifi_sta_iface_.get()); 42 } 43 44 virtual void TearDown() override { stopWifi(); } 45 46 protected: 47 bool isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask) { 48 const auto& status_and_caps = 49 HIDL_INVOKE(wifi_sta_iface_, getCapabilities); 50 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code); 51 return (status_and_caps.second & cap_mask) != 0; 52 } 53 54 sp<IWifiStaIface> wifi_sta_iface_; 55 }; 56 57 /* 58 * SetMacAddress: 59 * Ensures that calls to set MAC address will return a success status 60 * code. 61 */ 62 TEST_F(WifiStaIfaceHidlTest, SetMacAddress) { 63 const android::hardware::hidl_array<uint8_t, 6> kMac{ 64 std::array<uint8_t, 6>{{0x12, 0x22, 0x33, 0x52, 0x10, 0x41}}}; 65 EXPECT_EQ(WifiStatusCode::SUCCESS, 66 HIDL_INVOKE(wifi_sta_iface_, setMacAddress, kMac).code); 67 } 68 69 /* 70 * ReadApfPacketFilterData: 71 * Ensures that we can read the APF working memory when supported. 72 * 73 * TODO: Test disabled because we can't even test reading and writing the APF 74 * memory while the interface is in disconnected state (b/73804303#comment25). 75 * There's a pending bug on VTS infra to add such support (b/32974062). 76 * TODO: We can't execute APF opcodes from this test because there's no way 77 * to loop test packets through the wifi firmware (b/73804303#comment29). 78 */ 79 TEST_F(WifiStaIfaceHidlTest, DISABLED_ReadApfPacketFilterData) { 80 if (!isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask::APF)) { 81 // Disable test if APF packet filer is not supported. 82 LOG(WARNING) << "TEST SKIPPED: APF packet filtering not supported"; 83 return; 84 } 85 86 const auto& status_and_caps = 87 HIDL_INVOKE(wifi_sta_iface_, getApfPacketFilterCapabilities); 88 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code); 89 LOG(WARNING) << "StaApfPacketFilterCapabilities: version=" 90 << status_and_caps.second.version 91 << " maxLength=" << status_and_caps.second.maxLength; 92 93 const CommandId kCmd = 0; // Matches what WifiVendorHal.java uses. 94 const uint32_t kDataSize = 95 std::min(status_and_caps.second.maxLength, static_cast<uint32_t>(500)); 96 97 // Create a buffer and fill it with some values. 98 std::vector<uint8_t> data(kDataSize); 99 std::iota(data.begin(), data.end(), 0); 100 101 EXPECT_EQ( 102 HIDL_INVOKE(wifi_sta_iface_, installApfPacketFilter, kCmd, data).code, 103 WifiStatusCode::SUCCESS); 104 const auto& status_and_data = 105 HIDL_INVOKE(wifi_sta_iface_, readApfPacketFilterData); 106 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_data.first.code); 107 108 EXPECT_EQ(status_and_data.second, data); 109 } 110