diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2008-09-25 17:46:18 -0700 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2008-09-25 17:46:18 -0700 |
commit | 2ba670eae0d7d0d57160b7e5bd387079f86d933c (patch) | |
tree | c293f872adf188b9ecbc56c42f179fddeac6ff85 /src | |
parent | 5db4580312522b870068c89f5064d1c832075434 (diff) |
Clean up authentication and service discovery initiation code
Diffstat (limited to 'src')
-rw-r--r-- | src/dbus-hci.c | 43 | ||||
-rw-r--r-- | src/device.c | 32 |
2 files changed, 44 insertions, 31 deletions
diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 8332fb4d..e003e084 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -505,7 +505,6 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, DBusMessage *reply; struct btd_device *device; struct bonding_request_info *bonding; - gboolean paired = TRUE; struct pending_auth_info *auth; debug("hcid_dbus_bonding_process_complete: status=%02x", status); @@ -520,11 +519,23 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, bonding = adapter_get_bonding_info(adapter); + if (status == 0) { + device = adapter_get_device(connection, adapter, paddr); + if (!device) { + /* This should really only happen if we run out of + * memory */ + error("Unable to get device object!"); + status = HCI_REJECTED_LIMITED_RESOURCES; + } + } + if (status && bonding) bonding->hci_status = status; auth = adapter_find_auth_request(adapter, peer); if (!auth) { + /* This means that there was no pending PIN or SSP token request + * from the controller, i.e. this is not a new pairing */ debug("hcid_dbus_bonding_process_complete: no pending auth request"); goto proceed; } @@ -534,14 +545,10 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, adapter_remove_auth_request(adapter, peer); - if (status) - goto proceed; - - device = adapter_get_device(connection, adapter, paddr); - if (device) { - const gchar *dev_path; - - debug("hcid_dbus_bonding_process_complete: removing temporary flag"); + /* If this is a new pairing send the appropriate signal for it */ + if (status == 0) { + const char *dev_path; + dbus_bool_t paired = TRUE; device_set_temporary(device, FALSE); dev_path = device_get_path(device); @@ -563,16 +570,14 @@ proceed: goto cleanup; } - if ((device = adapter_find_device(adapter, paddr))) { - if (status) { - reply = new_authentication_return(bonding->msg, status); - dbus_connection_send(connection, reply, NULL); - dbus_message_unref(reply); - } else { - device_set_temporary(device, FALSE); - device_browse(device, bonding->conn, - bonding->msg, NULL); - } + if (status) { + reply = new_authentication_return(bonding->msg, status); + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + } else { + device_set_temporary(device, FALSE); + device_browse(device, bonding->conn, + bonding->msg, NULL); } cleanup: diff --git a/src/device.c b/src/device.c index e7f1c1fa..9b28ae41 100644 --- a/src/device.c +++ b/src/device.c @@ -979,24 +979,28 @@ static void search_cb(sdp_list_t *recs, int err, gpointer user_data) services_changed(req); proceed: - /* Store the device's profiles in the filesystem */ store(device); - if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE, - "DiscoverServices")) { - discover_device_reply(req, req->records); - goto cleanup; - } + if (req->msg) { + if (dbus_message_is_method_call(req->msg, DEVICE_INTERFACE, + "DiscoverServices")) { + discover_device_reply(req, req->records); + goto cleanup; + } - g_dbus_emit_signal(req->conn, dbus_message_get_path(req->msg), + g_dbus_emit_signal(req->conn, dbus_message_get_path(req->msg), ADAPTER_INTERFACE, "DeviceCreated", DBUS_TYPE_OBJECT_PATH, &device->path, DBUS_TYPE_INVALID); + } /* Update device list */ adapter_update_devices(device->adapter); + if (!req->msg) + goto cleanup; + /* Reply create device request */ reply = dbus_message_new_method_return(req->msg); if (!reply) @@ -1018,8 +1022,10 @@ cleanup: device->discov_requestor = NULL; } - dbus_message_unref(req->msg); - dbus_connection_unref(req->conn); + if (req->msg) + dbus_message_unref(req->msg); + if (req->conn) + dbus_connection_unref(req->conn); g_slist_free(req->uuids_added); g_slist_free(req->uuids_removed); if (req->records) @@ -1097,7 +1103,7 @@ static void init_browse(struct browse_req *req) if (uuid16 == uuid_list[j]) continue; } - + } /* ... and of UUIDs another driver already asked for */ if (g_slist_find_custom(req->uuids, driver->uuids[i], @@ -1129,8 +1135,10 @@ int device_browse(struct btd_device *device, DBusConnection *conn, adapter_get_address(adapter, &src); req = g_new0(struct browse_req, 1); - req->conn = dbus_connection_ref(conn); - req->msg = dbus_message_ref(msg); + if (conn && msg) { + req->conn = dbus_connection_ref(conn); + req->msg = dbus_message_ref(msg); + } req->device = device; if (search) { |