diff options
author | Roshan Pius <rpius@google.com> | 2018-01-04 14:59:12 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-01-12 16:13:25 -0800 |
commit | b283fd04f71fbcd0354a3aff796454f0a9067f09 (patch) | |
tree | f2f96a9e393eccfb7fc3c0a9c99291be7439778b | |
parent | 295a0f1632f2c46ffb050ad538eddeb9a2aa7a76 (diff) | |
download | android_frameworks_opt_net_wifi-b283fd04f71fbcd0354a3aff796454f0a9067f09.tar.gz android_frameworks_opt_net_wifi-b283fd04f71fbcd0354a3aff796454f0a9067f09.tar.bz2 android_frameworks_opt_net_wifi-b283fd04f71fbcd0354a3aff796454f0a9067f09.zip |
libwifi-system: Remove unused methods from HostapdManager
This functionality has been migrated to the HIDL interface.
Bug: 36646171
Test: Compiles
Change-Id: If3fb7a016459fa5ddf33c4df064250cc543a0d5d
-rw-r--r-- | libwifi_system/Android.bp | 18 | ||||
-rw-r--r-- | libwifi_system/hostapd_manager.cpp | 150 | ||||
-rw-r--r-- | libwifi_system/include/wifi_system/hostapd_manager.h | 22 | ||||
-rw-r--r-- | libwifi_system/testlib/include/wifi_system_test/mock_hostapd_manager.h | 9 | ||||
-rw-r--r-- | libwifi_system/tests/hostapd_manager_unittest.cpp | 128 | ||||
-rw-r--r-- | libwifi_system/tests/main.cpp | 27 |
6 files changed, 0 insertions, 354 deletions
diff --git a/libwifi_system/Android.bp b/libwifi_system/Android.bp index f5ea184f3..a3aa7034a 100644 --- a/libwifi_system/Android.bp +++ b/libwifi_system/Android.bp @@ -56,21 +56,3 @@ cc_library_static { "testlib/include", ], } - -// Unit tests for libwifi-system -// ============================================================ -cc_test { - name: "libwifi-system_tests", - defaults: ["libwifi-system-defaults"], - srcs: [ - "tests/main.cpp", - "tests/hostapd_manager_unittest.cpp", - ], - static_libs: [ - "libgmock", - ], - shared_libs: [ - "libbase", - "libwifi-system", - ], -} diff --git a/libwifi_system/hostapd_manager.cpp b/libwifi_system/hostapd_manager.cpp index 8c7de320b..3f2e27f23 100644 --- a/libwifi_system/hostapd_manager.cpp +++ b/libwifi_system/hostapd_manager.cpp @@ -16,66 +16,12 @@ #include "wifi_system/hostapd_manager.h" -#include <iomanip> -#include <sstream> -#include <string> -#include <vector> - -#include <android-base/file.h> #include <android-base/logging.h> -#include <android-base/parseint.h> -#include <android-base/stringprintf.h> #include <cutils/properties.h> -#include <openssl/evp.h> -#include <openssl/sha.h> -#include <private/android_filesystem_config.h> - -#include "wifi_system/supplicant_manager.h" - -using android::base::ParseInt; -using android::base::ReadFileToString; -using android::base::RemoveFileIfExists; -using android::base::StringPrintf; -using android::base::WriteStringToFile; -using std::string; -using std::vector; -using std::stringstream; namespace android { namespace wifi_system { -namespace { - -const int kDefaultApChannel = 6; const char kHostapdServiceName[] = "hostapd"; -const char kHostapdConfigFilePath[] = "/data/misc/wifi/hostapd.conf"; - - -string GeneratePsk(const vector<uint8_t>& ssid, - const vector<uint8_t>& passphrase) { - string result; - unsigned char psk[SHA256_DIGEST_LENGTH]; - - // Use the PKCS#5 PBKDF2 with 4096 iterations - if (PKCS5_PBKDF2_HMAC_SHA1(reinterpret_cast<const char*>(passphrase.data()), - passphrase.size(), - ssid.data(), ssid.size(), - 4096, sizeof(psk), psk) != 1) { - LOG(ERROR) << "Cannot generate PSK using PKCS#5 PBKDF2"; - return result; - } - - stringstream ss; - ss << std::hex; - ss << std::setfill('0'); - for (int j = 0; j < SHA256_DIGEST_LENGTH; j++) { - ss << std::setw(2) << static_cast<unsigned int>(psk[j]); - } - result = ss.str(); - - return result; -} - -} // namespace bool HostapdManager::StartHostapd() { if (property_set("ctl.start", kHostapdServiceName) != 0) { @@ -98,101 +44,5 @@ bool HostapdManager::StopHostapd() { LOG(DEBUG) << "SoftAP stopped successfully"; return true; } - -bool HostapdManager::WriteHostapdConfig(const string& config) { - // Remove hostapd.conf because its file owner might be system - // in previous OS and chmod fails in that case. - RemoveFileIfExists(kHostapdConfigFilePath); - if (!WriteStringToFile(config, kHostapdConfigFilePath, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, - AID_WIFI, AID_WIFI)) { - int error = errno; - LOG(ERROR) << "Cannot write hostapd config to \"" - << kHostapdConfigFilePath << "\": " << strerror(error); - struct stat st; - int result = stat(kHostapdConfigFilePath, &st); - if (result == 0) { - LOG(ERROR) << "hostapd config file uid: "<< st.st_uid << ", gid: " << st.st_gid - << ", mode: " << st.st_mode; - } else { - LOG(ERROR) << "Error calling stat() on hostapd config file: " << strerror(errno); - } - return false; - } - return true; -} - -string HostapdManager::CreateHostapdConfig( - const string& interface_name, - const vector<uint8_t> ssid, - bool is_hidden, - int channel, - EncryptionType encryption_type, - const vector<uint8_t> passphrase) { - string result; - - if (channel < 0) { - channel = kDefaultApChannel; - } - - if (ssid.size() > 32) { - LOG(ERROR) << "SSIDs must be <= 32 bytes long"; - return result; - } - - stringstream ss; - ss << std::hex; - ss << std::setfill('0'); - for (uint8_t b : ssid) { - ss << std::setw(2) << static_cast<unsigned int>(b); - } - const string ssid_as_string = ss.str(); - - string encryption_config; - if (encryption_type != EncryptionType::kOpen) { - string psk = GeneratePsk(ssid, passphrase); - if (psk.empty()) { - return result; - } - if (encryption_type == EncryptionType::kWpa) { - encryption_config = StringPrintf("wpa=3\n" - "wpa_pairwise=TKIP CCMP\n" - "wpa_psk=%s\n", psk.c_str()); - } else if (encryption_type == EncryptionType::kWpa2) { - encryption_config = StringPrintf("wpa=2\n" - "rsn_pairwise=CCMP\n" - "wpa_psk=%s\n", psk.c_str()); - } else { - using encryption_t = std::underlying_type<EncryptionType>::type; - LOG(ERROR) << "Unknown encryption type (" - << static_cast<encryption_t>(encryption_type) - << ")"; - return result; - } - } - - result = StringPrintf( - "interface=%s\n" - "driver=nl80211\n" - "ctrl_interface=/data/misc/wifi/hostapd/ctrl\n" - // ssid2 signals to hostapd that the value is not a literal value - // for use as a SSID. In this case, we're giving it a hex string - // and hostapd needs to expect that. - "ssid2=%s\n" - "channel=%d\n" - "ieee80211n=1\n" - "hw_mode=%c\n" - "ignore_broadcast_ssid=%d\n" - "wowlan_triggers=any\n" - "%s", - interface_name.c_str(), - ssid_as_string.c_str(), - channel, - (channel <= 14) ? 'g' : 'a', - (is_hidden) ? 1 : 0, - encryption_config.c_str()); - return result; -} - } // namespace wifi_system } // namespace android diff --git a/libwifi_system/include/wifi_system/hostapd_manager.h b/libwifi_system/include/wifi_system/hostapd_manager.h index 485267078..6e351bf54 100644 --- a/libwifi_system/include/wifi_system/hostapd_manager.h +++ b/libwifi_system/include/wifi_system/hostapd_manager.h @@ -44,28 +44,6 @@ class HostapdManager { // Returns true on success. virtual bool StopHostapd(); - // Create a string suitable for writing to the hostapd configuration file. - // |interface_name| is a network interface name (e.g. "wlan0"). - // |ssid| is the SSID used by the configurated network. - // |is_hidden| is true iff hostapd should not broadcast the SSID. - // |channel| is the WiFi channel (e.g. 6) or <0 for a default value. - // |encryption_type| defines the encryption of the configured network. - // |passphrase| is ignored for kOpen networks. - // - // Returns an empty string on failure. - virtual std::string CreateHostapdConfig( - const std::string& interface_name, - const std::vector<uint8_t> ssid, - bool is_hidden, - int channel, - EncryptionType encryption, - const std::vector<uint8_t> passphrase); - - // Write out a hostapd configuration file created via CreateHostapdConfig(). - // Future instances of hostapd will use this new configuration. - // Returns true if the configuration file is successfully written. - virtual bool WriteHostapdConfig(const std::string& config_file); - private: DISALLOW_COPY_AND_ASSIGN(HostapdManager); }; // class HostapdManager diff --git a/libwifi_system/testlib/include/wifi_system_test/mock_hostapd_manager.h b/libwifi_system/testlib/include/wifi_system_test/mock_hostapd_manager.h index 94ed41b42..f15222c3e 100644 --- a/libwifi_system/testlib/include/wifi_system_test/mock_hostapd_manager.h +++ b/libwifi_system/testlib/include/wifi_system_test/mock_hostapd_manager.h @@ -30,15 +30,6 @@ class MockHostapdManager : public HostapdManager { MOCK_METHOD0(StartHostapd, bool()); MOCK_METHOD0(IsHostapdRunning, bool()); MOCK_METHOD0(StopHostapd, bool()); - MOCK_METHOD6(CreateHostapdConfig, std::string( - const std::string& interface_name, - const std::vector<uint8_t> ssid, - bool is_hidden, - int channel, - EncryptionType encryption, - const std::vector<uint8_t> passphrase)); - MOCK_METHOD1(WriteHostapdConfig, bool(const std::string& config_file)); - }; // class MockHostapdManager } // namespace wifi_system diff --git a/libwifi_system/tests/hostapd_manager_unittest.cpp b/libwifi_system/tests/hostapd_manager_unittest.cpp deleted file mode 100644 index b25dd8ec7..000000000 --- a/libwifi_system/tests/hostapd_manager_unittest.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2016, The Android Open Source Project - * - * Licensed under the Apache 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 <gmock/gmock.h> -#include <gtest/gtest.h> - -#include <string> -#include <vector> - -#include "wifi_system/hostapd_manager.h" - -using std::string; -using std::vector; -using testing::HasSubstr; -using testing::Not; - -namespace android { -namespace wifi_system { -namespace { - -const char kTestInterfaceName[] = "foobar0"; -const char kTestSsidStr[] = "helloisitme"; -const char kTestPassphraseStr[] = "yourelookingfor"; -const int kTestChannel = 2; - -// If you generate your config file with both the test ssid -// and the test passphrase, you'll get this line in the config. -const char kConfigPskLine[] = - "wpa_psk=dffa36815281e5a6eca1910f254717fa2528681335e3bbec5966d2aa9221a66e\n"; - -class HostapdManagerTest : public ::testing::Test { - protected: - string GetConfigForEncryptionType( - HostapdManager::EncryptionType encryption_type) { - return HostapdManager().CreateHostapdConfig( - kTestInterfaceName, - cstr2vector(kTestSsidStr), - false, // not hidden - kTestChannel, - encryption_type, - cstr2vector(kTestPassphraseStr)); - } - - vector<uint8_t> cstr2vector(const char* data) { - return vector<uint8_t>(data, data + strlen(data)); - } -}; // class HostapdManagerTest - -// This is used to verify config string generated by test helper function -// |GetConfigForEncryptionType|. -void VerifyCommonConfigs(const string& config) { - EXPECT_THAT(config, HasSubstr("interface=foobar0\n")); - EXPECT_THAT(config, HasSubstr("driver=nl80211\n")); - EXPECT_THAT(config, HasSubstr("ctrl_interface=/data/misc/wifi/hostapd/ctrl\n")); - EXPECT_THAT(config, HasSubstr("ssid2=68656c6c6f" "6973" "6974" "6d65\n")); - EXPECT_THAT(config, HasSubstr("channel=2\n")); - EXPECT_THAT(config, HasSubstr("hw_mode=g\n")); - EXPECT_THAT(config, HasSubstr("wowlan_triggers=any\n")); - EXPECT_THAT(config, HasSubstr("ignore_broadcast_ssid=0\n")); - EXPECT_THAT(config, Not(HasSubstr("ignore_broadcast_ssid=1\n"))); -} - -} // namespace - -TEST_F(HostapdManagerTest, GeneratesCorrectOpenConfig) { - string config = GetConfigForEncryptionType( - HostapdManager::EncryptionType::kOpen); - VerifyCommonConfigs(config); -} - -TEST_F(HostapdManagerTest, GeneratesCorrectWpaConfig) { - string config = GetConfigForEncryptionType( - HostapdManager::EncryptionType::kWpa); - VerifyCommonConfigs(config); - EXPECT_THAT(config, HasSubstr("wpa=3\n")); - EXPECT_THAT(config, HasSubstr("wpa_pairwise=TKIP CCMP\n")); - EXPECT_THAT(config, HasSubstr(kConfigPskLine)); -} - -TEST_F(HostapdManagerTest, GeneratesCorrectWpa2Config) { - string config = GetConfigForEncryptionType( - HostapdManager::EncryptionType::kWpa2); - VerifyCommonConfigs(config); - EXPECT_THAT(config, HasSubstr("wpa=2\n")); - EXPECT_THAT(config, HasSubstr("rsn_pairwise=CCMP\n")); - EXPECT_THAT(config, HasSubstr(kConfigPskLine)); -} - -TEST_F(HostapdManagerTest, RespectsHiddenSetting) { - string config = HostapdManager().CreateHostapdConfig( - kTestInterfaceName, - cstr2vector(kTestSsidStr), - true, - kTestChannel, - HostapdManager::EncryptionType::kOpen, - vector<uint8_t>()); - EXPECT_THAT(config, HasSubstr("ignore_broadcast_ssid=1\n")); - EXPECT_THAT(config, Not(HasSubstr("ignore_broadcast_ssid=0\n"))); -} - -TEST_F(HostapdManagerTest, CorrectlyInfersHwMode) { - string config = HostapdManager().CreateHostapdConfig( - kTestInterfaceName, - cstr2vector(kTestSsidStr), - true, - 44, - HostapdManager::EncryptionType::kOpen, - vector<uint8_t>()); - EXPECT_THAT(config, HasSubstr("hw_mode=a\n")); - EXPECT_THAT(config, Not(HasSubstr("hw_mode=g\n"))); -} - - -} // namespace wifi_system -} // namespace android diff --git a/libwifi_system/tests/main.cpp b/libwifi_system/tests/main.cpp deleted file mode 100644 index 51e8dad29..000000000 --- a/libwifi_system/tests/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache 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 <gtest/gtest.h> - -#include <android-base/logging.h> - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - // Force ourselves to always log to stderr - android::base::InitLogging(argv, android::base::StderrLogger); - return RUN_ALL_TESTS(); -} - |