Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 5 | #include "shill/ethernet_service.h" |
| 6 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 7 | #include <time.h> |
| 8 | #include <stdio.h> |
| 9 | #include <netinet/ether.h> |
| 10 | #include <linux/if.h> |
| 11 | |
| 12 | #include <string> |
| 13 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 14 | #include <base/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | #include <chromeos/dbus/service_constants.h> |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 16 | |
| 17 | #include "shill/control_interface.h" |
| 18 | #include "shill/device.h" |
| 19 | #include "shill/device_info.h" |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 20 | #include "shill/eap_credentials.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 21 | #include "shill/ethernet.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 22 | #include "shill/event_dispatcher.h" |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 23 | #include "shill/manager.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 24 | #include "shill/profile.h" |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 25 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 26 | using std::string; |
| 27 | |
| 28 | namespace shill { |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 29 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 30 | // static |
| 31 | const char EthernetService::kServiceType[] = "ethernet"; |
| 32 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 33 | EthernetService::EthernetService(ControlInterface *control_interface, |
| 34 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 35 | Metrics *metrics, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 36 | Manager *manager, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 37 | const EthernetRefPtr &device) |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 38 | : Service(control_interface, dispatcher, metrics, manager, |
| 39 | Technology::kEthernet), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 40 | ethernet_(device) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 41 | SetConnectable(true); |
| 42 | SetAutoConnect(true); |
Paul Stewart | 0ad019a | 2012-04-19 11:06:43 -0700 | [diff] [blame] | 43 | set_friendly_name("Ethernet"); |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 44 | SetStrength(kStrengthMax); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | EthernetService::~EthernetService() { } |
| 48 | |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 49 | void EthernetService::Connect(Error *error, const char *reason) { |
| 50 | Service::Connect(error, reason); |
Christopher Wiley | 2f1bbf0 | 2012-10-25 15:31:13 -0700 | [diff] [blame] | 51 | ethernet_->ConnectTo(this); |
| 52 | } |
| 53 | |
| 54 | void EthernetService::Disconnect(Error */*error*/) { |
| 55 | ethernet_->DisconnectFrom(this); |
| 56 | } |
| 57 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 58 | std::string EthernetService::GetDeviceRpcId(Error */*error*/) { |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 59 | return ethernet_->GetRpcIdentifier(); |
| 60 | } |
| 61 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 62 | string EthernetService::GetStorageIdentifier() const { |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 63 | return base::StringPrintf("%s_%s", |
| 64 | kServiceType, ethernet_->address().c_str()); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 67 | bool EthernetService::SetAutoConnectFull(const bool &connect, |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 68 | Error *error) { |
Paul Stewart | cf199de | 2012-08-16 07:50:41 -0700 | [diff] [blame] | 69 | if (!connect) { |
| 70 | Error::PopulateAndLog( |
| 71 | error, Error::kInvalidArguments, |
| 72 | "Auto-connect on Ethernet services must not be disabled."); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 73 | return false; |
Paul Stewart | cf199de | 2012-08-16 07:50:41 -0700 | [diff] [blame] | 74 | } |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 75 | return Service::SetAutoConnectFull(connect, error); |
Paul Stewart | cf199de | 2012-08-16 07:50:41 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 78 | void EthernetService::Remove(Error *error) { |
| 79 | error->Populate(Error::kNotSupported); |
| 80 | } |
| 81 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 82 | } // namespace shill |