blob: 8888e606118c84a33000128195261ab7cb2f224b [file] [log] [blame]
Darin Petkov41c0e0a2012-01-09 16:38:53 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov887f2982011-07-14 16:10:17 -07002// 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 Chan62028b22012-11-05 11:20:02 -08007#include <base/file_path.h>
Darin Petkov887f2982011-07-14 16:10:17 -07008#include <mm/mm-modem.h>
Darin Petkov137884a2011-10-26 18:52:47 +02009#include <mobile_provider.h>
Darin Petkov887f2982011-07-14 16:10:17 -070010
Ben Chan62028b22012-11-05 11:20:02 -080011#include "shill/cellular_operator_info.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070012#include "shill/logging.h"
Darin Petkov887f2982011-07-14 16:10:17 -070013#include "shill/modem_manager.h"
14
15using std::string;
16
David Rochberg7cb06f62012-03-05 11:23:44 -050017// 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 Chan62028b22012-11-05 11:20:02 -080023namespace shill {
24
25namespace {
26
27const char kCromoService[] = "org.chromium.ModemManager";
28const char kCromoPath[] = "/org/chromium/ModemManager";
29
30const char kCellularOperatorInfoPath[] =
31 "/usr/share/shill/cellular_operator_info";
32const char kMobileProviderDBPath[] =
Darin Petkov137884a2011-10-26 18:52:47 +020033 "/usr/share/mobile-broadband-provider-info/serviceproviders.bfd";
Darin Petkov887f2982011-07-14 16:10:17 -070034
Ben Chan62028b22012-11-05 11:20:02 -080035} // namespace
36
Darin Petkov887f2982011-07-14 16:10:17 -070037ModemInfo::ModemInfo(ControlInterface *control_interface,
38 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080039 Metrics *metrics,
Darin Petkov887f2982011-07-14 16:10:17 -070040 Manager *manager,
41 GLib *glib)
42 : control_interface_(control_interface),
Darin Petkov67d8ecf2011-07-26 16:03:30 -070043 dispatcher_(dispatcher),
Thieu Le3426c8f2012-01-11 17:35:11 -080044 metrics_(metrics),
Darin Petkov887f2982011-07-14 16:10:17 -070045 manager_(manager),
Darin Petkov137884a2011-10-26 18:52:47 +020046 glib_(glib),
47 provider_db_path_(kMobileProviderDBPath),
48 provider_db_(NULL) {}
Darin Petkov887f2982011-07-14 16:10:17 -070049
50ModemInfo::~ModemInfo() {
51 Stop();
52}
53
54void ModemInfo::Start() {
Arman Ugurayf4c61812013-01-10 18:58:39 -080055 cellular_operator_info_.reset(new CellularOperatorInfo());
Ben Chan62028b22012-11-05 11:20:02 -080056 cellular_operator_info_->Load(FilePath(kCellularOperatorInfoPath));
57
Darin Petkov137884a2011-10-26 18:52:47 +020058 // 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 Rochberg7cb06f62012-03-05 11:23:44 -050063 RegisterModemManager<ModemManagerClassic>(MM_MODEMMANAGER_SERVICE,
64 MM_MODEMMANAGER_PATH);
65 RegisterModemManager<ModemManagerClassic>(kCromoService, kCromoPath);
66 RegisterModemManager<ModemManager1>(MM_DBUS_SERVICE, MM_DBUS_PATH);
Darin Petkov887f2982011-07-14 16:10:17 -070067}
68
69void ModemInfo::Stop() {
Ben Chan62028b22012-11-05 11:20:02 -080070 cellular_operator_info_.reset();
Darin Petkov137884a2011-10-26 18:52:47 +020071 mobile_provider_close_db(provider_db_);
72 provider_db_ = NULL;
Darin Petkov887f2982011-07-14 16:10:17 -070073 modem_managers_.reset();
74}
75
Darin Petkov41c0e0a2012-01-09 16:38:53 +010076void 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 Rochberg7cb06f62012-03-05 11:23:44 -050083template <class mm>
Darin Petkov887f2982011-07-14 16:10:17 -070084void ModemInfo::RegisterModemManager(const string &service,
85 const string &path) {
David Rochberg7cb06f62012-03-05 11:23:44 -050086 ModemManager *manager = new mm(service,
87 path,
88 control_interface_,
89 dispatcher_,
90 metrics_,
91 manager_,
92 glib_,
Ben Chan62028b22012-11-05 11:20:02 -080093 cellular_operator_info_.get(),
David Rochberg7cb06f62012-03-05 11:23:44 -050094 provider_db_);
Darin Petkov887f2982011-07-14 16:10:17 -070095 modem_managers_.push_back(manager); // Passes ownership.
96 manager->Start();
97}
Darin Petkov887f2982011-07-14 16:10:17 -070098} // namespace shill