This fixes an error in the proxy_get_role fuction in commit
6f6927236fc35429eecb1b1459ea5e20ab667db8.

The comment was correct as to what we want to accomplish here, however the
programming logic did not match what the comment says. Now it correctly
returns the most preferred role instead of just the first matching role.
---
 plugins/bluetooth.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 924336b..76669c8 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -88,9 +88,10 @@ static bool proxy_get_bool(GDBusProxy *proxy, const char 
*property)
        return value;
 }
 
-static const char* proxy_get_role(GDBusProxy *proxy)
+static const char *proxy_get_role(GDBusProxy *proxy)
 {
-        DBusMessageIter iter, value;
+       DBusMessageIter iter, value;
+       const char *pref = NULL;
 
        if (!proxy)
                return NULL;
@@ -104,20 +105,20 @@ static const char* proxy_get_role(GDBusProxy *proxy)
 
                dbus_message_iter_get_basic(&value, &uuid);
                /*
-                * Order matters here. If a device offers more than one role,
-                * we prefer NAP, then GN, then PANU.
+                * If a device offers more than one role, we prefer NAP,
+                * then GN, then PANU.
                 */
                if (!strcmp(uuid, BLUETOOTH_PAN_NAP))
                        return "nap";
                if (!strcmp(uuid, BLUETOOTH_PAN_GN))
-                       return "gn";
-               if (!strcmp(uuid, BLUETOOTH_PAN_PANU))
-                       return "panu";
+                       pref = "gn";
+               if (!strcmp(uuid, BLUETOOTH_PAN_PANU) && !pref)
+                       pref = "panu";
 
                 dbus_message_iter_next(&value);
         }
 
-       return NULL;
+       return pref;
 }
 
 static int bluetooth_pan_probe(struct connman_network *network)
-- 
1.9.1

_______________________________________________
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman

Reply via email to