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
29 #include <sys/ioctl.h>
30 #include <sys/socket.h>
32 #include <linux/netlink.h>
33 #include <linux/rtnetlink.h>
37 #define CONNMAN_API_SUBJECT_TO_CHANGE
38 #include <connman/plugin.h>
39 #include <connman/device.h>
40 #include <connman/rtnl.h>
41 #include <connman/log.h>
45 struct ethernet_data {
51 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
53 struct connman_device *device = user_data;
54 struct ethernet_data *ethernet = connman_device_get_data(device);
56 DBG("index %d flags %ld change %ld", ethernet->index, flags, change);
58 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
61 connman_device_set_powered(device, TRUE);
64 connman_device_set_powered(device, FALSE);
68 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
69 if (flags & IFF_LOWER_UP) {
71 connman_device_set_carrier(device, TRUE);
74 connman_device_set_carrier(device, FALSE);
78 ethernet->flags = flags;
81 static int ethernet_probe(struct connman_device *device)
83 struct ethernet_data *ethernet;
85 DBG("device %p", device);
87 ethernet = g_try_new0(struct ethernet_data, 1);
91 connman_device_set_data(device, ethernet);
93 ethernet->index = connman_device_get_index(device);
96 ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
97 ethernet_newlink, device);
99 connman_rtnl_send_getlink();
104 static void ethernet_remove(struct connman_device *device)
106 struct ethernet_data *ethernet = connman_device_get_data(device);
108 DBG("device %p", device);
110 connman_device_set_data(device, NULL);
112 connman_rtnl_remove_watch(ethernet->watch);
117 static int ethernet_enable(struct connman_device *device)
119 struct ethernet_data *ethernet = connman_device_get_data(device);
121 DBG("device %p", device);
123 return inet_ifup(ethernet->index);
126 static int ethernet_disable(struct connman_device *device)
128 struct ethernet_data *ethernet = connman_device_get_data(device);
130 DBG("device %p", device);
132 return inet_ifdown(ethernet->index);
135 static struct connman_device_driver ethernet_driver = {
137 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
138 .probe = ethernet_probe,
139 .remove = ethernet_remove,
140 .enable = ethernet_enable,
141 .disable = ethernet_disable,
144 static int ethernet_init(void)
146 return connman_device_driver_register(ðernet_driver);
149 static void ethernet_exit(void)
151 connman_device_driver_unregister(ðernet_driver);
154 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
155 ethernet_init, ethernet_exit)