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);
99 static void ethernet_remove(struct connman_device *device)
101 struct ethernet_data *ethernet = connman_device_get_data(device);
103 DBG("device %p", device);
105 connman_device_set_data(device, NULL);
107 connman_rtnl_remove_watch(ethernet->watch);
112 static int ethernet_enable(struct connman_device *device)
114 struct ethernet_data *ethernet = connman_device_get_data(device);
116 DBG("device %p", device);
118 return connman_inet_ifup(ethernet->index);
121 static int ethernet_disable(struct connman_device *device)
123 struct ethernet_data *ethernet = connman_device_get_data(device);
125 DBG("device %p", device);
127 return connman_inet_ifdown(ethernet->index);
130 static int ethernet_connect(struct connman_device *device)
132 struct ethernet_data *ethernet = connman_device_get_data(device);
134 DBG("device %p", device);
136 if (!(ethernet->flags & IFF_LOWER_UP))
139 return connman_device_set_connected(device, TRUE);
142 static int ethernet_disconnect(struct connman_device *device)
144 struct ethernet_data *ethernet = connman_device_get_data(device);
146 DBG("device %p", device);
148 if (!(ethernet->flags & IFF_LOWER_UP))
151 return connman_device_set_connected(device, FALSE);
154 static struct connman_device_driver ethernet_driver = {
156 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
157 .probe = ethernet_probe,
158 .remove = ethernet_remove,
159 .enable = ethernet_enable,
160 .disable = ethernet_disable,
161 .connect = ethernet_connect,
162 .disconnect = ethernet_disconnect,
165 static int ethernet_init(void)
167 return connman_device_driver_register(ðernet_driver);
170 static void ethernet_exit(void)
172 connman_device_driver_unregister(ðernet_driver);
175 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
176 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)