Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -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 "shill/cellular.h" |
| 6 | |
| 7 | #include <string> |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 8 | #include <utility> |
| 9 | #include <vector> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/logging.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | |
| 14 | #include "shill/cellular_service.h" |
| 15 | #include "shill/control_interface.h" |
| 16 | #include "shill/device.h" |
| 17 | #include "shill/device_info.h" |
| 18 | #include "shill/manager.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 19 | #include "shill/profile.h" |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 20 | #include "shill/property_accessor.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 21 | #include "shill/shill_event.h" |
| 22 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 23 | using std::make_pair; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 24 | using std::string; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 25 | using std::vector; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | |
| 27 | namespace shill { |
| 28 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 29 | Cellular::Network::Network() { |
| 30 | dict_[flimflam::kStatusProperty] = ""; |
| 31 | dict_[flimflam::kNetworkIdProperty] = ""; |
| 32 | dict_[flimflam::kShortNameProperty] = ""; |
| 33 | dict_[flimflam::kLongNameProperty] = ""; |
| 34 | dict_[flimflam::kTechnologyProperty] = ""; |
| 35 | } |
| 36 | |
| 37 | Cellular::Network::~Network() {} |
| 38 | |
| 39 | const std::string &Cellular::Network::GetStatus() const { |
| 40 | return dict_.find(flimflam::kStatusProperty)->second; |
| 41 | } |
| 42 | |
| 43 | void Cellular::Network::SetStatus(const std::string &status) { |
| 44 | dict_[flimflam::kStatusProperty] = status; |
| 45 | } |
| 46 | |
| 47 | const std::string &Cellular::Network::GetId() const { |
| 48 | return dict_.find(flimflam::kNetworkIdProperty)->second; |
| 49 | } |
| 50 | |
| 51 | void Cellular::Network::SetId(const std::string &id) { |
| 52 | dict_[flimflam::kNetworkIdProperty] = id; |
| 53 | } |
| 54 | |
| 55 | const std::string &Cellular::Network::GetShortName() const { |
| 56 | return dict_.find(flimflam::kShortNameProperty)->second; |
| 57 | } |
| 58 | |
| 59 | void Cellular::Network::SetShortName(const std::string &name) { |
| 60 | dict_[flimflam::kShortNameProperty] = name; |
| 61 | } |
| 62 | |
| 63 | const std::string &Cellular::Network::GetLongName() const { |
| 64 | return dict_.find(flimflam::kLongNameProperty)->second; |
| 65 | } |
| 66 | |
| 67 | void Cellular::Network::SetLongName(const std::string &name) { |
| 68 | dict_[flimflam::kLongNameProperty] = name; |
| 69 | } |
| 70 | |
| 71 | const std::string &Cellular::Network::GetTechnology() const { |
| 72 | return dict_.find(flimflam::kTechnologyProperty)->second; |
| 73 | } |
| 74 | |
| 75 | void Cellular::Network::SetTechnology(const std::string &technology) { |
| 76 | dict_[flimflam::kTechnologyProperty] = technology; |
| 77 | } |
| 78 | |
| 79 | const Stringmap &Cellular::Network::ToDict() const { |
| 80 | return dict_; |
| 81 | } |
| 82 | |
| 83 | Cellular::SimLockStatus::SimLockStatus() {} |
| 84 | |
| 85 | Cellular::SimLockStatus::~SimLockStatus() {} |
| 86 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 87 | Cellular::Cellular(ControlInterface *control_interface, |
| 88 | EventDispatcher *dispatcher, |
| 89 | Manager *manager, |
| 90 | const string &link, |
| 91 | int interface_index) |
| 92 | : Device(control_interface, |
| 93 | dispatcher, |
| 94 | manager, |
| 95 | link, |
| 96 | interface_index), |
| 97 | service_(new CellularService(control_interface, |
| 98 | dispatcher, |
| 99 | this, |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 100 | manager->ActiveProfile(), |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 101 | "service-" + link_name())), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 102 | service_registered_(false) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 103 | store_.RegisterConstString(flimflam::kCarrierProperty, &carrier_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 104 | store_.RegisterBool(flimflam::kCellularAllowRoamingProperty, &allow_roaming_); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 105 | store_.RegisterConstString(flimflam::kEsnProperty, &esn_); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 106 | store_.RegisterConstString(flimflam::kFirmwareRevisionProperty, |
| 107 | &firmware_revision_); |
| 108 | store_.RegisterConstString(flimflam::kHardwareRevisionProperty, |
| 109 | &hardware_revision_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 110 | store_.RegisterConstString(flimflam::kImeiProperty, &imei_); |
| 111 | store_.RegisterConstString(flimflam::kImsiProperty, &imsi_); |
| 112 | store_.RegisterConstString(flimflam::kManufacturerProperty, &manufacturer_); |
| 113 | store_.RegisterConstString(flimflam::kMdnProperty, &mdn_); |
| 114 | store_.RegisterConstString(flimflam::kMeidProperty, &meid_); |
| 115 | store_.RegisterConstString(flimflam::kMinProperty, &min_); |
| 116 | store_.RegisterConstString(flimflam::kModelIDProperty, &model_id_); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 117 | store_.RegisterConstInt16(flimflam::kPRLVersionProperty, &prl_version_); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 118 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 119 | HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty, |
| 120 | &Cellular::SimLockStatusToProperty, |
| 121 | NULL); |
| 122 | HelpRegisterDerivedStringmaps(flimflam::kFoundNetworksProperty, |
| 123 | &Cellular::EnumerateNetworks, |
| 124 | NULL); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 125 | |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 126 | store_.RegisterConstBool(flimflam::kScanningProperty, &scanning_); |
| 127 | store_.RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_); |
| 128 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 129 | VLOG(2) << "Cellular device " << link_name() << " initialized."; |
| 130 | } |
| 131 | |
| 132 | Cellular::~Cellular() { |
| 133 | Stop(); |
| 134 | } |
| 135 | |
| 136 | void Cellular::Start() { |
| 137 | Device::Start(); |
| 138 | } |
| 139 | |
| 140 | void Cellular::Stop() { |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 141 | manager_->DeregisterService(service_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 142 | Device::Stop(); |
| 143 | } |
| 144 | |
| 145 | bool Cellular::TechnologyIs(const Device::Technology type) { |
| 146 | return type == Device::kCellular; |
| 147 | } |
| 148 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 149 | Stringmaps Cellular::EnumerateNetworks() { |
| 150 | Stringmaps to_return; |
| 151 | for (vector<Network>::const_iterator it = found_networks_.begin(); |
| 152 | it != found_networks_.end(); |
| 153 | ++it) { |
| 154 | to_return.push_back(it->ToDict()); |
| 155 | } |
| 156 | return to_return; |
| 157 | } |
| 158 | |
| 159 | StrIntPair Cellular::SimLockStatusToProperty() { |
| 160 | return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty, |
| 161 | sim_lock_status_.lock_type), |
| 162 | make_pair(flimflam::kSIMLockRetriesLeftProperty, |
| 163 | sim_lock_status_.retries_left)); |
| 164 | } |
| 165 | |
| 166 | void Cellular::HelpRegisterDerivedStringmaps( |
| 167 | const string &name, |
| 168 | Stringmaps(Cellular::*get)(void), |
| 169 | bool(Cellular::*set)(const Stringmaps&)) { |
| 170 | store_.RegisterDerivedStringmaps( |
| 171 | name, |
| 172 | StringmapsAccessor( |
| 173 | new CustomAccessor<Cellular, Stringmaps>(this, get, set))); |
| 174 | } |
| 175 | |
| 176 | void Cellular::HelpRegisterDerivedStrIntPair( |
| 177 | const string &name, |
| 178 | StrIntPair(Cellular::*get)(void), |
| 179 | bool(Cellular::*set)(const StrIntPair&)) { |
| 180 | store_.RegisterDerivedStrIntPair( |
| 181 | name, |
| 182 | StrIntPairAccessor( |
| 183 | new CustomAccessor<Cellular, StrIntPair>(this, get, set))); |
| 184 | } |
| 185 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 186 | } // namespace shill |