blob: 20240ab359d9fd83ee82790c7c93c1254c5de3c9 [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
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
18namespace apmanager {
19
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080020class Manager;
21
Peter Qiufb39ba42014-11-21 09:09:59 -080022// Abstraction for WiFi Device (PHY). Each device can have one or more
23// interfaces defined on it.
24class 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 Qiu8e785b92014-11-24 10:01:08 -080050 struct BandCapability {
51 std::vector<uint32_t> frequencies;
52 uint16_t ht_capability_mask;
53 uint16_t vht_capability_mask;
54 };
55
Peter Qiu7e0ffcf2014-12-02 12:53:27 -080056 Device(Manager* manager, const std::string& device_name);
Peter Qiufb39ba42014-11-21 09:09:59 -080057 virtual ~Device();
58
59 // Register Device DBus object.
60 void RegisterAsync(
61 chromeos::dbus_utils::ExportedObjectManager* object_manager,
Peter Qiuc9ce1f12014-12-05 11:14:29 -080062 const scoped_refptr<dbus::Bus>& bus,
Peter Qiufb39ba42014-11-21 09:09:59 -080063 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 Qiu1ff67a72014-11-22 07:06:10 -080070 // Parse device capability from NL80211 message.
71 void ParseWiphyCapability(const shill::Nl80211Message& msg);
Peter Qiufb39ba42014-11-21 09:09:59 -080072
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 Qiu8e785b92014-11-24 10:01:08 -080083 // 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 Qiufb39ba42014-11-21 09:09:59 -080089 private:
90 friend class DeviceTest;
91
Peter Qiu8e785b92014-11-24 10:01:08 -080092 // 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 Qiufb39ba42014-11-21 09:09:59 -080097 // Determine preferred interface to used for AP operation based on the list
98 // of interfaces reside on this device
99 void UpdatePreferredAPInterface();
100
Peter Qiu8e785b92014-11-24 10:01:08 -0800101 // 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 Qiu7e0ffcf2014-12-02 12:53:27 -0800106 Manager* manager_;
107
Peter Qiufb39ba42014-11-21 09:09:59 -0800108 // 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 Qiu3d95ac72014-12-06 18:26:18 -0800114 // Flag indicating if this device supports AP mode interface or not.
115 bool supports_ap_mode_;
116
Peter Qiu8e785b92014-11-24 10:01:08 -0800117 // Wiphy band capabilities.
118 std::vector<BandCapability> band_capability_;
119
Peter Qiufb39ba42014-11-21 09:09:59 -0800120 DISALLOW_COPY_AND_ASSIGN(Device);
121};
122
123} // namespace apmanager
124
125#endif // APMANAGER_DEVICE_H_