From: "guoqiang.liu" <[email protected]>
Gadget technology will not update despite gadget interface state
changed. at the same times, the gadget interface will not up/down
even enable/disable gadget technology.
Here initiative up/down the interface when enable/disable gadget
technology, and monitor rtnl message to update gadget technology
power state.
---
plugins/ethernet.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 51 insertions(+), 2 deletions(-)
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index 260d32c..90a3da1 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -226,24 +226,73 @@ static struct connman_device_driver ethernet_driver = {
.disable = ethernet_disable,
};
+static void gadget_newlink(unsigned flags, unsigned change, void *user_data)
+{
+ struct connman_device *device = user_data;
+ struct ethernet_data *ethernet = connman_device_get_data(device);
+
+ DBG("index %d flags %d change %d", ethernet->index, flags, change);
+
+ if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
+ if (flags & IFF_UP) {
+ DBG("power on");
+ connman_device_set_powered(device, true);
+ } else {
+ DBG("power off");
+ connman_device_set_powered(device, false);
+ }
+ }
+
+ ethernet->flags = flags;
+}
+
static int gadget_probe(struct connman_device *device)
{
+ struct ethernet_data *ethernet;
+
DBG("device %p", device);
+
+ ethernet = g_try_new0(struct ethernet_data, 1);
+ if (ethernet == NULL)
+ return -ENOMEM;
+
+ connman_device_set_data(device, ethernet);
+
+ ethernet->index = connman_device_get_index(device);
+ ethernet->flags = 0;
+
+ ethernet->watch = connman_rtnl_add_newlink_watch(ethernet->index,
+ gadget_newlink, device);
+
return 0;
}
static void gadget_remove(struct connman_device *device)
{
+ struct ethernet_data *ethernet = connman_device_get_data(device);
+
DBG("device %p", device);
+
+ connman_device_set_data(device, NULL);
+
+ connman_rtnl_remove_watch(ethernet->watch);
+
+ g_free(ethernet);
}
static int gadget_enable(struct connman_device *device)
{
+ struct ethernet_data *ethernet = connman_device_get_data(device);
+
DBG("device %p", device);
- return 0;
+
+ return connman_inet_ifup(ethernet->index);
}
static int gadget_disable(struct connman_device *device)
{
+ struct ethernet_data *ethernet = connman_device_get_data(device);
+
DBG("device %p", device);
- return 0;
+
+ return connman_inet_ifdown(ethernet->index);
}
static struct connman_device_driver gadget_driver = {
--
1.7.9.5
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman