cellular_capability.cc revision 7fce52c4afdc5e73a9e740dc9b90f1e61ae8cea4
15de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov// Use of this source code is governed by a BSD-style license that can be
3daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov// found in the LICENSE file.
4daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
5daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov#include "shill/cellular_capability.h"
6daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
79a24553461df7036755060423f90804011612249Eric Shienbrood#include <base/bind.h>
85de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood#include <chromeos/dbus/service_constants.h>
95de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood
10daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov#include "shill/cellular.h"
11b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov#include "shill/error.h"
129c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov#include "shill/property_accessor.h"
13fad4a0b7e55dd82d3815ee96862b6e546727eb6eBen Chan#include "shill/scope_logger.h"
14b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov
153e20a2341d0aeb7681e4ee0f89eae6817ade2b3bEric Shienbroodusing base::Closure;
16b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkovusing std::string;
17daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
18daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkovnamespace shill {
19daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
207fce52c4afdc5e73a9e740dc9b90f1e61ae8cea4Eric Shienbroodconst char CellularCapability::kModemPropertyIMSI[] = "imsi";
217fce52c4afdc5e73a9e740dc9b90f1e61ae8cea4Eric Shienbroodconst char CellularCapability::kModemPropertyState[] = "State";
229a24553461df7036755060423f90804011612249Eric Shienbrood// All timeout values are in milliseconds
239a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutActivate = 120000;
249a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutConnect = 45000;
259a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutDefault = 5000;
269a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutEnable = 15000;
279a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutRegister = 90000;
289a24553461df7036755060423f90804011612249Eric Shienbroodconst int CellularCapability::kTimeoutScan = 120000;
295de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood
305de44ab664b7cbb7619e31431e346ec8309548a6Eric ShienbroodCellularCapability::CellularCapability(Cellular *cellular,
315de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood                                       ProxyFactory *proxy_factory)
3282f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow    : cellular_(cellular),
339a24553461df7036755060423f90804011612249Eric Shienbrood      proxy_factory_(proxy_factory),
3482f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow      allow_roaming_(false) {
359c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  HelpRegisterDerivedBool(flimflam::kCellularAllowRoamingProperty,
369c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov                          &CellularCapability::GetAllowRoaming,
379c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov                          &CellularCapability::SetAllowRoaming);
385de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood}
39daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
40daf4386a4775be7c965493749ccfe2fecc2e4167Darin PetkovCellularCapability::~CellularCapability() {}
41daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov
429c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkovvoid CellularCapability::HelpRegisterDerivedBool(
439c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    const string &name,
449c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    bool(CellularCapability::*get)(Error *error),
459c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    void(CellularCapability::*set)(const bool &value, Error *error)) {
469c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  cellular()->mutable_store()->RegisterDerivedBool(
479c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov      name,
489c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov      BoolAccessor(
499c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov          new CustomAccessor<CellularCapability, bool>(this, get, set)));
509c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov}
519c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov
529c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkovvoid CellularCapability::SetAllowRoaming(const bool &value, Error */*error*/) {
53fad4a0b7e55dd82d3815ee96862b6e546727eb6eBen Chan  SLOG(Cellular, 2) << __func__
54fad4a0b7e55dd82d3815ee96862b6e546727eb6eBen Chan                    << "(" << allow_roaming_ << "->" << value << ")";
559c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  if (allow_roaming_ == value) {
569c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    return;
579c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  }
589c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  allow_roaming_ = value;
5982f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow  // Use AllowRoaming() instead of allow_roaming_ in order to
6082f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow  // incorporate provider preferences when evaluating if a disconnect
6182f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow  // is required.
6282f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow  if (!AllowRoaming() &&
6382f9ab3f404c8f414348c6effdc57c4d3b9223d7Jason Glasgow      GetRoamingStateString() == flimflam::kRoamingStateRoaming) {
649c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    Error error;
659c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov    cellular()->Disconnect(&error);
669c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  }
679c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov  cellular()->adaptor()->EmitBoolChanged(
689c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov      flimflam::kCellularAllowRoamingProperty, value);
699c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov}
709c1dcef1a5a21057392874bd511b5c577c35634aDarin Petkov
719a24553461df7036755060423f90804011612249Eric Shienbroodvoid CellularCapability::RunNextStep(CellularTaskList *tasks) {
729a24553461df7036755060423f90804011612249Eric Shienbrood  CHECK(!tasks->empty());
73fad4a0b7e55dd82d3815ee96862b6e546727eb6eBen Chan  SLOG(Cellular, 2) << __func__ << ": " << tasks->size() << " remaining tasks";
749a24553461df7036755060423f90804011612249Eric Shienbrood  Closure task = (*tasks)[0];
759a24553461df7036755060423f90804011612249Eric Shienbrood  tasks->erase(tasks->begin());
769a24553461df7036755060423f90804011612249Eric Shienbrood  cellular()->dispatcher()->PostTask(task);
779a24553461df7036755060423f90804011612249Eric Shienbrood}
789a24553461df7036755060423f90804011612249Eric Shienbrood
799a24553461df7036755060423f90804011612249Eric Shienbroodvoid CellularCapability::StepCompletedCallback(
809a24553461df7036755060423f90804011612249Eric Shienbrood    const ResultCallback &callback,
81923006bc5f3fde53ea8651de16200d7226f065a2Thieu Le    bool ignore_error,
829a24553461df7036755060423f90804011612249Eric Shienbrood    CellularTaskList *tasks,
839a24553461df7036755060423f90804011612249Eric Shienbrood    const Error &error) {
84923006bc5f3fde53ea8651de16200d7226f065a2Thieu Le  if ((ignore_error || error.IsSuccess()) && !tasks->empty()) {
859a24553461df7036755060423f90804011612249Eric Shienbrood    RunNextStep(tasks);
869a24553461df7036755060423f90804011612249Eric Shienbrood    return;
879a24553461df7036755060423f90804011612249Eric Shienbrood  }
889a24553461df7036755060423f90804011612249Eric Shienbrood  delete tasks;
899a24553461df7036755060423f90804011612249Eric Shienbrood  callback.Run(error);
909a24553461df7036755060423f90804011612249Eric Shienbrood}
919a24553461df7036755060423f90804011612249Eric Shienbrood
925de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbroodvoid CellularCapability::OnUnsupportedOperation(
935de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood    const char *operation,
949a24553461df7036755060423f90804011612249Eric Shienbrood    Error *error) {
955de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood  string message("The ");
965de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood  message.append(operation).append(" operation is not supported.");
979a24553461df7036755060423f90804011612249Eric Shienbrood  Error::PopulateAndLog(error, Error::kNotSupported, message);
985de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood}
995de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood
100184c54e6091b21fc2a8ba40d8957ca6c84c37d6eDarin Petkovvoid CellularCapability::RegisterOnNetwork(
1019a24553461df7036755060423f90804011612249Eric Shienbrood    const string &/*network_id*/,
1029a24553461df7036755060423f90804011612249Eric Shienbrood    Error *error, const ResultCallback &/*callback*/) {
1039a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
104184c54e6091b21fc2a8ba40d8957ca6c84c37d6eDarin Petkov}
105184c54e6091b21fc2a8ba40d8957ca6c84c37d6eDarin Petkov
1069a24553461df7036755060423f90804011612249Eric Shienbroodvoid CellularCapability::RequirePIN(const std::string &/*pin*/,
1079a24553461df7036755060423f90804011612249Eric Shienbrood                                    bool /*require*/,
1089a24553461df7036755060423f90804011612249Eric Shienbrood                                    Error *error,
1099a24553461df7036755060423f90804011612249Eric Shienbrood                                    const ResultCallback &/*callback*/) {
1109a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
111b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov}
112b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov
113e5bc2cbc1c9717564d4ab75c42a26492b505f537Darin Petkovvoid CellularCapability::EnterPIN(const string &/*pin*/,
1149a24553461df7036755060423f90804011612249Eric Shienbrood                                  Error *error,
1159a24553461df7036755060423f90804011612249Eric Shienbrood                                  const ResultCallback &/*callback*/) {
1169a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
117b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov}
118b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov
119b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkovvoid CellularCapability::UnblockPIN(const string &/*unblock_code*/,
120b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov                                    const string &/*pin*/,
1219a24553461df7036755060423f90804011612249Eric Shienbrood                                    Error *error,
1229a24553461df7036755060423f90804011612249Eric Shienbrood                                    const ResultCallback &/*callback*/) {
1239a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
124b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov}
125b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov
126b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkovvoid CellularCapability::ChangePIN(const string &/*old_pin*/,
127b05315fa7beab387bcbfd9330215aa50cdd6c8f4Darin Petkov                                   const string &/*new_pin*/,
1289a24553461df7036755060423f90804011612249Eric Shienbrood                                   Error *error,
1299a24553461df7036755060423f90804011612249Eric Shienbrood                                   const ResultCallback &/*callback*/) {
1309a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
1315de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood}
1325de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood
1339a24553461df7036755060423f90804011612249Eric Shienbroodvoid CellularCapability::Scan(Error *error,
1349a24553461df7036755060423f90804011612249Eric Shienbrood                              const ResultCallback &callback) {
1359a24553461df7036755060423f90804011612249Eric Shienbrood  OnUnsupportedOperation(__func__, error);
1365de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood}
1375de44ab664b7cbb7619e31431e346ec8309548a6Eric Shienbrood
138daf4386a4775be7c965493749ccfe2fecc2e4167Darin Petkov}  // namespace shill
139