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 { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 20 | |
| 21 | WiFiService::WiFiService(ControlInterface *control_interface, |
| 22 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 23 | Manager *manager, |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 24 | const WiFiRefPtr &device, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 25 | const std::vector<uint8_t> ssid, |
| 26 | uint32_t mode, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 27 | const std::string &key_management) |
| 28 | : Service(control_interface, dispatcher, manager), |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 29 | task_factory_(this), |
| 30 | wifi_(device), |
| 31 | ssid_(ssid), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 32 | mode_(mode) { |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 33 | eap_.key_management = key_management; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 34 | |
| 35 | // TODO(cmasone): Figure out if mode_ should be a string or what |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 36 | // store_.RegisterString(flimflam::kModeProperty, &mode_); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 37 | store_.RegisterString(flimflam::kPassphraseProperty, &passphrase_); |
| 38 | store_.RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 39 | store_.RegisterConstString(flimflam::kSecurityProperty, &security_); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 40 | store_.RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
| 41 | store_.RegisterConstString(flimflam::kTypeProperty, &type_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 42 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 43 | store_.RegisterConstString(flimflam::kWifiAuthMode, &auth_mode_); |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 44 | store_.RegisterConstBool(flimflam::kWifiHiddenSsid, &hidden_ssid_); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 45 | store_.RegisterConstUint16(flimflam::kWifiFrequency, &frequency_); |
| 46 | store_.RegisterConstUint16(flimflam::kWifiPhyMode, &physical_mode_); |
| 47 | store_.RegisterConstUint16(flimflam::kWifiHexSsid, &hex_ssid_); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | WiFiService::~WiFiService() { |
| 51 | LOG(INFO) << __func__; |
| 52 | } |
| 53 | |
| 54 | void WiFiService::Connect() { |
| 55 | LOG(INFO) << __func__; |
| 56 | |
| 57 | // NB(quiche) defer handling, since dbus-c++ does not permit us to |
| 58 | // send an outbound request while processing an inbound one. |
| 59 | dispatcher_->PostTask( |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 60 | task_factory_.NewRunnableMethod(&WiFiService::ConnectTask)); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 63 | void WiFiService::Disconnect() { |
| 64 | // TODO(quiche) RemoveNetwork from supplicant |
| 65 | // XXX remove from favorite networks list? |
| 66 | } |
| 67 | |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 68 | uint32_t WiFiService::mode() const { |
| 69 | return mode_; |
| 70 | } |
| 71 | |
| 72 | const std::string &WiFiService::key_management() const { |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 73 | return eap_.key_management; |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | const std::vector<uint8_t> &WiFiService::ssid() const { |
| 77 | return ssid_; |
| 78 | } |
| 79 | |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 80 | void WiFiService::ConnectTask() { |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 81 | wifi_->ConnectTo(*this); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 84 | string WiFiService::GetDeviceRpcId() { |
| 85 | return wifi_->GetRpcIdentifier(); |
| 86 | } |
| 87 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 88 | } // namespace shill |