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 | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
| 11 | #include <base/string_number_conversions.h> |
| 12 | #include <base/string_util.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 14 | |
| 15 | #include "shill/control_interface.h" |
| 16 | #include "shill/device.h" |
| 17 | #include "shill/shill_event.h" |
| 18 | #include "shill/wifi.h" |
| 19 | |
| 20 | using std::string; |
| 21 | |
| 22 | namespace shill { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 23 | |
| 24 | WiFiService::WiFiService(ControlInterface *control_interface, |
| 25 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 26 | Manager *manager, |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 27 | const WiFiRefPtr &device, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 28 | const std::vector<uint8_t> ssid, |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 29 | const std::string &mode, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 30 | const std::string &key_management) |
| 31 | : Service(control_interface, dispatcher, manager), |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 32 | security_(flimflam::kSecurityNone), |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 33 | type_(flimflam::kTypeWifi), |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 34 | mode_(mode), |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 35 | task_factory_(this), |
| 36 | wifi_(device), |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 37 | ssid_(ssid) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 38 | SetEAPKeyManagement(key_management); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 39 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 40 | PropertyStore *store = this->store(); |
| 41 | store->RegisterConstString(flimflam::kModeProperty, &mode_); |
| 42 | store->RegisterString(flimflam::kPassphraseProperty, &passphrase_); |
| 43 | store->RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
| 44 | store->RegisterConstString(flimflam::kSecurityProperty, &security_); |
| 45 | store->RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
| 46 | store->RegisterConstString(flimflam::kTypeProperty, &type_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 47 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 48 | store->RegisterConstString(flimflam::kWifiAuthMode, &auth_mode_); |
| 49 | store->RegisterConstBool(flimflam::kWifiHiddenSsid, &hidden_ssid_); |
| 50 | store->RegisterConstUint16(flimflam::kWifiFrequency, &frequency_); |
| 51 | store->RegisterConstUint16(flimflam::kWifiPhyMode, &physical_mode_); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 52 | store->RegisterConstString(flimflam::kWifiHexSsid, &hex_ssid_); |
| 53 | |
| 54 | hex_ssid_ = base::HexEncode(&(*ssid_.begin()), ssid_.size()); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame^] | 55 | set_name(name() + |
| 56 | "_" + |
| 57 | string(reinterpret_cast<const char*>(ssid_.data()), ssid_.size())); |
| 58 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 59 | // TODO(quiche): set based on security properties |
| 60 | need_passphrase_ = false; |
| 61 | // TODO(quiche): figure out when to set true |
| 62 | hidden_ssid_ = false; |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | WiFiService::~WiFiService() { |
| 66 | LOG(INFO) << __func__; |
| 67 | } |
| 68 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 69 | void WiFiService::Connect(Error *error) { |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 70 | LOG(INFO) << __func__; |
| 71 | |
| 72 | // NB(quiche) defer handling, since dbus-c++ does not permit us to |
| 73 | // send an outbound request while processing an inbound one. |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 74 | dispatcher()->PostTask( |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 75 | task_factory_.NewRunnableMethod(&WiFiService::ConnectTask)); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 78 | void WiFiService::Disconnect() { |
| 79 | // TODO(quiche) RemoveNetwork from supplicant |
| 80 | // XXX remove from favorite networks list? |
| 81 | } |
| 82 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame^] | 83 | string WiFiService::GetStorageIdentifier() { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 84 | return StringToLowerASCII(base::StringPrintf("%s_%s_%s_%s_%s", |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 85 | flimflam::kTypeWifi, |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame^] | 86 | wifi_->address().c_str(), |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 87 | hex_ssid_.c_str(), |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 88 | mode_.c_str(), |
| 89 | security_.c_str())); |
| 90 | } |
| 91 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 92 | const string &WiFiService::mode() const { |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 93 | return mode_; |
| 94 | } |
| 95 | |
Chris Masone | 092df3e | 2011-08-22 09:41:39 -0700 | [diff] [blame] | 96 | const string &WiFiService::key_management() const { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 97 | return GetEAPKeyManagement(); |
mukesh agrawal | 445e72c | 2011-06-22 11:13:50 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | const std::vector<uint8_t> &WiFiService::ssid() const { |
| 101 | return ssid_; |
| 102 | } |
| 103 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 104 | // private methods |
mukesh agrawal | dc42bb3 | 2011-07-28 10:40:26 -0700 | [diff] [blame] | 105 | void WiFiService::ConnectTask() { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 106 | wifi_->ConnectTo(this); |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 109 | string WiFiService::GetDeviceRpcId() { |
| 110 | return wifi_->GetRpcIdentifier(); |
| 111 | } |
| 112 | |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 113 | } // namespace shill |