blob: 36be3480856b95f3f4ca68ba96a765fdaa819397 [file] [log] [blame]
Peter Qiufb39ba42014-11-21 09:09:59 -08001// 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 Qiu0ca183b2015-03-09 13:41:06 -07008#include <set>
Peter Qiufb39ba42014-11-21 09:09:59 -08009#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
19namespace apmanager {
20
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080021class Manager;
22
Peter Qiufb39ba42014-11-21 09:09:59 -080023// Abstraction for WiFi Device (PHY). Each device can have one or more
24// interfaces defined on it.
25class 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 Qiu8e785b92014-11-24 10:01:08 -080051 struct BandCapability {
52 std::vector<uint32_t> frequencies;
53 uint16_t ht_capability_mask;
54 uint16_t vht_capability_mask;
55 };
56
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080057 Device(Manager* manager, const std::string& device_name);
Peter Qiufb39ba42014-11-21 09:09:59 -080058 virtual ~Device();
59
60 // Register Device DBus object.
61 void RegisterAsync(
62 chromeos::dbus_utils::ExportedObjectManager* object_manager,
Peter Qiuc9ce1f12014-12-05 11:14:29 -080063 const scoped_refptr<dbus::Bus>& bus,
Peter Qiufb39ba42014-11-21 09:09:59 -080064 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 Qiu1ff67a72014-11-22 07:06:10 -080071 // Parse device capability from NL80211 message.
72 void ParseWiphyCapability(const shill::Nl80211Message& msg);
Peter Qiufb39ba42014-11-21 09:09:59 -080073
Peter Qiu0ca183b2015-03-09 13:41:06 -070074 // 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 Qiufb39ba42014-11-21 09:09:59 -080080 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 Qiu8e785b92014-11-24 10:01:08 -080086 // 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 Qiufb39ba42014-11-21 09:09:59 -080092 private:
93 friend class DeviceTest;
94
Peter Qiu8e785b92014-11-24 10:01:08 -080095 // 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 Qiufb39ba42014-11-21 09:09:59 -0800100 // Determine preferred interface to used for AP operation based on the list
101 // of interfaces reside on this device
102 void UpdatePreferredAPInterface();
103
Peter Qiu8e785b92014-11-24 10:01:08 -0800104 // 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 Qiu7e0ffcf2014-12-02 12:53:27 -0800109 Manager* manager_;
110
Peter Qiufb39ba42014-11-21 09:09:59 -0800111 // 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 Qiu3d95ac72014-12-06 18:26:18 -0800117 // Flag indicating if this device supports AP mode interface or not.
118 bool supports_ap_mode_;
119
Peter Qiu8e785b92014-11-24 10:01:08 -0800120 // Wiphy band capabilities.
121 std::vector<BandCapability> band_capability_;
122
Peter Qiu0ca183b2015-03-09 13:41:06 -0700123 // List of claimed interfaces.
124 std::set<std::string> claimed_interfaces_;
125
Peter Qiufb39ba42014-11-21 09:09:59 -0800126 DISALLOW_COPY_AND_ASSIGN(Device);
127};
128
129} // namespace apmanager
130
131#endif // APMANAGER_DEVICE_H_