5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #define IFF_LOWER_UP 0x10000
35 #define CONNMAN_API_SUBJECT_TO_CHANGE
36 #include <connman/plugin.h>
37 #include <connman/device.h>
38 #include <connman/inet.h>
39 #include <connman/rtnl.h>
40 #include <connman/log.h>
42 struct ethernet_data {
48 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
50 struct connman_device *device = user_data;
51 struct ethernet_data *ethernet = connman_device_get_data(device);
53 DBG("index %d flags %d change %d", ethernet->index, flags, change);
55 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
58 connman_device_set_powered(device, TRUE);
61 connman_device_set_powered(device, FALSE);
65 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
66 if (flags & IFF_LOWER_UP) {
68 connman_device_set_carrier(device, TRUE);
71 connman_device_set_carrier(device, FALSE);
75 ethernet->flags = flags;
78 static int ethernet_probe(struct connman_device *device)
80 struct ethernet_data *ethernet;
82 DBG("device %p", device);
84 ethernet = g_try_new0(struct ethernet_data, 1);
88 connman_device_set_data(device, ethernet);
90 ethernet->index = connman_device_get_index(device);
93 ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
94 ethernet_newlink, device);
96 connman_rtnl_send_getlink();
101 static void ethernet_remove(struct connman_device *device)
103 struct ethernet_data *ethernet = connman_device_get_data(device);
105 DBG("device %p", device);
107 connman_device_set_data(device, NULL);
109 connman_rtnl_remove_watch(ethernet->watch);
114 static int ethernet_enable(struct connman_device *device)
116 struct ethernet_data *ethernet = connman_device_get_data(device);
118 DBG("device %p", device);
120 return connman_inet_ifup(ethernet->index);
123 static int ethernet_disable(struct connman_device *device)
125 struct ethernet_data *ethernet = connman_device_get_data(device);
127 DBG("device %p", device);
129 return connman_inet_ifdown(ethernet->index);
132 static struct connman_device_driver ethernet_driver = {
134 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
135 .probe = ethernet_probe,
136 .remove = ethernet_remove,
137 .enable = ethernet_enable,
138 .disable = ethernet_disable,
141 static int ethernet_init(void)
143 return connman_device_driver_register(ðernet_driver);
146 static void ethernet_exit(void)
148 connman_device_driver_unregister(ðernet_driver);
151 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
152 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)