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 | 1ec4e7e | 2015-09-17 21:49:00 -0700 | [diff] [blame] | 29 | #include "dbus_bindings/org.chromium.apmanager.Device.h" |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 30 | |
| 31 | namespace apmanager { |
| 32 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 33 | class Manager; |
| 34 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 35 | // Abstraction for WiFi Device (PHY). Each device can have one or more |
| 36 | // interfaces defined on it. |
| 37 | class Device : public base::RefCounted<Device>, |
| 38 | public org::chromium::apmanager::DeviceAdaptor, |
| 39 | public org::chromium::apmanager::DeviceInterface { |
| 40 | public: |
| 41 | struct WiFiInterface { |
| 42 | WiFiInterface() : iface_index(0), iface_type(0) {} |
| 43 | WiFiInterface(const std::string& in_iface_name, |
| 44 | const std::string& in_device_name, |
| 45 | uint32_t in_iface_index, |
| 46 | uint32_t in_iface_type) |
| 47 | : iface_name(in_iface_name), |
| 48 | device_name(in_device_name), |
| 49 | iface_index(in_iface_index), |
| 50 | iface_type(in_iface_type) {} |
| 51 | std::string iface_name; |
| 52 | std::string device_name; |
| 53 | uint32_t iface_index; |
| 54 | uint32_t iface_type; |
| 55 | bool Equals(const WiFiInterface& other) const { |
| 56 | return this->iface_name == other.iface_name && |
| 57 | this->device_name == other.device_name && |
| 58 | this->iface_index == other.iface_index && |
| 59 | this->iface_type == other.iface_type; |
| 60 | } |
| 61 | }; |
| 62 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 63 | struct BandCapability { |
| 64 | std::vector<uint32_t> frequencies; |
| 65 | uint16_t ht_capability_mask; |
| 66 | uint16_t vht_capability_mask; |
| 67 | }; |
| 68 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 69 | Device(Manager* manager, const std::string& device_name); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 70 | virtual ~Device(); |
| 71 | |
| 72 | // Register Device DBus object. |
| 73 | void RegisterAsync( |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 74 | brillo::dbus_utils::ExportedObjectManager* object_manager, |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 75 | const scoped_refptr<dbus::Bus>& bus, |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 76 | brillo::dbus_utils::AsyncEventSequencer* sequencer, |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 77 | int device_identifier); |
| 78 | |
| 79 | // Register/deregister WiFi interface on this device. |
| 80 | virtual void RegisterInterface(const WiFiInterface& interface); |
| 81 | virtual void DeregisterInterface(const WiFiInterface& interface); |
| 82 | |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame] | 83 | // Parse device capability from NL80211 message. |
| 84 | void ParseWiphyCapability(const shill::Nl80211Message& msg); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 85 | |
Peter Qiu | 0ca183b | 2015-03-09 13:41:06 -0700 | [diff] [blame] | 86 | // Claim ownership of this device for AP operation. When |full_control| is |
| 87 | // set to true, this will claim all interfaces reside on this device. |
| 88 | // When it is set to false, this will only claim the interface used for AP |
| 89 | // operation. |
| 90 | virtual bool ClaimDevice(bool full_control); |
| 91 | // Release any claimed interfaces. |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 92 | virtual bool ReleaseDevice(); |
| 93 | |
| 94 | // Return true if interface with |interface_name| resides on this device, |
| 95 | // false otherwise. |
| 96 | virtual bool InterfaceExists(const std::string& interface_name); |
| 97 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 98 | // Get HT and VHT capability string based on the operating channel. |
| 99 | // Return true and set the output capability string if such capability |
| 100 | // exist for the band the given |channel| is in, false otherwise. |
| 101 | virtual bool GetHTCapability(uint16_t channel, std::string* ht_cap); |
| 102 | virtual bool GetVHTCapability(uint16_t channel, std::string* vht_cap); |
| 103 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 104 | private: |
| 105 | friend class DeviceTest; |
| 106 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 107 | // Get the HT secondary channel location base on the primary channel. |
| 108 | // Return true and set the output |above| flag if channel is valid, |
| 109 | // otherwise return false. |
| 110 | static bool GetHTSecondaryChannelLocation(uint16_t channel, bool* above); |
| 111 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 112 | // Determine preferred interface to used for AP operation based on the list |
| 113 | // of interfaces reside on this device |
| 114 | void UpdatePreferredAPInterface(); |
| 115 | |
Peter Qiu | 8e785b9 | 2014-11-24 10:01:08 -0800 | [diff] [blame] | 116 | // Get the capability for the band the given |channel| is in. Return true |
| 117 | // and set the output |capability| pointer if such capability exist for the |
| 118 | // band the given |channel| is in, false otherwise. |
| 119 | bool GetBandCapability(uint16_t channel, BandCapability* capability); |
| 120 | |
Peter Qiu | 7e0ffcf | 2014-12-02 12:53:27 -0800 | [diff] [blame] | 121 | Manager* manager_; |
| 122 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 123 | // List of WiFi interfaces live on this device (PHY). |
| 124 | std::vector<WiFiInterface> interface_list_; |
| 125 | |
| 126 | dbus::ObjectPath dbus_path_; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 127 | std::unique_ptr<brillo::dbus_utils::DBusObject> dbus_object_; |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 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 | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 138 | DISALLOW_COPY_AND_ASSIGN(Device); |
| 139 | }; |
| 140 | |
| 141 | } // namespace apmanager |
| 142 | |
| 143 | #endif // APMANAGER_DEVICE_H_ |