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_supplicant_bss_proxy.h"
18 
19 #include <string>
20 
21 #include <base/bind.h>
22 
23 #include "shill/logging.h"
24 #include "shill/supplicant/wpa_supplicant.h"
25 #include "shill/wifi/wifi_endpoint.h"
26 
27 using std::string;
28 
29 namespace shill {
30 
31 namespace Logging {
32 static auto kModuleLogScope = ScopeLogger::kDBus;
ObjectID(const dbus::ObjectPath * p)33 static string ObjectID(const dbus::ObjectPath* p) { return p->value(); }
34 }
35 
ChromeosSupplicantBSSProxy(const scoped_refptr<dbus::Bus> & bus,const std::string & object_path,WiFiEndpoint * wifi_endpoint)36 ChromeosSupplicantBSSProxy::ChromeosSupplicantBSSProxy(
37     const scoped_refptr<dbus::Bus>& bus,
38     const std::string& object_path,
39     WiFiEndpoint* wifi_endpoint)
40     : bss_proxy_(
41         new fi::w1::wpa_supplicant1::BSSProxy(
42             bus,
43             WPASupplicant::kDBusAddr,
44             dbus::ObjectPath(object_path))),
45       wifi_endpoint_(wifi_endpoint) {
46   // Register signal handler.
47   bss_proxy_->RegisterPropertiesChangedSignalHandler(
48       base::Bind(&ChromeosSupplicantBSSProxy::PropertiesChanged,
49                  weak_factory_.GetWeakPtr()),
50       base::Bind(&ChromeosSupplicantBSSProxy::OnSignalConnected,
51                  weak_factory_.GetWeakPtr()));
52 }
53 
~ChromeosSupplicantBSSProxy()54 ChromeosSupplicantBSSProxy::~ChromeosSupplicantBSSProxy() {
55   bss_proxy_->ReleaseObjectProxy(base::Bind(&base::DoNothing));
56 }
57 
PropertiesChanged(const brillo::VariantDictionary & properties)58 void ChromeosSupplicantBSSProxy::PropertiesChanged(
59     const brillo::VariantDictionary& properties) {
60   SLOG(&bss_proxy_->GetObjectPath(), 2) << __func__;
61   KeyValueStore store;
62   KeyValueStore::ConvertFromVariantDictionary(properties, &store);
63   wifi_endpoint_->PropertiesChanged(store);
64 }
65 
66 // Called when signal is connected to the ObjectProxy.
OnSignalConnected(const std::string & interface_name,const std::string & signal_name,bool success)67 void ChromeosSupplicantBSSProxy::OnSignalConnected(
68     const std::string& interface_name,
69     const std::string& signal_name,
70     bool success) {
71   SLOG(&bss_proxy_->GetObjectPath(), 2) << __func__
72       << "interface: " << interface_name << " signal: " << signal_name
73       << "success: " << success;
74   if (!success) {
75     LOG(ERROR) << "Failed to connect signal " << signal_name
76         << " to interface " << interface_name;
77   }
78 }
79 
80 }  // namespace shill
81