5 * Copyright (C) 2007-2010 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 {
46 struct connman_network *network;
49 static int cable_probe(struct connman_network *network)
51 DBG("network %p", network);
56 static void cable_remove(struct connman_network *network)
58 DBG("network %p", network);
61 static int cable_connect(struct connman_network *network)
63 DBG("network %p", network);
68 static int cable_disconnect(struct connman_network *network)
70 DBG("network %p", network);
75 static struct connman_network_driver cable_driver = {
77 .type = CONNMAN_NETWORK_TYPE_ETHERNET,
79 .remove = cable_remove,
80 .connect = cable_connect,
81 .disconnect = cable_disconnect,
84 static void add_network(struct connman_device *device)
86 struct connman_network *network;
89 network = connman_network_create("carrier",
90 CONNMAN_NETWORK_TYPE_ETHERNET);
94 index = connman_device_get_index(device);
95 connman_network_set_index(network, index);
97 connman_network_set_name(network, "Wired");
98 connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP);
100 if (connman_device_add_network(device, network) < 0) {
101 connman_network_unref(network);
105 connman_network_set_available(network, TRUE);
107 connman_network_set_group(network, "cable");
109 connman_network_set_connected(network, TRUE);
112 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
114 struct connman_device *device = user_data;
115 struct ethernet_data *ethernet = connman_device_get_data(device);
117 DBG("index %d flags %d change %d", ethernet->index, flags, change);
119 if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
120 if (flags & IFF_UP) {
122 connman_device_set_powered(device, TRUE);
125 connman_device_set_powered(device, FALSE);
129 if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
130 if (flags & IFF_LOWER_UP) {
135 connman_device_remove_all_networks(device);
139 ethernet->flags = flags;
142 static int ethernet_probe(struct connman_device *device)
144 struct ethernet_data *ethernet;
146 DBG("device %p", device);
148 ethernet = g_try_new0(struct ethernet_data, 1);
149 if (ethernet == NULL)
152 connman_device_set_data(device, ethernet);
154 ethernet->index = connman_device_get_index(device);
157 ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
158 ethernet_newlink, device);
163 static void ethernet_remove(struct connman_device *device)
165 struct ethernet_data *ethernet = connman_device_get_data(device);
167 DBG("device %p", device);
169 connman_device_set_data(device, NULL);
171 connman_rtnl_remove_watch(ethernet->watch);
173 connman_device_remove_all_networks(device);
178 static int ethernet_enable(struct connman_device *device)
180 struct ethernet_data *ethernet = connman_device_get_data(device);
182 DBG("device %p", device);
184 return connman_inet_ifup(ethernet->index);
187 static int ethernet_disable(struct connman_device *device)
189 struct ethernet_data *ethernet = connman_device_get_data(device);
191 DBG("device %p", device);
193 return connman_inet_ifdown(ethernet->index);
196 static struct connman_device_driver ethernet_driver = {
198 .type = CONNMAN_DEVICE_TYPE_ETHERNET,
199 .probe = ethernet_probe,
200 .remove = ethernet_remove,
201 .enable = ethernet_enable,
202 .disable = ethernet_disable,
205 static int ethernet_init(void)
209 err = connman_network_driver_register(&cable_driver);
213 err = connman_device_driver_register(ðernet_driver);
215 connman_network_driver_unregister(&cable_driver);
222 static void ethernet_exit(void)
224 connman_network_driver_unregister(&cable_driver);
226 connman_device_driver_unregister(ðernet_driver);
229 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
230 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)