blob: 9a8681afed5c5e234122f521bae9fdcf0a1543f5 [file] [log] [blame]
Roshan Pius3e2d6712016-10-06 13:16:23 -07001/*
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
Roshan Pius3e2d6712016-10-06 13:16:23 -070017#include <android-base/logging.h>
18
Roshan Pius907d4a22016-10-27 12:48:12 -070019#include "hidl_return_util.h"
Roshan Pius7f4574d2017-02-22 09:48:03 -080020#include "hidl_struct_util.h"
Roshan Pius907d4a22016-10-27 12:48:12 -070021#include "wifi_ap_iface.h"
Roshan Pius734fea02016-10-11 08:30:28 -070022#include "wifi_status_util.h"
Roshan Pius3e2d6712016-10-06 13:16:23 -070023
24namespace android {
25namespace hardware {
26namespace wifi {
Jong Wook Kimda830c92018-07-23 15:29:38 -070027namespace V1_3 {
Roshan Pius3e2d6712016-10-06 13:16:23 -070028namespace implementation {
Roshan Pius907d4a22016-10-27 12:48:12 -070029using hidl_return_util::validateAndCall;
Roshan Pius3e2d6712016-10-06 13:16:23 -070030
Roshan Pius6cedc972016-10-28 10:11:17 -070031WifiApIface::WifiApIface(
32 const std::string& ifname,
Roshan Pius99dab382019-02-14 07:57:10 -080033 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
Roshan Pius3b6705f2019-02-14 09:43:43 -080034 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
35 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags)
Roshan Pius99dab382019-02-14 07:57:10 -080036 : ifname_(ifname),
37 legacy_hal_(legacy_hal),
38 iface_util_(iface_util),
Roshan Pius3b6705f2019-02-14 09:43:43 -080039 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}
Roshan Pius3e2d6712016-10-06 13:16:23 -070054
55void WifiApIface::invalidate() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070056 legacy_hal_.reset();
57 is_valid_ = false;
Roshan Pius3e2d6712016-10-06 13:16:23 -070058}
59
Roshan Piusabcf78f2017-10-06 16:30:38 -070060bool WifiApIface::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -070061
Roshan Pius675609b2017-10-31 14:24:58 -070062std::string WifiApIface::getName() { return ifname_; }
63
Roshan Pius734fea02016-10-11 08:30:28 -070064Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070065 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
66 &WifiApIface::getNameInternal, hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -070067}
68
Roshan Pius734fea02016-10-11 08:30:28 -070069Return<void> WifiApIface::getType(getType_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070070 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
71 &WifiApIface::getTypeInternal, hidl_status_cb);
Roshan Pius907d4a22016-10-27 12:48:12 -070072}
73
Roshan Pius32fc12e2017-01-25 17:44:42 -080074Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code,
75 setCountryCode_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070076 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
77 &WifiApIface::setCountryCodeInternal, hidl_status_cb,
78 code);
Roshan Pius32fc12e2017-01-25 17:44:42 -080079}
80
Roshan Pius7f4574d2017-02-22 09:48:03 -080081Return<void> WifiApIface::getValidFrequenciesForBand(
82 WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070083 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
84 &WifiApIface::getValidFrequenciesForBandInternal,
85 hidl_status_cb, band);
Roshan Pius7f4574d2017-02-22 09:48:03 -080086}
87
Roshan Pius907d4a22016-10-27 12:48:12 -070088std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070089 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
Roshan Pius907d4a22016-10-27 12:48:12 -070090}
91
92std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070093 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP};
Roshan Pius3e2d6712016-10-06 13:16:23 -070094}
95
Roshan Pius32fc12e2017-01-25 17:44:42 -080096WifiStatus WifiApIface::setCountryCodeInternal(
97 const std::array<int8_t, 2>& code) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070098 legacy_hal::wifi_error legacy_status =
99 legacy_hal_.lock()->setCountryCode(ifname_, code);
100 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius32fc12e2017-01-25 17:44:42 -0800101}
102
Roshan Pius7f4574d2017-02-22 09:48:03 -0800103std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
104WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700105 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};
Roshan Pius7f4574d2017-02-22 09:48:03 -0800113}
Roshan Pius3e2d6712016-10-06 13:16:23 -0700114} // namespace implementation
Jong Wook Kimda830c92018-07-23 15:29:38 -0700115} // namespace V1_3
Roshan Pius3e2d6712016-10-06 13:16:23 -0700116} // namespace wifi
117} // namespace hardware
118} // namespace android