From 681e50c618d246483728bca6628a18c1c44c5b36 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 5 Sep 2008 15:37:54 -0300 Subject: Fix problem which prevents drivers from being probed. --- src/device.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 2bc50711..1cf260ec 100644 --- a/src/device.c +++ b/src/device.c @@ -87,6 +87,7 @@ struct browse_req { struct btd_device *device; GSList *uuids_added; GSList *uuids_removed; + sdp_list_t *records; int search_uuid; gboolean browse; }; @@ -776,6 +777,7 @@ static void update_services(struct browse_req *req, sdp_list_t *recs) for (seq = recs; seq; seq = seq->next) { sdp_record_t *rec = (sdp_record_t *) seq->data; + sdp_buf_t pdu; sdp_list_t *svcclass = NULL; gchar *uuid_str; GSList *l; @@ -792,6 +794,16 @@ static void update_services(struct browse_req *req, sdp_list_t *recs) if (!uuid_str) continue; + /* Copy record */ + if (sdp_gen_record_pdu(rec, &pdu) == 0) { + sdp_record_t *record; + int scanned; + + record = sdp_extract_pdu(pdu.data, pdu.data_size, + &scanned); + req->records = sdp_list_append(req->records, record); + } + l = g_slist_find_custom(device->uuids, uuid_str, (GCompareFunc) strcmp); if (!l) @@ -837,8 +849,11 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data) DBusMessage *reply; const gchar *source = adapter_get_address(adapter); - if (err < 0) + if (err < 0) { + error("%s: error updating services: %s (%d)", + device->path, strerror(-err), -err); goto proceed; + } update_services(req, recs); @@ -856,27 +871,30 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data) probe: - if (!req->uuids_added && !req->uuids_removed) + if (!req->uuids_added && !req->uuids_removed) { + debug("%s: No service found", device->path); goto proceed; + } /* Probe matching drivers for services added */ if (req->uuids_added) - device_probe_drivers(device, req->uuids_added, recs); + device_probe_drivers(device, req->uuids_added, req->records); /* Remove drivers for services removed */ if (req->uuids_removed) - device_remove_drivers(device, req->uuids_removed, recs); - - /* Store the device's profiles in the filesystem */ - store(device); + device_remove_drivers(device, req->uuids_removed, req->records); /* Propagate services changes */ 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, recs); + discover_device_reply(req, req->records); goto cleanup; } @@ -910,6 +928,8 @@ cleanup: dbus_connection_unref(req->conn); g_slist_free(req->uuids_added); g_slist_free(req->uuids_removed); + if (req->records) + sdp_list_free(req->records, (sdp_free_func_t) sdp_record_free); g_free(req); } -- cgit From 37a7d2aba17bcb47a3e9bfba78ad23a8a3cbe420 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 5 Sep 2008 23:05:30 +0300 Subject: Check for duplicate records when discovering services --- src/device.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 1cf260ec..3476ec06 100644 --- a/src/device.c +++ b/src/device.c @@ -787,13 +787,19 @@ static void update_services(struct browse_req *req, sdp_list_t *recs) if (sdp_get_service_classes(rec, &svcclass) < 0) continue; - store_record(src, dst, rec); /* Extract the first element and skip the remainning */ uuid_str = bt_uuid2string(svcclass->data); if (!uuid_str) continue; + /* Check for duplicates */ + if (g_slist_find_custom(req->uuids_added, uuid_str, + (GCompareFunc) strcmp)) + continue; + + store_record(src, dst, rec); + /* Copy record */ if (sdp_gen_record_pdu(rec, &pdu) == 0) { sdp_record_t *record; -- cgit From 8b2e688eaf5b71006c72cf91a8e4df3c0c41c306 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 5 Sep 2008 23:31:31 +0300 Subject: Check for duplicate record handles and not UUIDs --- src/device.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 3476ec06..65b68e2f 100644 --- a/src/device.c +++ b/src/device.c @@ -767,6 +767,14 @@ static void services_changed(struct browse_req *req) g_free(uuids); } +static int rec_cmp(const void *a, const void *b) +{ + const sdp_record_t *r1 = a; + const sdp_record_t *r2 = b; + + return r1->handle - r2->handle; +} + static void update_services(struct browse_req *req, sdp_list_t *recs) { struct btd_device *device = req->device; @@ -794,8 +802,7 @@ static void update_services(struct browse_req *req, sdp_list_t *recs) continue; /* Check for duplicates */ - if (g_slist_find_custom(req->uuids_added, uuid_str, - (GCompareFunc) strcmp)) + if (sdp_list_find(req->records, rec, rec_cmp)) continue; store_record(src, dst, rec); -- cgit