blob: 9aab0f05951d9d485c998f7ff8d16c552cb8c28f [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// Copyright (c) 2011 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#include <time.h>
Paul Stewart75897df2011-04-27 09:05:53 -07006#include <stdio.h>
Chris Masoneee929b72011-05-10 10:02:18 -07007
Paul Stewart75897df2011-04-27 09:05:53 -07008#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -07009#include <vector>
Paul Stewart75897df2011-04-27 09:05:53 -070010
Chris Masoneee929b72011-05-10 10:02:18 -070011#include <base/logging.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070012#include <base/memory/ref_counted.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013#include <chromeos/dbus/service_constants.h>
Chris Masoneee929b72011-05-10 10:02:18 -070014
Paul Stewart75897df2011-04-27 09:05:53 -070015#include "shill/control_interface.h"
16#include "shill/device.h"
Chris Masoned7732e42011-05-20 11:08:56 -070017#include "shill/device_dbus_adaptor.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070018#include "shill/dhcp_provider.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070019#include "shill/error.h"
20#include "shill/manager.h"
Chris Masone0e1d1042011-05-09 18:07:03 -070021#include "shill/shill_event.h"
Paul Stewart75897df2011-04-27 09:05:53 -070022
Chris Masone8fe2c7e2011-06-09 15:51:19 -070023using std::string;
24using std::vector;
25
Paul Stewart75897df2011-04-27 09:05:53 -070026namespace shill {
27Device::Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070028 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070029 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070030 const string &link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070031 int interface_index)
Darin Petkovafa6fc42011-06-21 16:21:08 -070032 : manager_(manager),
33 link_name_(link_name),
Paul Stewartf1ce5d22011-05-19 13:10:20 -070034 adaptor_(control_interface->CreateDeviceAdaptor(this)),
35 interface_index_(interface_index),
36 running_(false) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070037 known_properties_.push_back(flimflam::kNameProperty);
38 known_properties_.push_back(flimflam::kTypeProperty);
39 known_properties_.push_back(flimflam::kPoweredProperty);
40 known_properties_.push_back(flimflam::kScanningProperty);
41 // known_properties_.push_back(flimflam::kReconnectProperty);
42 known_properties_.push_back(flimflam::kScanIntervalProperty);
43 known_properties_.push_back(flimflam::kBgscanMethodProperty);
44 known_properties_.push_back(flimflam::kBgscanShortIntervalProperty);
45 known_properties_.push_back(flimflam::kBgscanSignalThresholdProperty);
46 known_properties_.push_back(flimflam::kNetworksProperty);
47 known_properties_.push_back(flimflam::kIPConfigsProperty);
48 known_properties_.push_back(flimflam::kCellularAllowRoamingProperty);
49 known_properties_.push_back(flimflam::kCarrierProperty);
50 known_properties_.push_back(flimflam::kMeidProperty);
51 known_properties_.push_back(flimflam::kImeiProperty);
52 known_properties_.push_back(flimflam::kImsiProperty);
53 known_properties_.push_back(flimflam::kEsnProperty);
54 known_properties_.push_back(flimflam::kMdnProperty);
55 known_properties_.push_back(flimflam::kModelIDProperty);
56 known_properties_.push_back(flimflam::kManufacturerProperty);
57 known_properties_.push_back(flimflam::kFirmwareRevisionProperty);
58 known_properties_.push_back(flimflam::kHardwareRevisionProperty);
59 known_properties_.push_back(flimflam::kPRLVersionProperty);
60 known_properties_.push_back(flimflam::kSIMLockStatusProperty);
61 known_properties_.push_back(flimflam::kFoundNetworksProperty);
62 known_properties_.push_back(flimflam::kDBusConnectionProperty);
63 known_properties_.push_back(flimflam::kDBusObjectProperty);
Chris Masoneee929b72011-05-10 10:02:18 -070064 // Initialize Interface monitor, so we can detect new interfaces
Paul Stewartb50f0b92011-05-16 16:31:42 -070065 VLOG(2) << "Device " << link_name_ << " index " << interface_index;
Paul Stewart75897df2011-04-27 09:05:53 -070066}
67
68Device::~Device() {
Paul Stewartb50f0b92011-05-16 16:31:42 -070069 VLOG(2) << "Device " << link_name_ << " destroyed.";
Paul Stewart75897df2011-04-27 09:05:53 -070070}
71
72void Device::Start() {
73 running_ = true;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070074 VLOG(2) << "Device " << link_name_ << " starting.";
Chris Masone413a3192011-05-09 17:10:05 -070075 adaptor_->UpdateEnabled();
Paul Stewart75897df2011-04-27 09:05:53 -070076}
77
78void Device::Stop() {
79 running_ = false;
Chris Masone413a3192011-05-09 17:10:05 -070080 adaptor_->UpdateEnabled();
Paul Stewart75897df2011-04-27 09:05:53 -070081}
82
Darin Petkovafa6fc42011-06-21 16:21:08 -070083bool Device::TechnologyIs(const Technology type) {
84 return false;
85}
86
Paul Stewartf1ce5d22011-05-19 13:10:20 -070087void Device::LinkEvent(unsigned flags, unsigned change) {
88 VLOG(2) << "Device " << link_name_ << " flags " << flags << " changed "
89 << change;
90}
91
92void Device::Scan() {
93 VLOG(2) << "Device " << link_name_ << " scan requested.";
94}
95
Chris Masone3bd3c8c2011-06-13 08:20:26 -070096bool Device::Contains(const std::string &property) {
97 vector<string>::iterator it;
98 for (it = known_properties_.begin(); it != known_properties_.end(); ++it) {
99 if (property == *it)
100 return true;
101 }
102 return false;
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700103}
104
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700105bool Device::SetBoolProperty(const string& name, bool value, Error *error) {
106 VLOG(2) << "Setting " << name << " as a bool.";
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700107 // TODO(cmasone): Set actual properties.
108 return true;
109}
110
111bool Device::SetInt32Property(const std::string& name,
112 int32 value,
113 Error *error) {
114 VLOG(2) << "Setting " << name << " as an int32.";
115 // TODO(cmasone): Set actual properties.
116 return true;
117}
118
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700119bool Device::SetUint16Property(const std::string& name,
120 uint16 value,
121 Error *error) {
122 VLOG(2) << "Setting " << name << " as a uint16.";
123 // TODO(cmasone): Set actual properties.
124 return true;
125}
126
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700127const string& Device::UniqueName() const {
128 // TODO(pstew): link_name is only run-time unique and won't persist
Darin Petkovafa6fc42011-06-21 16:21:08 -0700129 return link_name();
130}
131
132void Device::DestroyIPConfig() {
133 if (ipconfig_.get()) {
134 ipconfig_->ReleaseIP();
135 ipconfig_ = NULL;
136 }
137}
138
139bool Device::AcquireDHCPConfig() {
140 DestroyIPConfig();
141 ipconfig_ = DHCPProvider::GetInstance()->CreateConfig(link_name());
142 ipconfig_->RegisterUpdateCallback(
143 NewCallback(this, &Device::IPConfigUpdatedCallback));
144 return ipconfig_->RequestIP();
145}
146
147void Device::IPConfigUpdatedCallback(IPConfigRefPtr ipconfig, bool success) {
148 // TODO(petkov): Use DeviceInfo to configure IP, etc. -- maybe through
149 // ConfigIP? Also, maybe allow forwarding the callback to interested listeners
150 // (e.g., the Manager).
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700151}
152
Paul Stewart75897df2011-04-27 09:05:53 -0700153} // namespace shill