blob: 284f9b9774fd191ca5056740f831e1a92c19f6f6 [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 {
Etan Cohen6ce50902017-09-14 07:30:57 -070027namespace V1_2 {
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,
33 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
Roshan Pius3e2d6712016-10-06 13:16:23 -070034 : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {}
35
36void WifiApIface::invalidate() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070037 legacy_hal_.reset();
38 is_valid_ = false;
Roshan Pius3e2d6712016-10-06 13:16:23 -070039}
40
Roshan Piusabcf78f2017-10-06 16:30:38 -070041bool WifiApIface::isValid() { return is_valid_; }
Roshan Pius907d4a22016-10-27 12:48:12 -070042
Roshan Pius734fea02016-10-11 08:30:28 -070043Return<void> WifiApIface::getName(getName_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070044 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
45 &WifiApIface::getNameInternal, hidl_status_cb);
Roshan Pius3e2d6712016-10-06 13:16:23 -070046}
47
Roshan Pius734fea02016-10-11 08:30:28 -070048Return<void> WifiApIface::getType(getType_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070049 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
50 &WifiApIface::getTypeInternal, hidl_status_cb);
Roshan Pius907d4a22016-10-27 12:48:12 -070051}
52
Roshan Pius32fc12e2017-01-25 17:44:42 -080053Return<void> WifiApIface::setCountryCode(const hidl_array<int8_t, 2>& code,
54 setCountryCode_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070055 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
56 &WifiApIface::setCountryCodeInternal, hidl_status_cb,
57 code);
Roshan Pius32fc12e2017-01-25 17:44:42 -080058}
59
Roshan Pius7f4574d2017-02-22 09:48:03 -080060Return<void> WifiApIface::getValidFrequenciesForBand(
61 WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070062 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
63 &WifiApIface::getValidFrequenciesForBandInternal,
64 hidl_status_cb, band);
Roshan Pius7f4574d2017-02-22 09:48:03 -080065}
66
Roshan Pius907d4a22016-10-27 12:48:12 -070067std::pair<WifiStatus, std::string> WifiApIface::getNameInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070068 return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_};
Roshan Pius907d4a22016-10-27 12:48:12 -070069}
70
71std::pair<WifiStatus, IfaceType> WifiApIface::getTypeInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -070072 return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::AP};
Roshan Pius3e2d6712016-10-06 13:16:23 -070073}
74
Roshan Pius32fc12e2017-01-25 17:44:42 -080075WifiStatus WifiApIface::setCountryCodeInternal(
76 const std::array<int8_t, 2>& code) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070077 legacy_hal::wifi_error legacy_status =
78 legacy_hal_.lock()->setCountryCode(ifname_, code);
79 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius32fc12e2017-01-25 17:44:42 -080080}
81
Roshan Pius7f4574d2017-02-22 09:48:03 -080082std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
83WifiApIface::getValidFrequenciesForBandInternal(WifiBand band) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070084 static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t),
85 "Size mismatch");
86 legacy_hal::wifi_error legacy_status;
87 std::vector<uint32_t> valid_frequencies;
88 std::tie(legacy_status, valid_frequencies) =
89 legacy_hal_.lock()->getValidFrequenciesForBand(
90 ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band));
91 return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies};
Roshan Pius7f4574d2017-02-22 09:48:03 -080092}
Roshan Pius3e2d6712016-10-06 13:16:23 -070093} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -070094} // namespace V1_2
Roshan Pius3e2d6712016-10-06 13:16:23 -070095} // namespace wifi
96} // namespace hardware
97} // namespace android