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/rtnl.h>
39 #include <connman/log.h>
43 struct ethernet_data {
49 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
51 struct connman_device *device = user_data;
52 struct ethernet_data *ethernet = connman_device_get_data(device);
54 DBG("index %d flags %ld change %ld", ethernet->index, flags, change);
56 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
59 connman_device_set_powered(device, TRUE);
62 connman_device_set_powered(device, FALSE);
66 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
67 if (flags & IFF_LOWER_UP) {
69 connman_device_set_carrier(device, TRUE);
72 connman_device_set_carrier(device, FALSE);
76 ethernet->flags = flags;
79 static int ethernet_probe(struct connman_device *device)
81 struct ethernet_data *ethernet;
83 DBG("device %p", device);
85 ethernet = g_try_new0(struct ethernet_data, 1);
89 connman_device_set_data(device, ethernet);
91 ethernet->index = connman_device_get_index(device);
94 ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
95 ethernet_newlink, device);
97 connman_rtnl_send_getlink();
102 static void ethernet_remove(struct connman_device *device)
104 struct ethernet_data *ethernet = connman_device_get_data(device);
106 DBG("device %p", device);
108 connman_device_set_data(device, NULL);
110 connman_rtnl_remove_watch(ethernet->watch);
115 static int ethernet_enable(struct connman_device *device)
117 struct ethernet_data *ethernet = connman_device_get_data(device);
119 DBG("device %p", device);
121 return inet_ifup(ethernet->index);
124 static int ethernet_disable(struct connman_device *device)
126 struct ethernet_data *ethernet = connman_device_get_data(device);
128 DBG("device %p", device);
130 return inet_ifdown(ethernet->index);
133 static struct connman_device_driver ethernet_driver = {
135 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
136 .probe = ethernet_probe,
137 .remove = ethernet_remove,
138 .enable = ethernet_enable,
139 .disable = ethernet_disable,
142 static int ethernet_init(void)
144 return connman_device_driver_register(ðernet_driver);
147 static void ethernet_exit(void)
149 connman_device_driver_unregister(ðernet_driver);
152 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
153 ethernet_init, ethernet_exit)