Tethering: Add gadget device rtnl handler 36/11436/1
authorguoqiang.liu <guoqiang.liu@archermind.com>
Sat, 12 Oct 2013 03:21:03 +0000 (11:21 +0800)
committerZhang zhengguang <zhengguang.zhang@intel.com>
Mon, 28 Oct 2013 05:22:51 +0000 (13:22 +0800)
The technology will not power on despite gadget interface is
up, add rtnl handler to fix it.

Change-Id: I25409db8793fd79c1e6b1248a7d919701890ed4d

plugins/ethernet.c

index 4f23e75..aa4edfa 100644 (file)
@@ -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)
 {