xref: /aosp_15_r20/hardware/interfaces/wifi/aidl/default/wifi_ap_iface.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2022 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 #ifndef WIFI_AP_IFACE_H_
18 #define WIFI_AP_IFACE_H_
19 
20 #include <aidl/android/hardware/wifi/BnWifiApIface.h>
21 #include <android-base/macros.h>
22 
23 #include "wifi_iface_util.h"
24 #include "wifi_legacy_hal.h"
25 
26 namespace aidl {
27 namespace android {
28 namespace hardware {
29 namespace wifi {
30 
31 /**
32  * AIDL interface object used to control an AP Iface instance.
33  */
34 class WifiApIface : public BnWifiApIface {
35   public:
36     WifiApIface(const std::string& ifname, const bool usesMlo,
37                 const std::vector<std::string>& instances,
38                 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
39                 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util);
40     // Refer to |WifiChip::invalidate()|.
41     void invalidate();
42     bool isValid();
43     std::string getName();
44     bool usesMlo();
45     void removeInstance(std::string instance);
46 
47     // AIDL methods exposed.
48     ndk::ScopedAStatus getName(std::string* _aidl_return) override;
49     ndk::ScopedAStatus setCountryCode(const std::array<uint8_t, 2>& in_code) override;
50     ndk::ScopedAStatus setMacAddress(const std::array<uint8_t, 6>& in_mac) override;
51     ndk::ScopedAStatus getFactoryMacAddress(std::array<uint8_t, 6>* _aidl_return) override;
52     ndk::ScopedAStatus resetToFactoryMacAddress() override;
53     ndk::ScopedAStatus getBridgedInstances(std::vector<std::string>* _aidl_return) override;
54     ndk::ScopedAStatus usesMlo(bool* _aidl_return) override;
55 
56   private:
57     // Corresponding worker functions for the AIDL methods.
58     std::pair<std::string, ndk::ScopedAStatus> getNameInternal();
59     ndk::ScopedAStatus setCountryCodeInternal(const std::array<uint8_t, 2>& code);
60     ndk::ScopedAStatus setMacAddressInternal(const std::array<uint8_t, 6>& mac);
61     std::pair<std::array<uint8_t, 6>, ndk::ScopedAStatus> getFactoryMacAddressInternal(
62             const std::string& ifaceName);
63     ndk::ScopedAStatus resetToFactoryMacAddressInternal();
64     std::pair<std::vector<std::string>, ndk::ScopedAStatus> getBridgedInstancesInternal();
65 
66     std::string ifname_;
67     bool uses_mlo_;
68     std::vector<std::string> instances_;
69     std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
70     std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_;
71     bool is_valid_;
72 
73     // The mlo is using one interface but owning two link instances.
74     // The operating should be based on interface.
getOperatingInstanceName()75     inline std::string getOperatingInstanceName() {
76         return (instances_.size() > 0 && !uses_mlo_) ? instances_[0] : ifname_;
77     };
78 
79     DISALLOW_COPY_AND_ASSIGN(WifiApIface);
80 };
81 
82 }  // namespace wifi
83 }  // namespace hardware
84 }  // namespace android
85 }  // namespace aidl
86 
87 #endif  // WIFI_AP_IFACE_H_
88