Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2014 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 | // |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_DEVICE_H_ |
| 18 | #define APMANAGER_DEVICE_H_ |
| 19 | |
Peter Qiu | 0ca183b | 2015-03-09 13:41:06 -0700 | [diff] [blame] | 20 | #include <set> |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <base/macros.h> |
| 25 | #include <base/memory/ref_counted.h> |
| 26 | #include <shill/net/byte_string.h> |
| 27 | #include <shill/net/nl80211_message.h> |
| 28 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 29 | #include "apmanager/device_adaptor_interface.h" |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 30 | |
| 31 | namespace apmanager { |
| 32 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 33 | class ControlInterface; |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 34 | class Manager; |
| 35 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 36 | // Abstraction for WiFi Device (PHY). Each device can have one or more |
| 37 | // interfaces defined on it. |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 38 | class Device : public base::RefCounted<Device> { |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 39 | public: |
| 40 | struct WiFiInterface { |
| 41 | WiFiInterface() : iface_index(0), iface_type(0) {} |
| 42 | WiFiInterface(const std::string& in_iface_name, |
| 43 | const std::string& in_device_name, |
| 44 | uint32_t in_iface_index, |
| 45 | uint32_t in_iface_type) |
| 46 | : iface_name(in_iface_name), |
| 47 | device_name(in_device_name), |
| 48 | iface_index(in_iface_index), |
| 49 | iface_type(in_iface_type) {} |
| 50 | std::string iface_name; |
| 51 | std::string device_name; |
| 52 | uint32_t iface_index; |
| 53 | uint32_t iface_type; |
| 54 | bool Equals(const WiFiInterface& other) const { |
| 55 | return this->iface_name == other.iface_name && |
| 56 | this->device_name == other.device_name && |
| 57 | this->iface_index == other.iface_index && |
| 58 | this->iface_type == other.iface_type; |
| 59 | } |
| 60 | }; |
| 61 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 62 | struct BandCapability { |
| 63 | std::vector<uint32_t> frequencies; |
| 64 | uint16_t ht_capability_mask; |
| 65 | uint16_t vht_capability_mask; |
| 66 | }; |
| 67 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 68 | Device(Manager* manager, |
| 69 | const std::string& device_name, |
| 70 | int identifier); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 71 | virtual ~Device(); |
| 72 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 73 | // Register/deregister WiFi interface on this device. |
| 74 | virtual void RegisterInterface(const WiFiInterface& interface); |
| 75 | virtual void DeregisterInterface(const WiFiInterface& interface); |
| 76 | |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame] | 77 | // Parse device capability from NL80211 message. |
| 78 | void ParseWiphyCapability(const shill::Nl80211Message& msg); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 79 | |
Peter Qiu | 0ca183b | 2015-03-09 13:41:06 -0700 | [diff] [blame] | 80 | // Claim ownership of this device for AP operation. When |full_control| is |
| 81 | // set to true, this will claim all interfaces reside on this device. |
| 82 | // When it is set to false, this will only claim the interface used for AP |
| 83 | // operation. |
| 84 | virtual bool ClaimDevice(bool full_control); |
| 85 | // Release any claimed interfaces. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 86 | virtual bool ReleaseDevice(); |
| 87 | |
| 88 | // Return true if interface with |interface_name| resides on this device, |
| 89 | // false otherwise. |
| 90 | virtual bool InterfaceExists(const std::string& interface_name); |
| 91 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 92 | // Get HT and VHT capability string based on the operating channel. |
| 93 | // Return true and set the output capability string if such capability |
| 94 | // exist for the band the given |channel| is in, false otherwise. |
| 95 | virtual bool GetHTCapability(uint16_t channel, std::string* ht_cap); |
| 96 | virtual bool GetVHTCapability(uint16_t channel, std::string* vht_cap); |
| 97 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 98 | void SetDeviceName(const std::string& device_name); |
| 99 | std::string GetDeviceName() const; |
| 100 | void SetPreferredApInterface(const std::string& interface_name); |
| 101 | std::string GetPreferredApInterface() const; |
| 102 | void SetInUse(bool in_use); |
| 103 | bool GetInUse() const; |
| 104 | |
| 105 | int identifier() const { return identifier_; } |
| 106 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 107 | private: |
| 108 | friend class DeviceTest; |
| 109 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 110 | // Get the HT secondary channel location base on the primary channel. |
| 111 | // Return true and set the output |above| flag if channel is valid, |
| 112 | // otherwise return false. |
| 113 | static bool GetHTSecondaryChannelLocation(uint16_t channel, bool* above); |
| 114 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 115 | // Determine preferred interface to used for AP operation based on the list |
| 116 | // of interfaces reside on this device |
| 117 | void UpdatePreferredAPInterface(); |
| 118 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 119 | // Get the capability for the band the given |channel| is in. Return true |
| 120 | // and set the output |capability| pointer if such capability exist for the |
| 121 | // band the given |channel| is in, false otherwise. |
| 122 | bool GetBandCapability(uint16_t channel, BandCapability* capability); |
| 123 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 124 | Manager* manager_; |
| 125 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 126 | // List of WiFi interfaces live on this device (PHY). |
| 127 | std::vector<WiFiInterface> interface_list_; |
| 128 | |
Peter Qiu | 3d95ac7 | 2014-12-06 18:26:18 -0800 | [diff] [blame] | 129 | // Flag indicating if this device supports AP mode interface or not. |
| 130 | bool supports_ap_mode_; |
| 131 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 132 | // Wiphy band capabilities. |
| 133 | std::vector<BandCapability> band_capability_; |
| 134 | |
Peter Qiu | 0ca183b | 2015-03-09 13:41:06 -0700 | [diff] [blame] | 135 | // List of claimed interfaces. |
| 136 | std::set<std::string> claimed_interfaces_; |
| 137 | |
Peter Qiu | f933540 | 2015-11-16 12:09:16 -0800 | [diff] [blame] | 138 | // Unique device identifier. |
| 139 | int identifier_; |
| 140 | |
| 141 | // Adaptor for communicating with remote clients. |
| 142 | std::unique_ptr<DeviceAdaptorInterface> adaptor_; |
| 143 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 144 | DISALLOW_COPY_AND_ASSIGN(Device); |
| 145 | }; |
| 146 | |
| 147 | } // namespace apmanager |
| 148 | |
| 149 | #endif // APMANAGER_DEVICE_H_ |