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