Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 1 | /* |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 2 | * Copyright (C) 2022 The Android Open Source Project |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 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 | |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/wifi/IWifi.h> |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 21 | #include <wifi_system/interface_tool.h> |
| 22 | |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 23 | #include "wifi_legacy_hal.h" |
| 24 | |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 25 | namespace aidl { |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace wifi { |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 29 | namespace iface_util { |
| 30 | |
Roshan Pius | 356d5a6 | 2019-05-17 15:07:34 -0700 | [diff] [blame] | 31 | // Iface event handlers. |
| 32 | struct IfaceEventHandlers { |
| 33 | // Callback to be invoked when the iface is set down & up for MAC address |
| 34 | // change. |
| 35 | std::function<void(const std::string& iface_name)> on_state_toggle_off_on; |
| 36 | }; |
| 37 | |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 38 | /** |
| 39 | * Util class for common iface operations. |
| 40 | */ |
| 41 | class WifiIfaceUtil { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 42 | public: |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 43 | WifiIfaceUtil(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool, |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 44 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal); |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 45 | virtual ~WifiIfaceUtil() = default; |
| 46 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 47 | virtual std::array<uint8_t, 6> getFactoryMacAddress(const std::string& iface_name); |
| 48 | virtual bool setMacAddress(const std::string& iface_name, const std::array<uint8_t, 6>& mac); |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 49 | // Get or create a random MAC address. The MAC address returned from |
| 50 | // this method will remain the same throughout the lifetime of the HAL |
| 51 | // daemon. (So, changes on every reboot) |
| 52 | virtual std::array<uint8_t, 6> getOrCreateRandomMacAddress(); |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 53 | |
Roshan Pius | 356d5a6 | 2019-05-17 15:07:34 -0700 | [diff] [blame] | 54 | // Register for any iface event callbacks for the provided interface. |
| 55 | virtual void registerIfaceEventHandlers(const std::string& iface_name, |
| 56 | IfaceEventHandlers handlers); |
| 57 | virtual void unregisterIfaceEventHandlers(const std::string& iface_name); |
Roshan Pius | 5ba0a90 | 2020-04-14 11:55:42 -0700 | [diff] [blame] | 58 | virtual bool setUpState(const std::string& iface_name, bool request_up); |
Nate Jiang | 63f34ed | 2020-05-20 23:22:51 -0700 | [diff] [blame] | 59 | virtual unsigned ifNameToIndex(const std::string& iface_name); |
Roshan Pius | 356d5a6 | 2019-05-17 15:07:34 -0700 | [diff] [blame] | 60 | |
lesl | c92aa85 | 2020-11-16 15:20:33 +0800 | [diff] [blame] | 61 | virtual bool createBridge(const std::string& br_name); |
| 62 | |
| 63 | virtual bool deleteBridge(const std::string& br_name); |
| 64 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 65 | virtual bool addIfaceToBridge(const std::string& br_name, const std::string& if_name); |
lesl | c92aa85 | 2020-11-16 15:20:33 +0800 | [diff] [blame] | 66 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 67 | virtual bool removeIfaceFromBridge(const std::string& br_name, const std::string& if_name); |
Les Lee | da9f5fe | 2021-06-29 22:48:11 +0800 | [diff] [blame] | 68 | // Get a random MAC address. |
| 69 | virtual std::array<uint8_t, 6> createRandomMacAddress(); |
lesl | c92aa85 | 2020-11-16 15:20:33 +0800 | [diff] [blame] | 70 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 71 | private: |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 72 | std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_; |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 73 | std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 74 | std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_; |
Roshan Pius | 356d5a6 | 2019-05-17 15:07:34 -0700 | [diff] [blame] | 75 | std::map<std::string, IfaceEventHandlers> event_handlers_map_; |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace iface_util |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 79 | } // namespace wifi |
| 80 | } // namespace hardware |
| 81 | } // namespace android |
Gabriel Biren | e58e263 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 82 | } // namespace aidl |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 83 | |
| 84 | #endif // WIFI_IFACE_UTIL_H_ |