Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 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/modem_info.h" |
| 6 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 7 | #include <base/file_path.h> |
Darin Petkov | 75f201f | 2013-03-19 13:01:28 +0100 | [diff] [blame] | 8 | |
| 9 | #if !defined(DISABLE_CELLULAR) |
| 10 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 11 | #include <mm/mm-modem.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 12 | #include <mobile_provider.h> |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 13 | |
Darin Petkov | 75f201f | 2013-03-19 13:01:28 +0100 | [diff] [blame] | 14 | #endif // DISABLE_CELLULAR |
| 15 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 16 | #include "shill/cellular_operator_info.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 17 | #include "shill/logging.h" |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 18 | #include "shill/manager.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 19 | #include "shill/modem_manager.h" |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 20 | #include "shill/pending_activation_store.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 21 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 22 | using base::FilePath; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 23 | using std::string; |
| 24 | |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 25 | // TODO(rochberg): Fix modemmanager-next-interfaces ebuild to include |
| 26 | // these so that we can simply include ModemManager.h and use these |
| 27 | // defines |
| 28 | #define MM_DBUS_PATH "/org/freedesktop/ModemManager1" |
| 29 | #define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" |
| 30 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 31 | namespace shill { |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | const char kCromoService[] = "org.chromium.ModemManager"; |
| 36 | const char kCromoPath[] = "/org/chromium/ModemManager"; |
| 37 | |
| 38 | const char kCellularOperatorInfoPath[] = |
| 39 | "/usr/share/shill/cellular_operator_info"; |
| 40 | const char kMobileProviderDBPath[] = |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 41 | "/usr/share/mobile-broadband-provider-info/serviceproviders.bfd"; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 42 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 43 | } // namespace |
| 44 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 45 | ModemInfo::ModemInfo(ControlInterface *control_interface, |
| 46 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 47 | Metrics *metrics, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 48 | Manager *manager, |
| 49 | GLib *glib) |
| 50 | : control_interface_(control_interface), |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 51 | dispatcher_(dispatcher), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 52 | metrics_(metrics), |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 53 | manager_(manager), |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 54 | glib_(glib), |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 55 | pending_activation_store_(NULL), |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 56 | provider_db_path_(kMobileProviderDBPath), |
| 57 | provider_db_(NULL) {} |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 58 | |
| 59 | ModemInfo::~ModemInfo() { |
| 60 | Stop(); |
| 61 | } |
| 62 | |
Darin Petkov | 75f201f | 2013-03-19 13:01:28 +0100 | [diff] [blame] | 63 | #if defined(DISABLE_CELLULAR) |
| 64 | |
| 65 | void ModemInfo::Start() {} |
| 66 | void ModemInfo::Stop() {} |
| 67 | void ModemInfo::OnDeviceInfoAvailable(const string &link_name) { |
Darin Petkov | bd9f33a | 2013-03-20 10:38:07 +0100 | [diff] [blame] | 68 | NOTIMPLEMENTED(); |
Darin Petkov | 75f201f | 2013-03-19 13:01:28 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | #else |
| 72 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 73 | void ModemInfo::Start() { |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 74 | pending_activation_store_.reset(new PendingActivationStore()); |
| 75 | pending_activation_store_->InitStorage(manager_->glib(), |
Prathmesh Prabhu | 97f317c | 2013-03-15 16:20:34 -0700 | [diff] [blame] | 76 | manager_->storage_path()); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 77 | cellular_operator_info_.reset(new CellularOperatorInfo()); |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 78 | cellular_operator_info_->Load(FilePath(kCellularOperatorInfoPath)); |
| 79 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 80 | // TODO(petkov): Consider initializing the mobile provider database lazily |
| 81 | // only if a GSM modem needs to be registered. |
| 82 | provider_db_ = mobile_provider_open_db(provider_db_path_.c_str()); |
| 83 | PLOG_IF(WARNING, !provider_db_) |
| 84 | << "Unable to load mobile provider database: "; |
Ben Chan | 8799a4a | 2013-04-13 16:00:13 -0700 | [diff] [blame] | 85 | RegisterModemManager( |
| 86 | new ModemManagerClassic(kCromoService, kCromoPath, this)); |
| 87 | RegisterModemManager(new ModemManager1(MM_DBUS_SERVICE, MM_DBUS_PATH, this)); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void ModemInfo::Stop() { |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 91 | pending_activation_store_.reset(); |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 92 | cellular_operator_info_.reset(); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 93 | if(provider_db_) |
| 94 | mobile_provider_close_db(provider_db_); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 95 | provider_db_ = NULL; |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 96 | modem_managers_.clear(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 99 | void ModemInfo::OnDeviceInfoAvailable(const string &link_name) { |
| 100 | for (ModemManagers::iterator it = modem_managers_.begin(); |
| 101 | it != modem_managers_.end(); ++it) { |
| 102 | (*it)->OnDeviceInfoAvailable(link_name); |
| 103 | } |
| 104 | } |
| 105 | |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 106 | void ModemInfo::set_pending_activation_store( |
| 107 | PendingActivationStore *pending_activation_store) { |
| 108 | pending_activation_store_.reset(pending_activation_store); |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void ModemInfo::set_cellular_operator_info( |
| 112 | CellularOperatorInfo *cellular_operator_info) { |
| 113 | cellular_operator_info_.reset(cellular_operator_info); |
| 114 | } |
| 115 | |
Ben Chan | 8799a4a | 2013-04-13 16:00:13 -0700 | [diff] [blame] | 116 | void ModemInfo::RegisterModemManager(ModemManager *manager) { |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 117 | modem_managers_.push_back(manager); // Passes ownership. |
| 118 | manager->Start(); |
| 119 | } |
Darin Petkov | 75f201f | 2013-03-19 13:01:28 +0100 | [diff] [blame] | 120 | |
| 121 | #endif // DISABLE_CELLULAR |
| 122 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 123 | } // namespace shill |