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 | |
| 20 | // Abstraction for WiFi Device (PHY). Each device can have one or more |
| 21 | // interfaces defined on it. |
| 22 | class Device : public base::RefCounted<Device>, |
| 23 | public org::chromium::apmanager::DeviceAdaptor, |
| 24 | public org::chromium::apmanager::DeviceInterface { |
| 25 | public: |
| 26 | struct WiFiInterface { |
| 27 | WiFiInterface() : iface_index(0), iface_type(0) {} |
| 28 | WiFiInterface(const std::string& in_iface_name, |
| 29 | const std::string& in_device_name, |
| 30 | uint32_t in_iface_index, |
| 31 | uint32_t in_iface_type) |
| 32 | : iface_name(in_iface_name), |
| 33 | device_name(in_device_name), |
| 34 | iface_index(in_iface_index), |
| 35 | iface_type(in_iface_type) {} |
| 36 | std::string iface_name; |
| 37 | std::string device_name; |
| 38 | uint32_t iface_index; |
| 39 | uint32_t iface_type; |
| 40 | bool Equals(const WiFiInterface& other) const { |
| 41 | return this->iface_name == other.iface_name && |
| 42 | this->device_name == other.device_name && |
| 43 | this->iface_index == other.iface_index && |
| 44 | this->iface_type == other.iface_type; |
| 45 | } |
| 46 | }; |
| 47 | |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame^] | 48 | explicit Device(const std::string& device_name); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 49 | virtual ~Device(); |
| 50 | |
| 51 | // Register Device DBus object. |
| 52 | void RegisterAsync( |
| 53 | chromeos::dbus_utils::ExportedObjectManager* object_manager, |
| 54 | chromeos::dbus_utils::AsyncEventSequencer* sequencer, |
| 55 | int device_identifier); |
| 56 | |
| 57 | // Register/deregister WiFi interface on this device. |
| 58 | virtual void RegisterInterface(const WiFiInterface& interface); |
| 59 | virtual void DeregisterInterface(const WiFiInterface& interface); |
| 60 | |
Peter Qiu | 1ff67a7 | 2014-11-22 07:06:10 -0800 | [diff] [blame^] | 61 | // Parse device capability from NL80211 message. |
| 62 | void ParseWiphyCapability(const shill::Nl80211Message& msg); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 63 | |
| 64 | // Function for claiming/releasing ownership of this device. This will invoke |
| 65 | // dbus calls to shill to claim/release all the interfaces reside on this |
| 66 | // device. |
| 67 | virtual bool ClaimDevice(); |
| 68 | virtual bool ReleaseDevice(); |
| 69 | |
| 70 | // Return true if interface with |interface_name| resides on this device, |
| 71 | // false otherwise. |
| 72 | virtual bool InterfaceExists(const std::string& interface_name); |
| 73 | |
| 74 | private: |
| 75 | friend class DeviceTest; |
| 76 | |
| 77 | // Determine preferred interface to used for AP operation based on the list |
| 78 | // of interfaces reside on this device |
| 79 | void UpdatePreferredAPInterface(); |
| 80 | |
| 81 | // List of WiFi interfaces live on this device (PHY). |
| 82 | std::vector<WiFiInterface> interface_list_; |
| 83 | |
| 84 | dbus::ObjectPath dbus_path_; |
| 85 | std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_; |
| 86 | |
| 87 | DISALLOW_COPY_AND_ASSIGN(Device); |
| 88 | }; |
| 89 | |
| 90 | } // namespace apmanager |
| 91 | |
| 92 | #endif // APMANAGER_DEVICE_H_ |