blob: 063b0799306951a730beceadad626f8bc7039661 [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 Petkov75f201f2013-03-19 13:01:28 +01008
9#if !defined(DISABLE_CELLULAR)
10
Darin Petkov887f2982011-07-14 16:10:17 -070011#include <mm/mm-modem.h>
Darin Petkov137884a2011-10-26 18:52:47 +020012#include <mobile_provider.h>
Darin Petkov887f2982011-07-14 16:10:17 -070013
Darin Petkov75f201f2013-03-19 13:01:28 +010014#endif // DISABLE_CELLULAR
15
Ben Chan62028b22012-11-05 11:20:02 -080016#include "shill/cellular_operator_info.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070017#include "shill/logging.h"
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -070018#include "shill/manager.h"
Darin Petkov887f2982011-07-14 16:10:17 -070019#include "shill/modem_manager.h"
Arman Uguray41cc6342013-03-29 16:34:39 -070020#include "shill/pending_activation_store.h"
Darin Petkov887f2982011-07-14 16:10:17 -070021
Albert Chaulk0e1cdea2013-02-27 15:32:55 -080022using base::FilePath;
Darin Petkov887f2982011-07-14 16:10:17 -070023using std::string;
24
David Rochberg7cb06f62012-03-05 11:23:44 -050025// 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 Chan62028b22012-11-05 11:20:02 -080031namespace shill {
32
33namespace {
34
35const char kCromoService[] = "org.chromium.ModemManager";
36const char kCromoPath[] = "/org/chromium/ModemManager";
37
38const char kCellularOperatorInfoPath[] =
39 "/usr/share/shill/cellular_operator_info";
40const char kMobileProviderDBPath[] =
Darin Petkov137884a2011-10-26 18:52:47 +020041 "/usr/share/mobile-broadband-provider-info/serviceproviders.bfd";
Darin Petkov887f2982011-07-14 16:10:17 -070042
Ben Chan62028b22012-11-05 11:20:02 -080043} // namespace
44
Darin Petkov887f2982011-07-14 16:10:17 -070045ModemInfo::ModemInfo(ControlInterface *control_interface,
46 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080047 Metrics *metrics,
Darin Petkov887f2982011-07-14 16:10:17 -070048 Manager *manager,
49 GLib *glib)
50 : control_interface_(control_interface),
Darin Petkov67d8ecf2011-07-26 16:03:30 -070051 dispatcher_(dispatcher),
Thieu Le3426c8f2012-01-11 17:35:11 -080052 metrics_(metrics),
Darin Petkov887f2982011-07-14 16:10:17 -070053 manager_(manager),
Darin Petkov137884a2011-10-26 18:52:47 +020054 glib_(glib),
Arman Uguray41cc6342013-03-29 16:34:39 -070055 pending_activation_store_(NULL),
Darin Petkov137884a2011-10-26 18:52:47 +020056 provider_db_path_(kMobileProviderDBPath),
57 provider_db_(NULL) {}
Darin Petkov887f2982011-07-14 16:10:17 -070058
59ModemInfo::~ModemInfo() {
60 Stop();
61}
62
Darin Petkov75f201f2013-03-19 13:01:28 +010063#if defined(DISABLE_CELLULAR)
64
65void ModemInfo::Start() {}
66void ModemInfo::Stop() {}
67void ModemInfo::OnDeviceInfoAvailable(const string &link_name) {
Darin Petkovbd9f33a2013-03-20 10:38:07 +010068 NOTIMPLEMENTED();
Darin Petkov75f201f2013-03-19 13:01:28 +010069}
70
71#else
72
Darin Petkov887f2982011-07-14 16:10:17 -070073void ModemInfo::Start() {
Arman Uguray41cc6342013-03-29 16:34:39 -070074 pending_activation_store_.reset(new PendingActivationStore());
75 pending_activation_store_->InitStorage(manager_->glib(),
Prathmesh Prabhu97f317c2013-03-15 16:20:34 -070076 manager_->storage_path());
Arman Ugurayf4c61812013-01-10 18:58:39 -080077 cellular_operator_info_.reset(new CellularOperatorInfo());
Ben Chan62028b22012-11-05 11:20:02 -080078 cellular_operator_info_->Load(FilePath(kCellularOperatorInfoPath));
79
Darin Petkov137884a2011-10-26 18:52:47 +020080 // 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 Chan8799a4a2013-04-13 16:00:13 -070085 RegisterModemManager(
86 new ModemManagerClassic(kCromoService, kCromoPath, this));
87 RegisterModemManager(new ModemManager1(MM_DBUS_SERVICE, MM_DBUS_PATH, this));
Darin Petkov887f2982011-07-14 16:10:17 -070088}
89
90void ModemInfo::Stop() {
Arman Uguray41cc6342013-03-29 16:34:39 -070091 pending_activation_store_.reset();
Ben Chan62028b22012-11-05 11:20:02 -080092 cellular_operator_info_.reset();
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070093 if(provider_db_)
94 mobile_provider_close_db(provider_db_);
Darin Petkov137884a2011-10-26 18:52:47 +020095 provider_db_ = NULL;
Paul Stewart5ad16062013-02-21 18:10:48 -080096 modem_managers_.clear();
Darin Petkov887f2982011-07-14 16:10:17 -070097}
98
Darin Petkov41c0e0a2012-01-09 16:38:53 +010099void 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 Uguray41cc6342013-03-29 16:34:39 -0700106void ModemInfo::set_pending_activation_store(
107 PendingActivationStore *pending_activation_store) {
108 pending_activation_store_.reset(pending_activation_store);
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700109}
110
111void ModemInfo::set_cellular_operator_info(
112 CellularOperatorInfo *cellular_operator_info) {
113 cellular_operator_info_.reset(cellular_operator_info);
114}
115
Ben Chan8799a4a2013-04-13 16:00:13 -0700116void ModemInfo::RegisterModemManager(ModemManager *manager) {
Darin Petkov887f2982011-07-14 16:10:17 -0700117 modem_managers_.push_back(manager); // Passes ownership.
118 manager->Start();
119}
Darin Petkov75f201f2013-03-19 13:01:28 +0100120
121#endif // DISABLE_CELLULAR
122
Darin Petkov887f2982011-07-14 16:10:17 -0700123} // namespace shill