From a3ad08e36f0c3bd21fb742f09e2754d6bc446641 Mon Sep 17 00:00:00 2001 From: "guoqiang.liu" Date: Sat, 12 Oct 2013 11:21:03 +0800 Subject: Tethering: Add gadget device rtnl handler The technology will not power on despite gadget interface is up, add rtnl handler to fix it. Change-Id: I25409db8793fd79c1e6b1248a7d919701890ed4d --- plugins/ethernet.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/plugins/ethernet.c b/plugins/ethernet.c index 4f23e752..aa4edfae 100644 --- a/plugins/ethernet.c +++ b/plugins/ethernet.c @@ -226,14 +226,57 @@ 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) { -- cgit v1.2.3