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 {
50 static GSList *ethernet_list = NULL;
52 static void ethernet_newlink(unsigned short type, int index,
53 unsigned flags, unsigned change)
57 DBG("index %d flags %ld change %ld", index, flags, change);
59 for (list = ethernet_list; list; list = list->next) {
60 struct connman_device *device = list->data;
61 struct ethernet_data *ethernet;
63 ethernet = connman_device_get_data(device);
67 if (ethernet->index != index)
70 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
73 connman_device_set_powered(device, TRUE);
76 connman_device_set_powered(device, FALSE);
80 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
81 if (flags & IFF_LOWER_UP) {
83 connman_device_set_carrier(device, TRUE);
86 connman_device_set_carrier(device, FALSE);
90 ethernet->flags = flags;
94 static struct connman_rtnl ethernet_rtnl = {
96 .newlink = ethernet_newlink,
99 static int ethernet_probe(struct connman_device *device)
101 struct ethernet_data *ethernet;
103 DBG("device %p", device);
105 ethernet = g_try_new0(struct ethernet_data, 1);
106 if (ethernet == NULL)
109 ethernet_list = g_slist_append(ethernet_list, device);
111 connman_device_set_data(device, ethernet);
113 ethernet->index = connman_device_get_index(device);
115 connman_rtnl_send_getlink();
120 static void ethernet_remove(struct connman_device *device)
122 struct ethernet_data *ethernet = connman_device_get_data(device);
124 DBG("device %p", device);
126 connman_device_set_data(device, NULL);
128 ethernet_list = g_slist_remove(ethernet_list, device);
133 static int ethernet_enable(struct connman_device *device)
135 struct ethernet_data *ethernet = connman_device_get_data(device);
137 DBG("device %p", device);
139 return inet_ifup(ethernet->index);
142 static int ethernet_disable(struct connman_device *device)
144 struct ethernet_data *ethernet = connman_device_get_data(device);
146 DBG("device %p", device);
148 return inet_ifdown(ethernet->index);
151 static struct connman_device_driver ethernet_driver = {
153 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
154 .probe = ethernet_probe,
155 .remove = ethernet_remove,
156 .enable = ethernet_enable,
157 .disable = ethernet_disable,
160 static int ethernet_init(void)
164 err = connman_rtnl_register(ðernet_rtnl);
168 err = connman_device_driver_register(ðernet_driver);
170 connman_rtnl_unregister(ðernet_rtnl);
177 static void ethernet_exit(void)
179 connman_device_driver_unregister(ðernet_driver);
181 connman_rtnl_unregister(ðernet_rtnl);
184 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
185 ethernet_init, ethernet_exit)