Fix the malfunction of bonding 03/207603/1
authorinjun.yang <injun.yang@samsung.com>
Mon, 1 Apr 2019 00:27:05 +0000 (09:27 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 10 Jun 2019 02:42:38 +0000 (11:42 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] When app request bt_device_create_bond(), host initiate BT pairing instead of BLE pairing
[Cause & Measure] Till now, bluez didn't check the link status.
 Even though BLE connected, bluez initiate BT pairing.
 To prevent the malfunction, bluez will check the link type also.
[Checking Method] Initiate pairing

[Team] IoT Hub
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I5dbcc0a827ccc566b15490d3f1edc31acbac949c
Signed-off-by: injun.yang <injun.yang@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
src/device.c

index 41a6dae..7bca3e6 100644 (file)
@@ -3222,6 +3222,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        uint8_t conn_type;
        bool connect_le = FALSE;
+       uint8_t link_type = DEV_CONNECTED_NONE;
 #endif
        int err;
 
@@ -3240,17 +3241,29 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        if (conn_type == DEV_CONN_DEFAULT) {
-               if (device_is_bonded(device, DEV_CONN_BREDR))
-                       return btd_error_already_exists(msg);
-               else if (device_is_bonded(device, DEV_CONN_LE))
-                       return btd_error_already_exists(msg);
+               link_type = device_get_connected_state(device);
 
-               if (device->bredr)
-                       conn_type = DEV_CONN_BREDR;
-               else if (device->le)
-                       conn_type = DEV_CONN_LE;
-               else
+               if (link_type == DEV_CONNECTED_BREDR) {
+                       if (device_is_bonded(device, DEV_CONN_BREDR))
+                               return btd_error_already_exists(msg);
                        conn_type = DEV_CONN_BREDR;
+               } else if (link_type == DEV_CONNECTED_LE) {
+                        if (device_is_bonded(device, DEV_CONN_LE))
+                               return btd_error_already_exists(msg);
+                        conn_type = DEV_CONN_LE;
+               } else {
+                       if (device_is_bonded(device, DEV_CONN_BREDR))
+                               return btd_error_already_exists(msg);
+                       else if (device_is_bonded(device, DEV_CONN_LE))
+                               return btd_error_already_exists(msg);
+
+                       if (device->bredr)
+                               conn_type = DEV_CONN_BREDR;
+                       else if (device->le)
+                               conn_type = DEV_CONN_LE;
+                       else
+                               conn_type = DEV_CONN_BREDR;
+               }
        } else {
                if (device_is_bonded(device, conn_type))
                        return btd_error_already_exists(msg);
@@ -3271,6 +3284,8 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 #endif
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       DBG("conn_type %d, link_type %d, bdaddr_type %d, device->bredr %d",
+                       conn_type, link_type, bdaddr_type, device->bredr);
        if (conn_type == DEV_CONN_LE &&
            (device_is_bredrle(device) || bdaddr_type != BDADDR_BREDR)) {
                DBG("LE Connect request");