blob: 8fab092b0b0ba2b884102c1b75759ebda5de3b4b [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewartf1ce5d22011-05-19 13:10:20 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkovafa6fc42011-06-21 16:21:08 -07005#include "shill/ethernet_service.h"
6
Paul Stewartf1ce5d22011-05-19 13:10:20 -07007#include <time.h>
8#include <stdio.h>
9#include <netinet/ether.h>
10#include <linux/if.h>
11
12#include <string>
13
Chris Masone34af2182011-08-22 11:59:36 -070014#include <base/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015#include <chromeos/dbus/service_constants.h>
Paul Stewartf1ce5d22011-05-19 13:10:20 -070016
17#include "shill/control_interface.h"
18#include "shill/device.h"
19#include "shill/device_info.h"
Paul Stewartc43cbbe2013-04-11 06:29:30 -070020#include "shill/eap_credentials.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070021#include "shill/ethernet.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070022#include "shill/event_dispatcher.h"
Paul Stewartf1ce5d22011-05-19 13:10:20 -070023#include "shill/manager.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070024#include "shill/profile.h"
Paul Stewartf1ce5d22011-05-19 13:10:20 -070025
Paul Stewartf1ce5d22011-05-19 13:10:20 -070026using std::string;
27
28namespace shill {
Darin Petkovafa6fc42011-06-21 16:21:08 -070029
Chris Masone34af2182011-08-22 11:59:36 -070030// static
31const char EthernetService::kServiceType[] = "ethernet";
32
Paul Stewartf1ce5d22011-05-19 13:10:20 -070033EthernetService::EthernetService(ControlInterface *control_interface,
34 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080035 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070036 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070037 const EthernetRefPtr &device)
Thieu Le3426c8f2012-01-11 17:35:11 -080038 : Service(control_interface, dispatcher, metrics, manager,
39 Technology::kEthernet),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070040 ethernet_(device) {
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070041 SetConnectable(true);
42 SetAutoConnect(true);
Paul Stewart0ad019a2012-04-19 11:06:43 -070043 set_friendly_name("Ethernet");
mukesh agrawal8f3f7752012-02-17 19:42:09 -080044 SetStrength(kStrengthMax);
Paul Stewartf1ce5d22011-05-19 13:10:20 -070045}
46
47EthernetService::~EthernetService() { }
48
mukesh agrawaldc7b8442012-09-27 13:48:14 -070049void EthernetService::Connect(Error *error, const char *reason) {
50 Service::Connect(error, reason);
Christopher Wiley2f1bbf02012-10-25 15:31:13 -070051 ethernet_->ConnectTo(this);
52}
53
54void EthernetService::Disconnect(Error */*error*/) {
55 ethernet_->DisconnectFrom(this);
56}
57
Gaurav Shah1b7a6162011-11-09 11:41:01 -080058std::string EthernetService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070059 return ethernet_->GetRpcIdentifier();
60}
61
Chris Masone6515aab2011-10-12 16:19:09 -070062string EthernetService::GetStorageIdentifier() const {
Chris Masone9d779932011-08-25 16:33:41 -070063 return base::StringPrintf("%s_%s",
64 kServiceType, ethernet_->address().c_str());
Chris Masone34af2182011-08-22 11:59:36 -070065}
66
mukesh agrawalbebf1b82013-04-23 15:06:33 -070067bool EthernetService::SetAutoConnectFull(const bool &connect,
mukesh agrawalcbfb34e2013-04-17 19:33:25 -070068 Error *error) {
Paul Stewartcf199de2012-08-16 07:50:41 -070069 if (!connect) {
70 Error::PopulateAndLog(
71 error, Error::kInvalidArguments,
72 "Auto-connect on Ethernet services must not be disabled.");
mukesh agrawalbebf1b82013-04-23 15:06:33 -070073 return false;
Paul Stewartcf199de2012-08-16 07:50:41 -070074 }
mukesh agrawalbebf1b82013-04-23 15:06:33 -070075 return Service::SetAutoConnectFull(connect, error);
Paul Stewartcf199de2012-08-16 07:50:41 -070076}
77
Albert Chaulk0e1cdea2013-02-27 15:32:55 -080078void EthernetService::Remove(Error *error) {
79 error->Populate(Error::kNotSupported);
80}
81
Paul Stewartf1ce5d22011-05-19 13:10:20 -070082} // namespace shill