Home | History | Annotate | Download | only in dbus
      1 //
      2 // Copyright (C) 2015 The Android Open Source Project
      3 //
      4 // Licensed under the Apache License, Version 2.0 (the "License");
      5 // you may not use this file except in compliance with the License.
      6 // You may obtain a copy of the License at
      7 //
      8 //      http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unless required by applicable law or agreed to in writing, software
     11 // distributed under the License is distributed on an "AS IS" BASIS,
     12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 // See the License for the specific language governing permissions and
     14 // limitations under the License.
     15 //
     16 
     17 #include "shill/dbus/chromeos_dbus_control.h"
     18 
     19 #include <brillo/dbus/async_event_sequencer.h>
     20 
     21 #if defined(__ANDROID__)
     22 #include <dbus/service_constants.h>
     23 #else
     24 #include <chromeos/dbus/service_constants.h>
     25 #endif  // __ANDROID__
     26 
     27 #include "shill/dbus/chromeos_device_dbus_adaptor.h"
     28 #include "shill/dbus/chromeos_ipconfig_dbus_adaptor.h"
     29 #include "shill/dbus/chromeos_manager_dbus_adaptor.h"
     30 #include "shill/dbus/chromeos_profile_dbus_adaptor.h"
     31 #include "shill/dbus/chromeos_rpc_task_dbus_adaptor.h"
     32 #include "shill/dbus/chromeos_service_dbus_adaptor.h"
     33 #include "shill/dbus/chromeos_third_party_vpn_dbus_adaptor.h"
     34 
     35 #include "shill/dbus/chromeos_dhcpcd_listener.h"
     36 #include "shill/dbus/chromeos_dhcpcd_proxy.h"
     37 #if defined(__ANDROID__)
     38 #include "shill/dbus/chromeos_firewalld_proxy.h"
     39 #include "shill/power_manager_proxy_stub.h"
     40 #include "shill/upstart/upstart_proxy_stub.h"
     41 #else
     42 #include "shill/dbus/chromeos_permission_broker_proxy.h"
     43 #include "shill/dbus/chromeos_power_manager_proxy.h"
     44 #include "shill/dbus/chromeos_upstart_proxy.h"
     45 #endif  // __ANDROID__
     46 #include "shill/dbus/chromeos_dbus_service_watcher.h"
     47 
     48 #if !defined(DISABLE_CELLULAR)
     49 #include "shill/dbus/chromeos_dbus_objectmanager_proxy.h"
     50 #include "shill/dbus/chromeos_dbus_properties_proxy.h"
     51 #include "shill/dbus/chromeos_mm1_modem_modem3gpp_proxy.h"
     52 #include "shill/dbus/chromeos_mm1_modem_modemcdma_proxy.h"
     53 #include "shill/dbus/chromeos_mm1_modem_proxy.h"
     54 #include "shill/dbus/chromeos_mm1_modem_simple_proxy.h"
     55 #include "shill/dbus/chromeos_mm1_sim_proxy.h"
     56 #include "shill/dbus/chromeos_modem_cdma_proxy.h"
     57 #include "shill/dbus/chromeos_modem_gobi_proxy.h"
     58 #include "shill/dbus/chromeos_modem_gsm_card_proxy.h"
     59 #include "shill/dbus/chromeos_modem_gsm_network_proxy.h"
     60 #include "shill/dbus/chromeos_modem_manager_proxy.h"
     61 #include "shill/dbus/chromeos_modem_proxy.h"
     62 #include "shill/dbus/chromeos_modem_simple_proxy.h"
     63 #endif  // DISABLE_CELLULAR
     64 
     65 #if !defined(DISABLE_WIFI)
     66 #include "shill/dbus/chromeos_supplicant_bss_proxy.h"
     67 #endif  // DISABLE_WIFI
     68 
     69 #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
     70 #include "shill/dbus/chromeos_supplicant_interface_proxy.h"
     71 #include "shill/dbus/chromeos_supplicant_network_proxy.h"
     72 #include "shill/dbus/chromeos_supplicant_process_proxy.h"
     73 #endif  // DISABLE_WIFI || DISABLE_WIRED_8021X
     74 
     75 #if !defined(DISABLE_WIMAX)
     76 #include "shill/dbus/chromeos_wimax_device_proxy.h"
     77 #include "shill/dbus/chromeos_wimax_manager_proxy.h"
     78 #include "shill/dbus/chromeos_wimax_network_proxy.h"
     79 #endif  // DISABLE_WIMAX
     80 
     81 #include "shill/manager.h"
     82 
     83 using brillo::dbus_utils::AsyncEventSequencer;
     84 using std::string;
     85 
     86 namespace shill {
     87 
     88 // static.
     89 const char ChromeosDBusControl::kNullPath[] = "/";
     90 
     91 ChromeosDBusControl::ChromeosDBusControl(EventDispatcher* dispatcher)
     92     : dispatcher_(dispatcher),
     93       null_identifier_(kNullPath) {
     94   dbus::Bus::Options options;
     95   options.bus_type = dbus::Bus::SYSTEM;
     96 
     97   adaptor_bus_ = new dbus::Bus(options);
     98   proxy_bus_ = new dbus::Bus(options);
     99   CHECK(adaptor_bus_->Connect());
    100   CHECK(proxy_bus_->Connect());
    101 }
    102 
    103 ChromeosDBusControl::~ChromeosDBusControl() {
    104   if (adaptor_bus_) {
    105     adaptor_bus_->ShutdownAndBlock();
    106   }
    107   if (proxy_bus_) {
    108     proxy_bus_->ShutdownAndBlock();
    109   }
    110 }
    111 
    112 const string& ChromeosDBusControl::NullRPCIdentifier() {
    113   return null_identifier_;
    114 }
    115 
    116 void ChromeosDBusControl::RegisterManagerObject(
    117     Manager* manager, const base::Closure& registration_done_callback) {
    118   registration_done_callback_ = registration_done_callback;
    119   scoped_refptr<AsyncEventSequencer> sequencer(new AsyncEventSequencer());
    120   manager->RegisterAsync(
    121       base::Bind(
    122           &ChromeosDBusControl::OnDBusServiceRegistered,
    123           base::Unretained(this),
    124           sequencer->GetHandler("Manager.RegisterAsync() failed.", true)));
    125   sequencer->OnAllTasksCompletedCall({
    126       base::Bind(&ChromeosDBusControl::TakeServiceOwnership,
    127                  base::Unretained(this))
    128   });
    129 }
    130 
    131 template <typename Object, typename AdaptorInterface, typename Adaptor>
    132 AdaptorInterface* ChromeosDBusControl::CreateAdaptor(Object* object) {
    133   return new Adaptor(adaptor_bus_, object);
    134 }
    135 
    136 void ChromeosDBusControl::OnDBusServiceRegistered(
    137     const base::Callback<void(bool)>& completion_action, bool success) {
    138   // The DBus control interface will take over the ownership of the DBus service
    139   // in this callback.  The daemon will crash if registration failed.
    140   completion_action.Run(success);
    141 
    142   // We can start the manager now that we have ownership of the D-Bus service.
    143   // Doing so earlier would allow the manager to emit signals before service
    144   // ownership was acquired.
    145   registration_done_callback_.Run();
    146 }
    147 
    148 void ChromeosDBusControl::TakeServiceOwnership(bool success) {
    149   // Success should always be true since we've said that failures are fatal.
    150   CHECK(success) << "Init of one or more objects has failed.";
    151   CHECK(adaptor_bus_->RequestOwnershipAndBlock(kFlimflamServiceName,
    152                                        dbus::Bus::REQUIRE_PRIMARY))
    153       << "Unable to take ownership of " << kFlimflamServiceName;
    154 }
    155 
    156 DeviceAdaptorInterface* ChromeosDBusControl::CreateDeviceAdaptor(
    157     Device* device) {
    158   return
    159       CreateAdaptor<Device, DeviceAdaptorInterface, ChromeosDeviceDBusAdaptor>(
    160           device);
    161 }
    162 
    163 IPConfigAdaptorInterface* ChromeosDBusControl::CreateIPConfigAdaptor(
    164     IPConfig* config) {
    165   return
    166       CreateAdaptor<IPConfig, IPConfigAdaptorInterface,
    167                     ChromeosIPConfigDBusAdaptor>(config);
    168 }
    169 
    170 ManagerAdaptorInterface* ChromeosDBusControl::CreateManagerAdaptor(
    171     Manager* manager) {
    172   return new ChromeosManagerDBusAdaptor(adaptor_bus_, proxy_bus_, manager);
    173 }
    174 
    175 ProfileAdaptorInterface* ChromeosDBusControl::CreateProfileAdaptor(
    176     Profile* profile) {
    177   return
    178       CreateAdaptor<Profile, ProfileAdaptorInterface,
    179                     ChromeosProfileDBusAdaptor>(profile);
    180 }
    181 
    182 RPCTaskAdaptorInterface* ChromeosDBusControl::CreateRPCTaskAdaptor(
    183     RPCTask* task) {
    184   return
    185       CreateAdaptor<RPCTask, RPCTaskAdaptorInterface,
    186                     ChromeosRPCTaskDBusAdaptor>(task);
    187 }
    188 
    189 ServiceAdaptorInterface* ChromeosDBusControl::CreateServiceAdaptor(
    190     Service* service) {
    191   return
    192       CreateAdaptor<Service, ServiceAdaptorInterface,
    193                     ChromeosServiceDBusAdaptor>(service);
    194 }
    195 
    196 #ifndef DISABLE_VPN
    197 ThirdPartyVpnAdaptorInterface* ChromeosDBusControl::CreateThirdPartyVpnAdaptor(
    198     ThirdPartyVpnDriver* driver) {
    199   return
    200       CreateAdaptor<ThirdPartyVpnDriver, ThirdPartyVpnAdaptorInterface,
    201                     ChromeosThirdPartyVpnDBusAdaptor>(driver);
    202 }
    203 #endif
    204 
    205 PowerManagerProxyInterface* ChromeosDBusControl::CreatePowerManagerProxy(
    206     PowerManagerProxyDelegate* delegate,
    207     const base::Closure& service_appeared_callback,
    208     const base::Closure& service_vanished_callback) {
    209 #if defined(__ANDROID__)
    210   return new PowerManagerProxyStub();
    211 #else
    212   return new ChromeosPowerManagerProxy(dispatcher_,
    213                                        proxy_bus_,
    214                                        delegate,
    215                                        service_appeared_callback,
    216                                        service_vanished_callback);
    217 #endif  // __ANDROID__
    218 }
    219 
    220 #if !defined(DISABLE_WIFI) || !defined(DISABLE_WIRED_8021X)
    221 SupplicantProcessProxyInterface*
    222     ChromeosDBusControl::CreateSupplicantProcessProxy(
    223         const base::Closure& service_appeared_callback,
    224         const base::Closure& service_vanished_callback) {
    225   return new ChromeosSupplicantProcessProxy(dispatcher_,
    226                                             proxy_bus_,
    227                                             service_appeared_callback,
    228                                             service_vanished_callback);
    229 }
    230 
    231 SupplicantInterfaceProxyInterface*
    232     ChromeosDBusControl::CreateSupplicantInterfaceProxy(
    233         SupplicantEventDelegateInterface* delegate,
    234         const string& object_path) {
    235   return new ChromeosSupplicantInterfaceProxy(
    236       proxy_bus_, object_path, delegate);
    237 }
    238 
    239 SupplicantNetworkProxyInterface*
    240     ChromeosDBusControl::CreateSupplicantNetworkProxy(
    241         const string& object_path) {
    242   return new ChromeosSupplicantNetworkProxy(proxy_bus_, object_path);
    243 }
    244 #endif  // DISABLE_WIFI || DISABLE_WIRED_8021X
    245 
    246 #if !defined(DISABLE_WIFI)
    247 SupplicantBSSProxyInterface* ChromeosDBusControl::CreateSupplicantBSSProxy(
    248     WiFiEndpoint* wifi_endpoint,
    249     const string& object_path) {
    250   return new ChromeosSupplicantBSSProxy(proxy_bus_, object_path, wifi_endpoint);
    251 }
    252 #endif  // DISABLE_WIFI
    253 
    254 DHCPCDListenerInterface* ChromeosDBusControl::CreateDHCPCDListener(
    255     DHCPProvider* provider) {
    256   return new ChromeosDHCPCDListener(proxy_bus_, dispatcher_, provider);
    257 }
    258 
    259 DHCPProxyInterface* ChromeosDBusControl::CreateDHCPProxy(
    260     const string& service) {
    261   return new ChromeosDHCPCDProxy(proxy_bus_, service);
    262 }
    263 
    264 UpstartProxyInterface* ChromeosDBusControl::CreateUpstartProxy() {
    265 #if defined(__ANDROID__)
    266   return new UpstartProxyStub();
    267 #else
    268   return new ChromeosUpstartProxy(proxy_bus_);
    269 #endif  // __ANDROID__
    270 }
    271 
    272 FirewallProxyInterface* ChromeosDBusControl::CreateFirewallProxy() {
    273 #if defined(__ANDROID__)
    274   return new ChromeosFirewalldProxy(proxy_bus_);
    275 #else
    276   return new ChromeosPermissionBrokerProxy(proxy_bus_);
    277 #endif  // __ANDROID__
    278 }
    279 
    280 #if !defined(DISABLE_CELLULAR)
    281 DBusPropertiesProxyInterface* ChromeosDBusControl::CreateDBusPropertiesProxy(
    282     const string& path,
    283     const string& service) {
    284   return new ChromeosDBusPropertiesProxy(proxy_bus_, path, service);
    285 }
    286 
    287 DBusObjectManagerProxyInterface*
    288     ChromeosDBusControl::CreateDBusObjectManagerProxy(
    289         const string& path,
    290         const string& service,
    291         const base::Closure& service_appeared_callback,
    292         const base::Closure& service_vanished_callback) {
    293   return new ChromeosDBusObjectManagerProxy(dispatcher_,
    294                                             proxy_bus_,
    295                                             path,
    296                                             service,
    297                                             service_appeared_callback,
    298                                             service_vanished_callback);
    299 }
    300 
    301 ModemManagerProxyInterface*
    302     ChromeosDBusControl::CreateModemManagerProxy(
    303         ModemManagerClassic* manager,
    304         const string& path,
    305         const string& service,
    306         const base::Closure& service_appeared_callback,
    307         const base::Closure& service_vanished_callback) {
    308   return new ChromeosModemManagerProxy(dispatcher_,
    309                                        proxy_bus_,
    310                                        manager,
    311                                        path,
    312                                        service,
    313                                        service_appeared_callback,
    314                                        service_vanished_callback);
    315 }
    316 
    317 ModemProxyInterface* ChromeosDBusControl::CreateModemProxy(
    318     const string& path,
    319     const string& service) {
    320   return new ChromeosModemProxy(proxy_bus_, path, service);
    321 }
    322 
    323 ModemSimpleProxyInterface* ChromeosDBusControl::CreateModemSimpleProxy(
    324     const string& path,
    325     const string& service) {
    326   return new ChromeosModemSimpleProxy(proxy_bus_, path, service);
    327 }
    328 
    329 ModemCDMAProxyInterface* ChromeosDBusControl::CreateModemCDMAProxy(
    330     const string& path,
    331     const string& service) {
    332   return new ChromeosModemCDMAProxy(proxy_bus_, path, service);
    333 }
    334 
    335 ModemGSMCardProxyInterface* ChromeosDBusControl::CreateModemGSMCardProxy(
    336     const string& path,
    337     const string& service) {
    338   return new ChromeosModemGSMCardProxy(proxy_bus_, path, service);
    339 }
    340 
    341 ModemGSMNetworkProxyInterface* ChromeosDBusControl::CreateModemGSMNetworkProxy(
    342     const string& path,
    343     const string& service) {
    344   return new ChromeosModemGSMNetworkProxy(proxy_bus_, path, service);
    345 }
    346 
    347 ModemGobiProxyInterface* ChromeosDBusControl::CreateModemGobiProxy(
    348     const string& path,
    349     const string& service) {
    350   return new ChromeosModemGobiProxy(proxy_bus_, path, service);
    351 }
    352 
    353 // Proxies for ModemManager1 interfaces
    354 mm1::ModemModem3gppProxyInterface*
    355     ChromeosDBusControl::CreateMM1ModemModem3gppProxy(
    356         const string& path,
    357         const string& service) {
    358   return new mm1::ChromeosModemModem3gppProxy(proxy_bus_, path, service);
    359 }
    360 
    361 mm1::ModemModemCdmaProxyInterface*
    362     ChromeosDBusControl::CreateMM1ModemModemCdmaProxy(
    363         const string& path,
    364         const string& service) {
    365   return new mm1::ChromeosModemModemCdmaProxy(proxy_bus_, path, service);
    366 }
    367 
    368 mm1::ModemProxyInterface* ChromeosDBusControl::CreateMM1ModemProxy(
    369     const string& path,
    370     const string& service) {
    371   return new mm1::ChromeosModemProxy(proxy_bus_, path, service);
    372 }
    373 
    374 mm1::ModemSimpleProxyInterface* ChromeosDBusControl::CreateMM1ModemSimpleProxy(
    375     const string& path,
    376     const string& service) {
    377   return new mm1::ChromeosModemSimpleProxy(proxy_bus_, path, service);
    378 }
    379 
    380 mm1::SimProxyInterface* ChromeosDBusControl::CreateSimProxy(
    381     const string& path,
    382     const string& service) {
    383   return new mm1::ChromeosSimProxy(proxy_bus_, path, service);
    384 }
    385 #endif  // DISABLE_CELLULAR
    386 
    387 #if !defined(DISABLE_WIMAX)
    388 WiMaxDeviceProxyInterface* ChromeosDBusControl::CreateWiMaxDeviceProxy(
    389     const string& path) {
    390   return new ChromeosWiMaxDeviceProxy(proxy_bus_, path);
    391 }
    392 
    393 WiMaxManagerProxyInterface* ChromeosDBusControl::CreateWiMaxManagerProxy(
    394     const base::Closure& service_appeared_callback,
    395     const base::Closure& service_vanished_callback) {
    396   return new ChromeosWiMaxManagerProxy(dispatcher_,
    397                                        proxy_bus_,
    398                                        service_appeared_callback,
    399                                        service_vanished_callback);
    400 }
    401 
    402 WiMaxNetworkProxyInterface* ChromeosDBusControl::CreateWiMaxNetworkProxy(
    403     const string& path) {
    404   return new ChromeosWiMaxNetworkProxy(proxy_bus_, path);
    405 }
    406 #endif  // DISABLE_WIMAX
    407 
    408 }  // namespace shill
    409