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 | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 8 | #include <mm/mm-modem.h> |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 9 | #include <mobile_provider.h> |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 10 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 11 | #include "shill/cellular_operator_info.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 12 | #include "shill/logging.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 13 | #include "shill/modem_manager.h" |
| 14 | |
| 15 | using std::string; |
| 16 | |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 17 | // TODO(rochberg): Fix modemmanager-next-interfaces ebuild to include |
| 18 | // these so that we can simply include ModemManager.h and use these |
| 19 | // defines |
| 20 | #define MM_DBUS_PATH "/org/freedesktop/ModemManager1" |
| 21 | #define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" |
| 22 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 23 | namespace shill { |
| 24 | |
| 25 | namespace { |
| 26 | |
| 27 | const char kCromoService[] = "org.chromium.ModemManager"; |
| 28 | const char kCromoPath[] = "/org/chromium/ModemManager"; |
| 29 | |
| 30 | const char kCellularOperatorInfoPath[] = |
| 31 | "/usr/share/shill/cellular_operator_info"; |
| 32 | const char kMobileProviderDBPath[] = |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 33 | "/usr/share/mobile-broadband-provider-info/serviceproviders.bfd"; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 34 | |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 35 | } // namespace |
| 36 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 37 | ModemInfo::ModemInfo(ControlInterface *control_interface, |
| 38 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 39 | Metrics *metrics, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 40 | Manager *manager, |
| 41 | GLib *glib) |
| 42 | : control_interface_(control_interface), |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 43 | dispatcher_(dispatcher), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 44 | metrics_(metrics), |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 45 | manager_(manager), |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 46 | glib_(glib), |
| 47 | provider_db_path_(kMobileProviderDBPath), |
| 48 | provider_db_(NULL) {} |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 49 | |
| 50 | ModemInfo::~ModemInfo() { |
| 51 | Stop(); |
| 52 | } |
| 53 | |
| 54 | void ModemInfo::Start() { |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 55 | cellular_operator_info_.reset(new CellularOperatorInfo()); |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 56 | cellular_operator_info_->Load(FilePath(kCellularOperatorInfoPath)); |
| 57 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 58 | // TODO(petkov): Consider initializing the mobile provider database lazily |
| 59 | // only if a GSM modem needs to be registered. |
| 60 | provider_db_ = mobile_provider_open_db(provider_db_path_.c_str()); |
| 61 | PLOG_IF(WARNING, !provider_db_) |
| 62 | << "Unable to load mobile provider database: "; |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 63 | RegisterModemManager<ModemManagerClassic>(MM_MODEMMANAGER_SERVICE, |
| 64 | MM_MODEMMANAGER_PATH); |
| 65 | RegisterModemManager<ModemManagerClassic>(kCromoService, kCromoPath); |
| 66 | RegisterModemManager<ModemManager1>(MM_DBUS_SERVICE, MM_DBUS_PATH); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void ModemInfo::Stop() { |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 70 | cellular_operator_info_.reset(); |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 71 | mobile_provider_close_db(provider_db_); |
| 72 | provider_db_ = NULL; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 73 | modem_managers_.reset(); |
| 74 | } |
| 75 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 76 | void ModemInfo::OnDeviceInfoAvailable(const string &link_name) { |
| 77 | for (ModemManagers::iterator it = modem_managers_.begin(); |
| 78 | it != modem_managers_.end(); ++it) { |
| 79 | (*it)->OnDeviceInfoAvailable(link_name); |
| 80 | } |
| 81 | } |
| 82 | |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 83 | template <class mm> |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 84 | void ModemInfo::RegisterModemManager(const string &service, |
| 85 | const string &path) { |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 86 | ModemManager *manager = new mm(service, |
| 87 | path, |
| 88 | control_interface_, |
| 89 | dispatcher_, |
| 90 | metrics_, |
| 91 | manager_, |
| 92 | glib_, |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 93 | cellular_operator_info_.get(), |
David Rochberg | 7cb06f6 | 2012-03-05 11:23:44 -0500 | [diff] [blame] | 94 | provider_db_); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 95 | modem_managers_.push_back(manager); // Passes ownership. |
| 96 | manager->Start(); |
| 97 | } |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 98 | } // namespace shill |