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