mukesh agrawal | b54601c | 2011-06-07 17:39:22 -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 "shill/wifi_service.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/logging.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 10 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 11 | |
| 12 | #include "shill/control_interface.h" |
| 13 | #include "shill/device.h" |
| 14 | #include "shill/shill_event.h" |
| 15 | #include "shill/wifi.h" |
| 16 | |
| 17 | using std::string; |
| 18 | |
| 19 | namespace shill { |
| 20 | const char WiFiService::kSupplicantPropertySSID[] = "ssid"; |
| 21 | const char WiFiService::kSupplicantPropertyNetworkMode[] = "mode"; |
| 22 | const char WiFiService::kSupplicantPropertyKeyMode[] = "key_mgmt"; |
| 23 | |
| 24 | WiFiService::WiFiService(ControlInterface *control_interface, |
| 25 | EventDispatcher *dispatcher, |
| 26 | WiFi *device, |
| 27 | const std::vector<uint8_t> ssid, |
| 28 | uint32_t mode, |
| 29 | const std::string &key_management, |
| 30 | const std::string &name) |
| 31 | : Service(control_interface, dispatcher, device, name), |
| 32 | task_factory_(this), |
| 33 | wifi_(device), |
| 34 | ssid_(ssid), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 35 | mode_(mode) { |
| 36 | eap_.key_management = key_management; |
| 37 | |
| 38 | // TODO(cmasone): Figure out if mode_ should be a string or what |
| 39 | // RegisterString(flimflam::kModeProperty, &mode_); |
| 40 | RegisterString(flimflam::kPassphraseProperty, &passphrase_); |
| 41 | RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
| 42 | RegisterConstString(flimflam::kSecurityProperty, &security_); |
| 43 | |
| 44 | RegisterConstString(flimflam::kWifiAuthMode, &auth_mode_); |
| 45 | RegisterConstBool(flimflam::kWifiHiddenSsid, &hidden_ssid_); |
| 46 | RegisterConstUint16(flimflam::kWifiFrequency, &frequency_); |
| 47 | RegisterConstUint16(flimflam::kWifiPhyMode, &physical_mode_); |
| 48 | RegisterConstUint16(flimflam::kWifiHexSsid, &hex_ssid_); |
| 49 | |
| 50 | RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
| 51 | RegisterConstString(flimflam::kTypeProperty, &type_); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | WiFiService::~WiFiService() { |
| 55 | LOG(INFO) << __func__; |
| 56 | } |
| 57 | |
| 58 | void WiFiService::Connect() { |
| 59 | LOG(INFO) << __func__; |
| 60 | |
| 61 | // NB(quiche) defer handling, since dbus-c++ does not permit us to |
| 62 | // send an outbound request while processing an inbound one. |
| 63 | dispatcher_->PostTask( |
| 64 | task_factory_.NewRunnableMethod(&WiFiService::RealConnect)); |
| 65 | } |
| 66 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 67 | void WiFiService::Disconnect() { |
| 68 | // TODO(quiche) RemoveNetwork from supplicant |
| 69 | // XXX remove from favorite networks list? |
| 70 | } |
| 71 | |
| 72 | bool WiFiService::Contains(const string &property) { |
| 73 | return (Service::Contains(property) || |
| 74 | uint16_properties_.find(property) != uint16_properties_.end()); |
| 75 | } |
| 76 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 77 | void WiFiService::RealConnect() { |
| 78 | std::map<string, DBus::Variant> add_network_args; |
| 79 | DBus::MessageIter mi; |
| 80 | DBus::Path network_path; |
| 81 | |
| 82 | add_network_args[kSupplicantPropertyNetworkMode].writer(). |
| 83 | append_uint32(mode_); |
| 84 | add_network_args[kSupplicantPropertyKeyMode].writer(). |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 85 | append_string(eap_.key_management.c_str()); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 86 | // TODO(quiche): figure out why we can't use operator<< without the |
| 87 | // temporary variable. |
| 88 | mi = add_network_args[kSupplicantPropertySSID].writer(); |
| 89 | mi << ssid_; |
| 90 | // TODO(quiche): set scan_ssid=1, like flimflam does? |
| 91 | |
| 92 | network_path = wifi_->AddNetwork(add_network_args); |
| 93 | wifi_->SelectNetwork(network_path); |
| 94 | // XXX add to favorite networks list? |
| 95 | } |
| 96 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 97 | } // namespace shill |