From: Luiz Augusto von Dentz Date: Wed, 8 Mar 2023 00:49:38 +0000 (-0800) Subject: gatt: Fix creating duplicated objects X-Git-Tag: accepted/tizen/unified/20240117.163238~318 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d29dd5bf37a86e8d7df52d9e819bd6988582c26;p=platform%2Fupstream%2Fbluez.git gatt: Fix creating duplicated objects This checks cid before attempting to create device, if the device is using an RPA it could be that the MGMT event has not been processed yet which would lead to create a second copy of the same device using its identity address. --- diff --git a/src/gatt-database.c b/src/gatt-database.c index 9e441ee..068e11b 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -700,6 +700,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) struct btd_device *device; uint8_t dst_type; bdaddr_t src, dst; + uint16_t cid; if (gerr) { error("%s", gerr->message); @@ -709,6 +710,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) bt_io_get(io, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_DEST_BDADDR, &dst, BT_IO_OPT_DEST_TYPE, &dst_type, + BT_IO_OPT_CID, &cid, BT_IO_OPT_INVALID); if (gerr) { error("bt_io_get: %s", gerr->message); @@ -723,9 +725,21 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) if (!adapter) return; - device = btd_adapter_get_device(adapter, &dst, dst_type); - if (!device) + /* Check cid before attempting to create device, if the device is using + * an RPA it could be that the MGMT event has not been processed yet + * which would lead to create a second copy of the same device using its + * identity address. + */ + if (cid == BT_ATT_CID) + device = btd_adapter_get_device(adapter, &dst, dst_type); + else + device = btd_adapter_find_device(adapter, &dst, dst_type); + + if (!device) { + error("Unable to find device, dropping connection attempt"); + g_io_channel_shutdown(io, FALSE, NULL); return; + } device_attach_att(device, io);