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