blob: 43cbfc586ad30f086058bb036290bb8ad2ddc390 [file] [log] [blame]
Paul Stewartb50f0b92011-05-16 16:31:42 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
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 <time.h>
6#include <stdio.h>
7
mukesh agrawalab87ea42011-05-18 11:44:49 -07008#include <map>
Paul Stewartb50f0b92011-05-16 16:31:42 -07009#include <string>
mukesh agrawalab87ea42011-05-18 11:44:49 -070010#include <vector>
Paul Stewartb50f0b92011-05-16 16:31:42 -070011
12#include <base/logging.h>
13
14#include "shill/control_interface.h"
15#include "shill/device.h"
16#include "shill/shill_event.h"
17
18#include "shill/wifi.h"
19
mukesh agrawalab87ea42011-05-18 11:44:49 -070020using std::string;
21
Paul Stewartb50f0b92011-05-16 16:31:42 -070022namespace shill {
mukesh agrawalab87ea42011-05-18 11:44:49 -070023const char WiFi::kSupplicantPath[] = "/fi/w1/wpa_supplicant1";
24const char WiFi::kSupplicantDBusAddr[] = "fi.w1.wpa_supplicant1";
25const char WiFi::kSupplicantWiFiDriver[] = "nl80211";
26
27WiFi::SupplicantProcessProxy::SupplicantProcessProxy(DBus::Connection *bus)
28 : DBus::ObjectProxy(*bus, kSupplicantPath, kSupplicantDBusAddr) {}
29
30void WiFi::SupplicantProcessProxy::InterfaceAdded(
31 const ::DBus::Path& path,
32 const std::map<string, ::DBus::Variant> &properties) {
33 LOG(INFO) << __func__;
34 // XXX
35}
36
37void WiFi::SupplicantProcessProxy::InterfaceRemoved(const ::DBus::Path& path) {
38 LOG(INFO) << __func__;
39 // XXX
40}
41
42void WiFi::SupplicantProcessProxy::PropertiesChanged(
43 const std::map<string, ::DBus::Variant>& properties) {
44 LOG(INFO) << __func__;
45 // XXX
46}
47
48WiFi::SupplicantInterfaceProxy::SupplicantInterfaceProxy(
49 WiFi *wifi,
50 DBus::Connection *bus,
51 const ::DBus::Path &object_path)
52 : wifi_(*wifi),
53 DBus::ObjectProxy(*bus, object_path, kSupplicantDBusAddr) {}
54
55void WiFi::SupplicantInterfaceProxy::ScanDone(const bool& success) {
56 LOG(INFO) << __func__ << " " << success;
57 if (success) {
58 wifi_.ScanDone();
59 }
60}
61
62void WiFi::SupplicantInterfaceProxy::BSSAdded(
63 const ::DBus::Path &BSS,
64 const std::map<string, ::DBus::Variant> &properties) {
65 LOG(INFO) << __func__;
66 wifi_.BSSAdded(BSS, properties);
67}
68
69void WiFi::SupplicantInterfaceProxy::BSSRemoved(const ::DBus::Path &BSS) {
70 LOG(INFO) << __func__;
71 // XXX
72}
73
74void WiFi::SupplicantInterfaceProxy::BlobAdded(const string &blobname) {
75 LOG(INFO) << __func__;
76 // XXX
77}
78
79void WiFi::SupplicantInterfaceProxy::BlobRemoved(const string &blobname) {
80 LOG(INFO) << __func__;
81 // XXX
82}
83
84void WiFi::SupplicantInterfaceProxy::NetworkAdded(
85 const ::DBus::Path &network,
86 const std::map<string, ::DBus::Variant> &properties) {
87 LOG(INFO) << __func__;
88 // XXX
89}
90
91void WiFi::SupplicantInterfaceProxy::NetworkRemoved(
92 const ::DBus::Path &network) {
93 LOG(INFO) << __func__;
94 // XXX
95}
96
97void WiFi::SupplicantInterfaceProxy::NetworkSelected(
98 const ::DBus::Path &network) {
99 LOG(INFO) << __func__;
100 // XXX
101}
102
103void WiFi::SupplicantInterfaceProxy::PropertiesChanged(
104 const std::map<string, ::DBus::Variant> &properties) {
105 LOG(INFO) << __func__;
106 // XXX
107}
108
109// NB: we assume supplicant is already running. [quiche.20110518]
Paul Stewartb50f0b92011-05-16 16:31:42 -0700110WiFi::WiFi(ControlInterface *control_interface,
111 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700112 Manager *manager,
113 const std::string& link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -0700114 int interface_index)
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700115 : Device(control_interface, dispatcher, manager, link_name,
mukesh agrawalab87ea42011-05-18 11:44:49 -0700116 interface_index),
117 dbus_(DBus::Connection::SystemBus()), scan_pending_(false) {
Paul Stewartb50f0b92011-05-16 16:31:42 -0700118 VLOG(2) << "WiFi device " << link_name << " initialized.";
119}
120
121WiFi::~WiFi() {
122}
123
mukesh agrawalab87ea42011-05-18 11:44:49 -0700124void WiFi::Start() {
125 std::map<string, DBus::Variant> create_interface_args;
126 std::map<string, DBus::Variant> scan_args;
127 ::DBus::Path interface_path;
128
129 supplicant_process_proxy_.reset(new SupplicantProcessProxy(&dbus_));
130 create_interface_args["Ifname"].writer().append_string(link_name_.c_str());
131 create_interface_args["Driver"].writer().append_string(kSupplicantWiFiDriver);
132 // TODO(quiche) create_interface_args["ConfigFile"].writer().append_string
133 // (file with pkcs config info)
134 interface_path =
135 supplicant_process_proxy_->CreateInterface(create_interface_args);
136 // TODO(quiche) if CreateInterface failed: call GetInterface instead
137 LOG(INFO) << "creating SupplicantInterfaceProxy.";
138 supplicant_interface_proxy_.reset(
139 new SupplicantInterfaceProxy(this, &dbus_, interface_path));
140 // TODO(quiche) set ApScan=1 and BSSExpireAge=190, like flimflam does?
141 scan_args["Type"].writer().append_string("active");
142 LOG(INFO) << "initiating Scan.";
143 // TODO(quiche) indicate scanning in UI
144 supplicant_interface_proxy_->Scan(scan_args);
145 scan_pending_ = true;
146 Device::Start();
147}
148
149void WiFi::BSSAdded(
150 const ::DBus::Path &BSS,
151 const std::map<string, ::DBus::Variant> &properties) {
152 std::vector<uint8_t> ssid = properties.find("SSID")->second;
153 ssids_.push_back(string(ssid.begin(), ssid.end()));
154}
155
156void WiFi::ScanDone() {
157 LOG(INFO) << __func__;
158
159 scan_pending_ = false;
160 for (std::vector<string>::iterator i(ssids_.begin());
161 i != ssids_.end(); ++i) {
162 LOG(INFO) << "found SSID " << *i;
163 }
164}
165
166void WiFi::Stop() {
167 LOG(INFO) << __func__;
168 // XXX
169 Device::Stop();
170}
171
Paul Stewartb50f0b92011-05-16 16:31:42 -0700172bool WiFi::TechnologyIs(const Device::Technology type) {
173 return type == Device::kWifi;
174}
175
176} // namespace shill