Remove obsolete file.
[connman] / plugins / ethernet.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <net/if.h>
28
29 #ifndef IFF_LOWER_UP
30 #define IFF_LOWER_UP    0x10000
31 #endif
32
33 #include <glib.h>
34
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>
41
42 struct ethernet_data {
43         int index;
44         unsigned flags;
45         unsigned int watch;
46 };
47
48 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
49 {
50         struct connman_device *device = user_data;
51         struct ethernet_data *ethernet = connman_device_get_data(device);
52
53         DBG("index %d flags %d change %d", ethernet->index, flags, change);
54
55         if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
56                 if (flags & IFF_UP) {
57                         DBG("power on");
58                         connman_device_set_powered(device, TRUE);
59                 } else {
60                         DBG("power off");
61                         connman_device_set_powered(device, FALSE);
62                 }
63         }
64
65         if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
66                 if (flags & IFF_LOWER_UP) {
67                         DBG("carrier on");
68                         connman_device_set_carrier(device, TRUE);
69                 } else {
70                         DBG("carrier off");
71                         connman_device_set_carrier(device, FALSE);
72                 }
73         }
74
75         ethernet->flags = flags;
76 }
77
78 static int ethernet_probe(struct connman_device *device)
79 {
80         struct ethernet_data *ethernet;
81
82         DBG("device %p", device);
83
84         ethernet = g_try_new0(struct ethernet_data, 1);
85         if (ethernet == NULL)
86                 return -ENOMEM;
87
88         connman_device_set_data(device, ethernet);
89
90         ethernet->index = connman_device_get_index(device);
91         ethernet->flags = 0;
92
93         ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
94                                                 ethernet_newlink, device);
95
96         connman_rtnl_send_getlink();
97
98         return 0;
99 }
100
101 static void ethernet_remove(struct connman_device *device)
102 {
103         struct ethernet_data *ethernet = connman_device_get_data(device);
104
105         DBG("device %p", device);
106
107         connman_device_set_data(device, NULL);
108
109         connman_rtnl_remove_watch(ethernet->watch);
110
111         g_free(ethernet);
112 }
113
114 static int ethernet_enable(struct connman_device *device)
115 {
116         struct ethernet_data *ethernet = connman_device_get_data(device);
117
118         DBG("device %p", device);
119
120         return connman_inet_ifup(ethernet->index);
121 }
122
123 static int ethernet_disable(struct connman_device *device)
124 {
125         struct ethernet_data *ethernet = connman_device_get_data(device);
126
127         DBG("device %p", device);
128
129         return connman_inet_ifdown(ethernet->index);
130 }
131
132 static struct connman_device_driver ethernet_driver = {
133         .name           = "ethernet",
134         .type           = CONNMAN_DEVICE_TYPE_ETHERNET,
135         .probe          = ethernet_probe,
136         .remove         = ethernet_remove,
137         .enable         = ethernet_enable,
138         .disable        = ethernet_disable,
139 };
140
141 static int ethernet_init(void)
142 {
143         return connman_device_driver_register(&ethernet_driver);
144 }
145
146 static void ethernet_exit(void)
147 {
148         connman_device_driver_unregister(&ethernet_driver);
149 }
150
151 CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
152                 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ethernet_init, ethernet_exit)