Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1 | // 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 Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 6 | #include <stdio.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 7 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 8 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 9 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 10 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 14 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | #include "shill/control_interface.h" |
| 16 | #include "shill/device.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 17 | #include "shill/device_dbus_adaptor.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 18 | #include "shill/dhcp_provider.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 19 | #include "shill/error.h" |
| 20 | #include "shill/manager.h" |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 21 | #include "shill/shill_event.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 23 | using std::string; |
| 24 | using std::vector; |
| 25 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 26 | namespace shill { |
| 27 | Device::Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 28 | EventDispatcher *dispatcher, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 29 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 30 | const string &link_name, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 31 | int interface_index) |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 32 | : manager_(manager), |
| 33 | link_name_(link_name), |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 34 | adaptor_(control_interface->CreateDeviceAdaptor(this)), |
| 35 | interface_index_(interface_index), |
| 36 | running_(false) { |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 37 | 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 Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 64 | // Initialize Interface monitor, so we can detect new interfaces |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 65 | VLOG(2) << "Device " << link_name_ << " index " << interface_index; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | Device::~Device() { |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 69 | VLOG(2) << "Device " << link_name_ << " destroyed."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void Device::Start() { |
| 73 | running_ = true; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 74 | VLOG(2) << "Device " << link_name_ << " starting."; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 75 | adaptor_->UpdateEnabled(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void Device::Stop() { |
| 79 | running_ = false; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 80 | adaptor_->UpdateEnabled(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 83 | bool Device::TechnologyIs(const Technology type) { |
| 84 | return false; |
| 85 | } |
| 86 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 87 | void Device::LinkEvent(unsigned flags, unsigned change) { |
| 88 | VLOG(2) << "Device " << link_name_ << " flags " << flags << " changed " |
| 89 | << change; |
| 90 | } |
| 91 | |
| 92 | void Device::Scan() { |
| 93 | VLOG(2) << "Device " << link_name_ << " scan requested."; |
| 94 | } |
| 95 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 96 | bool 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 Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 105 | bool Device::SetBoolProperty(const string& name, bool value, Error *error) { |
| 106 | VLOG(2) << "Setting " << name << " as a bool."; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 107 | // TODO(cmasone): Set actual properties. |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | bool 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 Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 119 | bool 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 Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 127 | const string& Device::UniqueName() const { |
| 128 | // TODO(pstew): link_name is only run-time unique and won't persist |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 129 | return link_name(); |
| 130 | } |
| 131 | |
| 132 | void Device::DestroyIPConfig() { |
| 133 | if (ipconfig_.get()) { |
| 134 | ipconfig_->ReleaseIP(); |
| 135 | ipconfig_ = NULL; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | bool 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 | |
| 147 | void 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 Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 153 | } // namespace shill |