blob: 77ac11af95a5343e546c19a0fdb71a6175b6fc20 [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"
Darin Petkovafa6fc42011-06-21 16:21:08 -070020#include "shill/ethernet.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070021#include "shill/event_dispatcher.h"
Paul Stewartf1ce5d22011-05-19 13:10:20 -070022#include "shill/manager.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070023#include "shill/profile.h"
Paul Stewartf1ce5d22011-05-19 13:10:20 -070024
Paul Stewartf1ce5d22011-05-19 13:10:20 -070025using std::string;
26
27namespace shill {
Darin Petkovafa6fc42011-06-21 16:21:08 -070028
Chris Masone34af2182011-08-22 11:59:36 -070029// static
30const char EthernetService::kServiceType[] = "ethernet";
31
Paul Stewartf1ce5d22011-05-19 13:10:20 -070032EthernetService::EthernetService(ControlInterface *control_interface,
33 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080034 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070035 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070036 const EthernetRefPtr &device)
Thieu Le3426c8f2012-01-11 17:35:11 -080037 : Service(control_interface, dispatcher, metrics, manager,
38 Technology::kEthernet),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070039 ethernet_(device) {
Gaurav Shah435de2c2011-11-17 19:01:07 -080040 set_connectable(true);
Darin Petkovafa6fc42011-06-21 16:21:08 -070041 set_auto_connect(true);
Paul Stewart0ad019a2012-04-19 11:06:43 -070042 set_friendly_name("Ethernet");
mukesh agrawal8f3f7752012-02-17 19:42:09 -080043 SetStrength(kStrengthMax);
Paul Stewartf1ce5d22011-05-19 13:10:20 -070044}
45
46EthernetService::~EthernetService() { }
47
Christopher Wiley2f1bbf02012-10-25 15:31:13 -070048void EthernetService::Connect(Error */*error*/) {
49 ethernet_->ConnectTo(this);
50}
51
52void EthernetService::Disconnect(Error */*error*/) {
53 ethernet_->DisconnectFrom(this);
54}
55
Gaurav Shah1b7a6162011-11-09 11:41:01 -080056std::string EthernetService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070057 return ethernet_->GetRpcIdentifier();
58}
59
Chris Masone6515aab2011-10-12 16:19:09 -070060string EthernetService::GetStorageIdentifier() const {
Chris Masone9d779932011-08-25 16:33:41 -070061 return base::StringPrintf("%s_%s",
62 kServiceType, ethernet_->address().c_str());
Chris Masone34af2182011-08-22 11:59:36 -070063}
64
Paul Stewartcf199de2012-08-16 07:50:41 -070065void EthernetService::SetAutoConnect(const bool &connect, Error *error) {
66 if (!connect) {
67 Error::PopulateAndLog(
68 error, Error::kInvalidArguments,
69 "Auto-connect on Ethernet services must not be disabled.");
70 return;
71 }
72 Service::SetAutoConnect(connect, error);
73}
74
Paul Stewartf1ce5d22011-05-19 13:10:20 -070075} // namespace shill