1 /* 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 17 #ifndef ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H 18 #define ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H 19 20 #include <array> 21 #include <cstdint> 22 #include <linux/if_ether.h> 23 24 namespace android { 25 namespace wifi_system { 26 27 class InterfaceTool { 28 public: 29 InterfaceTool() = default; 30 virtual ~InterfaceTool() = default; 31 32 // Get the interface state of |if_name|. 33 // Returns true iff the interface is up. 34 virtual bool GetUpState(const char* if_name); 35 36 // Set the interface named by |if_name| up or down. 37 // Returns true on success, false otherwise. 38 virtual bool SetUpState(const char* if_name, bool request_up); 39 40 // A helpful alias for SetUpState() that assumes there is a single system 41 // WiFi interface. Prefer this form if you're hardcoding "wlan0" to help us 42 // identify all the places we are hardcoding the name of the wifi interface. 43 virtual bool SetWifiUpState(bool request_up); 44 45 // Set the MAC address of the |if_name| interface 46 // Returns true on success, false otherwise. 47 virtual bool SetMacAddress(const char* if_name, 48 const std::array<uint8_t, ETH_ALEN>& address); 49 50 // Get the factory MAC address of the |if_name| interface. 51 // Returns all-zero address on error. 52 virtual std::array<uint8_t, ETH_ALEN> GetFactoryMacAddress(const char* if_name); 53 54 // Create a bridge 55 virtual bool createBridge(const std::string& br_name); 56 57 // Delete a bridge 58 virtual bool deleteBridge(const std::string& br_name); 59 60 // Add interface to bridge 61 virtual bool addIfaceToBridge(const std::string& br_name, 62 const std::string& if_name); 63 64 // Remove interface from bridge 65 virtual bool removeIfaceFromBridge(const std::string& br_name, 66 const std::string& if_name); 67 }; // class InterfaceTool 68 69 } // namespace wifi_system 70 } // namespace android 71 72 #endif // ANDROID_WIFI_SYSTEM_INTERFACE_TOOL_H 73