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