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 int ethernet_connect(struct connman_device *device)
134 struct ethernet_data *ethernet = connman_device_get_data(device);
136 DBG("device %p", device);
138 if (!(ethernet->flags & IFF_LOWER_UP))
141 connman_device_set_carrier(device, TRUE);
146 static int ethernet_disconnect(struct connman_device *device)
148 struct ethernet_data *ethernet = connman_device_get_data(device);
150 DBG("device %p", device);
152 if (!(ethernet->flags & IFF_LOWER_UP))
155 connman_device_set_carrier(device, FALSE);
160 static struct connman_device_driver ethernet_driver = {
162 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
163 .probe = ethernet_probe,
164 .remove = ethernet_remove,
165 .enable = ethernet_enable,
166 .disable = ethernet_disable,
167 .connect = ethernet_connect,
168 .disconnect = ethernet_disconnect,
171 static int ethernet_init(void)
173 return connman_device_driver_register(ðernet_driver);
176 static void ethernet_exit(void)
178 connman_device_driver_unregister(ðernet_driver);
181 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
182 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)