• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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_IFACE_UTIL_H_
18 #define WIFI_IFACE_UTIL_H_
19 
20 #include <wifi_system/interface_tool.h>
21 
22 #include <android/hardware/wifi/1.0/IWifi.h>
23 
24 #include "wifi_legacy_hal.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace wifi {
29 namespace V1_6 {
30 namespace implementation {
31 namespace iface_util {
32 
33 // Iface event handlers.
34 struct IfaceEventHandlers {
35     // Callback to be invoked when the iface is set down & up for MAC address
36     // change.
37     std::function<void(const std::string& iface_name)> on_state_toggle_off_on;
38 };
39 
40 /**
41  * Util class for common iface operations.
42  */
43 class WifiIfaceUtil {
44   public:
45     WifiIfaceUtil(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool,
46                   const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal);
47     virtual ~WifiIfaceUtil() = default;
48 
49     virtual std::array<uint8_t, 6> getFactoryMacAddress(const std::string& iface_name);
50     virtual bool setMacAddress(const std::string& iface_name, const std::array<uint8_t, 6>& mac);
51     // Get or create a random MAC address. The MAC address returned from
52     // this method will remain the same throughout the lifetime of the HAL
53     // daemon. (So, changes on every reboot)
54     virtual std::array<uint8_t, 6> getOrCreateRandomMacAddress();
55 
56     // Register for any iface event callbacks for the provided interface.
57     virtual void registerIfaceEventHandlers(const std::string& iface_name,
58                                             IfaceEventHandlers handlers);
59     virtual void unregisterIfaceEventHandlers(const std::string& iface_name);
60     virtual bool setUpState(const std::string& iface_name, bool request_up);
61     virtual unsigned ifNameToIndex(const std::string& iface_name);
62 
63     virtual bool createBridge(const std::string& br_name);
64 
65     virtual bool deleteBridge(const std::string& br_name);
66 
67     virtual bool addIfaceToBridge(const std::string& br_name, const std::string& if_name);
68 
69     virtual bool removeIfaceFromBridge(const std::string& br_name, const std::string& if_name);
70     // Get a random MAC address.
71     virtual std::array<uint8_t, 6> createRandomMacAddress();
72 
73   private:
74     std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
75     std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
76     std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_;
77     std::map<std::string, IfaceEventHandlers> event_handlers_map_;
78 };
79 
80 }  // namespace iface_util
81 }  // namespace implementation
82 }  // namespace V1_6
83 }  // namespace wifi
84 }  // namespace hardware
85 }  // namespace android
86 
87 #endif  // WIFI_IFACE_UTIL_H_
88