OSDN Git Service

Fix pairing process even if the ACL gets dropped before successful SDP
authorJohan Hedberg <johan.hedberg@nokia.com>
Mon, 1 Jun 2009 14:01:28 +0000 (17:01 +0300)
committerJohan Hedberg <johan.hedberg@nokia.com>
Mon, 1 Jun 2009 14:01:28 +0000 (17:01 +0300)
CreatePairedDevice should succeed if the pairing succeeds, but return only
after the SDP discovery is complete (either a success or a failure). Right
now the logic of the temporary flag and CancelDeviceCreation was such that
the device would be removed in the case of a successful pairing if the SDP
part failed.

This patch fixes the issue by clearing the temporary flag imediately after
a successful pairing but still allows CancelDeviceCreation to be called
after the pairing is complete but SDP isn't (i.e. Create*Device hasn't
returned anything yet). A new helper function for CancelDeviceCreation
called device_is_creating was added to allow easy checking of an ongoing
device creation.

src/adapter.c
src/device.c
src/device.h

index 0dae860..a45765d 100644 (file)
@@ -1394,15 +1394,16 @@ static DBusMessage *cancel_device_creation(DBusConnection *conn,
                return invalid_args(msg);
 
        device = adapter_find_device(adapter, address);
-       if (!device || !device_is_temporary(device))
+       if (!device || !device_is_creating(device, NULL))
                return g_dbus_create_error(msg,
                                ERROR_INTERFACE ".NotInProgress",
                                "Device creation not in progress");
 
-       if (device_is_bonding(device, NULL) &&
-                       !device_is_bonding(device, sender))
+       if (!device_is_creating(device, sender))
                return not_authorized(msg);
 
+       device_set_temporary(device, FALSE);
+
        if (device_is_connected(device)) {
                device_request_disconnect(device, msg);
                return NULL;
index 27f0bf8..d84e667 100644 (file)
@@ -1936,6 +1936,8 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
        if (device->renewed_key)
                return;
 
+       device_set_temporary(device, FALSE);
+
        /* If we were initiators start service discovery immediately.
         * However if the other end was the initator wait a few seconds
         * before SDP. This is due to potential IOP issues if the other
@@ -1950,11 +1952,9 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
 
                device_browse(device, bonding->conn, bonding->msg,
                                NULL, FALSE);
-       } else {
-               /* If not the initiator consider the device permanent otherwise
-                * wait to service discover to complete */
-               device_set_temporary(device, FALSE);
 
+               bonding_request_free(bonding);
+       } else {
                if (!device->browse && !device->discov_timer &&
                                main_opts.reverse_sdp) {
                        /* If we are not initiators and there is no currently
@@ -1970,14 +1970,35 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)
 
        device_set_paired(device, TRUE);
 
-       bonding_request_free(bonding);
-
        return;
 
 failed:
        device_cancel_bonding(device, status);
 }
 
+gboolean device_is_creating(struct btd_device *device, const char *sender)
+{
+       DBusMessage *msg;
+
+       if (device->bonding && device->bonding->msg)
+               msg = device->bonding->msg;
+       else if (device->browse && device->browse->msg)
+               msg = device->browse->msg;
+       else
+               return FALSE;
+
+       if (!dbus_message_is_method_call(msg, ADAPTER_INTERFACE,
+                                               "CreatePairedDevice") &&
+                       !dbus_message_is_method_call(msg, ADAPTER_INTERFACE,
+                                                       "CreateDevice"))
+               return FALSE;
+
+       if (sender == NULL)
+               return TRUE;
+
+       return g_str_equal(sender, dbus_message_get_sender(msg));
+}
+
 gboolean device_is_bonding(struct btd_device *device, const char *sender)
 {
        struct bonding_req *bonding = device->bonding;
index ac3a095..54c3e64 100644 (file)
@@ -67,6 +67,7 @@ DBusMessage *device_create_bonding(struct btd_device *device,
 void device_remove_bondind(struct btd_device *device, DBusConnection *connection);
 void device_bonding_complete(struct btd_device *device, uint8_t status);
 void device_simple_pairing_complete(struct btd_device *device, uint8_t status);
+gboolean device_is_creating(struct btd_device *device, const char *sender);
 gboolean device_is_bonding(struct btd_device *device, const char *sender);
 void device_cancel_bonding(struct btd_device *device, uint8_t status);
 int device_request_authentication(struct btd_device *device, auth_type_t type,