Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 1 | // 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 agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 8 | #include <map> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 9 | #include <string> |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 10 | #include <vector> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 11 | |
| 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 agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 20 | using std::string; |
| 21 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 22 | namespace shill { |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 23 | const char WiFi::kSupplicantPath[] = "/fi/w1/wpa_supplicant1"; |
| 24 | const char WiFi::kSupplicantDBusAddr[] = "fi.w1.wpa_supplicant1"; |
| 25 | const char WiFi::kSupplicantWiFiDriver[] = "nl80211"; |
| 26 | |
| 27 | WiFi::SupplicantProcessProxy::SupplicantProcessProxy(DBus::Connection *bus) |
| 28 | : DBus::ObjectProxy(*bus, kSupplicantPath, kSupplicantDBusAddr) {} |
| 29 | |
| 30 | void WiFi::SupplicantProcessProxy::InterfaceAdded( |
| 31 | const ::DBus::Path& path, |
| 32 | const std::map<string, ::DBus::Variant> &properties) { |
| 33 | LOG(INFO) << __func__; |
| 34 | // XXX |
| 35 | } |
| 36 | |
| 37 | void WiFi::SupplicantProcessProxy::InterfaceRemoved(const ::DBus::Path& path) { |
| 38 | LOG(INFO) << __func__; |
| 39 | // XXX |
| 40 | } |
| 41 | |
| 42 | void WiFi::SupplicantProcessProxy::PropertiesChanged( |
| 43 | const std::map<string, ::DBus::Variant>& properties) { |
| 44 | LOG(INFO) << __func__; |
| 45 | // XXX |
| 46 | } |
| 47 | |
| 48 | WiFi::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 | |
| 55 | void WiFi::SupplicantInterfaceProxy::ScanDone(const bool& success) { |
| 56 | LOG(INFO) << __func__ << " " << success; |
| 57 | if (success) { |
| 58 | wifi_.ScanDone(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void 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 | |
| 69 | void WiFi::SupplicantInterfaceProxy::BSSRemoved(const ::DBus::Path &BSS) { |
| 70 | LOG(INFO) << __func__; |
| 71 | // XXX |
| 72 | } |
| 73 | |
| 74 | void WiFi::SupplicantInterfaceProxy::BlobAdded(const string &blobname) { |
| 75 | LOG(INFO) << __func__; |
| 76 | // XXX |
| 77 | } |
| 78 | |
| 79 | void WiFi::SupplicantInterfaceProxy::BlobRemoved(const string &blobname) { |
| 80 | LOG(INFO) << __func__; |
| 81 | // XXX |
| 82 | } |
| 83 | |
| 84 | void WiFi::SupplicantInterfaceProxy::NetworkAdded( |
| 85 | const ::DBus::Path &network, |
| 86 | const std::map<string, ::DBus::Variant> &properties) { |
| 87 | LOG(INFO) << __func__; |
| 88 | // XXX |
| 89 | } |
| 90 | |
| 91 | void WiFi::SupplicantInterfaceProxy::NetworkRemoved( |
| 92 | const ::DBus::Path &network) { |
| 93 | LOG(INFO) << __func__; |
| 94 | // XXX |
| 95 | } |
| 96 | |
| 97 | void WiFi::SupplicantInterfaceProxy::NetworkSelected( |
| 98 | const ::DBus::Path &network) { |
| 99 | LOG(INFO) << __func__; |
| 100 | // XXX |
| 101 | } |
| 102 | |
| 103 | void 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 Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 110 | WiFi::WiFi(ControlInterface *control_interface, |
| 111 | EventDispatcher *dispatcher, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 112 | Manager *manager, |
| 113 | const std::string& link_name, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 114 | int interface_index) |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 115 | : Device(control_interface, dispatcher, manager, link_name, |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 116 | interface_index), |
| 117 | dbus_(DBus::Connection::SystemBus()), scan_pending_(false) { |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 118 | VLOG(2) << "WiFi device " << link_name << " initialized."; |
| 119 | } |
| 120 | |
| 121 | WiFi::~WiFi() { |
| 122 | } |
| 123 | |
mukesh agrawal | ab87ea4 | 2011-05-18 11:44:49 -0700 | [diff] [blame^] | 124 | void 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 | |
| 149 | void 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 | |
| 156 | void 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 | |
| 166 | void WiFi::Stop() { |
| 167 | LOG(INFO) << __func__; |
| 168 | // XXX |
| 169 | Device::Stop(); |
| 170 | } |
| 171 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 172 | bool WiFi::TechnologyIs(const Device::Technology type) { |
| 173 | return type == Device::kWifi; |
| 174 | } |
| 175 | |
| 176 | } // namespace shill |