blob: 9a8681afed5c5e234122f521bae9fdcf0a1543f5 [file] [log] [blame]
Alessandro Astone62b19f42019-09-10 23:32:56 +02001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache 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 "hidl_return_util.h"
20#include "hidl_struct_util.h"
21#include "wifi_ap_iface.h"
22#include "wifi_status_util.h"
23
24namespace android {
25namespace hardware {
26namespace wifi {
27namespace V1_3 {
28namespace implementation {
29using hidl_return_util::validateAndCall;
30
31WifiApIface::WifiApIface(
32 const std::string& ifname,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
34 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
35 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags)
36 : ifname_(ifname),
37 legacy_hal_(legacy_hal),
38 iface_util_(iface_util),
39 feature_flags_(feature_flags),
40 is_valid_(true) {
41 if (feature_flags_.lock()->isApMacRandomizationDisabled()) {
42 LOG(INFO) << "AP MAC randomization disabled";
43 return;
44 }
45 LOG(INFO) << "AP MAC randomization enabled";
46 // Set random MAC address
47 std::array<uint8_t, 6> randomized_mac =
48 iface_util_.lock()->getOrCreateRandomMacAddress();
49 bool status = iface_util_.lock()->setMacAddress(ifname_, randomized_mac);
50 if (!status) {
51 LOG(ERROR) << "Failed to set random mac address";
52 }
53}
54
55void WifiApIface::invalidate() {
56 legacy_hal_.reset();
57 is_valid_ = false;
58}
59
60bool WifiApIface::isValid() { return is_valid_; }
61
62std::string WifiApIface::getName() { return ifname_; }
63
64Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
65 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
66 &WifiApIface::getNameInternal, hidl_status_cb);
67}
68
69Return<void> WifiApIface::getType(getType_cb hidl_status_cb) {
70 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
71 &WifiApIface::getTypeInternal, hidl_status_cb);
72}
73
74Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code,
75 setCountryCode_cb hidl_status_cb) {
76 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
77 &WifiApIface::setCountryCodeInternal, hidl_status_cb,
78 code);
79}
80
81Return<void> WifiApIface::getValidFrequenciesForBand(
82 WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) {
83 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
84 &WifiApIface::getValidFrequenciesForBandInternal,
85 hidl_status_cb, band);
86}
87
88std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
89 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
90}
91
92std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {
93 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP};
94}
95
96WifiStatus WifiApIface::setCountryCodeInternal(
97 const std::array<int8_t, 2>& code) {
98 legacy_hal::wifi_error legacy_status =
99 legacy_hal_.lock()->setCountryCode(ifname_, code);
100 return createWifiStatusFromLegacyError(legacy_status);
101}
102
103std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
104WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) {
105 static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t),
106 "Size mismatch");
107 legacy_hal::wifi_error legacy_status;
108 std::vector<uint32_t> valid_frequencies;
109 std::tie(legacy_status, valid_frequencies) =
110 legacy_hal_.lock()->getValidFrequenciesForBand(
111 ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band));
112 return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies};
113}
114} // namespace implementation
115} // namespace V1_3
116} // namespace wifi
117} // namespace hardware
118} // namespace android