5 * Copyright (C) 2007-2008 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 #include <connman/plugin.h>
38 #include <connman/device.h>
39 #include <connman/rtnl.h>
40 #include <connman/log.h>
44 struct ethernet_data {
49 static GSList *ethernet_list = NULL;
51 static void ethernet_newlink(unsigned short type, int index,
52 unsigned flags, unsigned change)
56 DBG("index %d flags %ld change %ld", index, flags, change);
58 for (list = ethernet_list; list; list = list->next) {
59 struct connman_device *device = list->data;
60 struct ethernet_data *ethernet;
62 ethernet = connman_device_get_data(device);
66 if (ethernet->index != index)
69 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
72 connman_device_set_powered(device, TRUE);
75 connman_device_set_powered(device, FALSE);
79 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
80 if (flags & IFF_LOWER_UP) {
82 connman_device_set_carrier(device, TRUE);
85 connman_device_set_carrier(device, FALSE);
89 ethernet->flags = flags;
93 static struct connman_rtnl ethernet_rtnl = {
95 .newlink = ethernet_newlink,
98 static int ethernet_probe(struct connman_device *device)
100 struct ethernet_data *ethernet;
102 DBG("device %p", device);
104 ethernet = g_try_new0(struct ethernet_data, 1);
105 if (ethernet == NULL)
108 ethernet_list = g_slist_append(ethernet_list, device);
110 connman_device_set_data(device, ethernet);
112 ethernet->index = connman_device_get_index(device);
114 connman_rtnl_send_getlink();
119 static void ethernet_remove(struct connman_device *device)
121 struct ethernet_data *ethernet = connman_device_get_data(device);
123 DBG("device %p", device);
125 connman_device_set_data(device, NULL);
127 ethernet_list = g_slist_remove(ethernet_list, device);
132 static int ethernet_enable(struct connman_device *device)
134 struct ethernet_data *ethernet = connman_device_get_data(device);
136 DBG("device %p", device);
138 return inet_ifup(ethernet->index);
141 static int ethernet_disable(struct connman_device *device)
143 struct ethernet_data *ethernet = connman_device_get_data(device);
145 DBG("device %p", device);
147 return inet_ifdown(ethernet->index);
150 static struct connman_device_driver ethernet_driver = {
152 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
153 .probe = ethernet_probe,
154 .remove = ethernet_remove,
155 .enable = ethernet_enable,
156 .disable = ethernet_disable,
159 static int ethernet_init(void)
163 err = connman_rtnl_register(ðernet_rtnl);
167 err = connman_device_driver_register(ðernet_driver);
169 connman_rtnl_unregister(ðernet_rtnl);
176 static void ethernet_exit(void)
178 connman_device_driver_unregister(ðernet_driver);
180 connman_rtnl_unregister(ðernet_rtnl);
183 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
184 ethernet_init, ethernet_exit)