summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2023-09-11 15:30:01 -0700
committerAyush Garg <ayush.garg@samsung.com>2024-01-05 19:04:04 +0530
commit5dead2dcaab438095f4885eed19250d173ba64c9 (patch)
treefcf35609179ed56c4195bea407c35a1f522bdad0
parent017a91f7e97297654122005eb78092a64081a3c9 (diff)
downloadbluez-5dead2dcaab438095f4885eed19250d173ba64c9.tar.gz
bluez-5dead2dcaab438095f4885eed19250d173ba64c9.tar.bz2
bluez-5dead2dcaab438095f4885eed19250d173ba64c9.zip
device: Fix not handling initiator properly
Previously initiator would be set whenever a central key was found which turns out to be unreliable besides the MGMT New Connection event does in fact inform if the connection was initiated locally or not. Fixes: https://github.com/bluez/bluez/issues/598
-rw-r--r--src/adapter.c10
-rw-r--r--src/device.c15
-rw-r--r--src/device.h3
3 files changed, 13 insertions, 15 deletions
diff --git a/src/adapter.c b/src/adapter.c
index ed588cc0..a7a5fe9a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -10080,9 +10080,10 @@ static void adapter_remove_device(struct btd_adapter *adapter,
static void adapter_add_connection(struct btd_adapter *adapter,
struct btd_device *device,
- uint8_t bdaddr_type)
+ uint8_t bdaddr_type,
+ uint32_t flags)
{
- device_add_connection(device, bdaddr_type);
+ device_add_connection(device, bdaddr_type, flags);
if (g_slist_find(adapter->connections, device)) {
btd_error(adapter->dev_id,
@@ -10135,7 +10136,7 @@ static void get_connections_complete(uint8_t status, uint16_t length,
device = btd_adapter_get_device(adapter, &addr->bdaddr,
addr->type);
if (device)
- adapter_add_connection(adapter, device, addr->type);
+ adapter_add_connection(adapter, device, addr->type, 0);
}
}
@@ -15524,7 +15525,8 @@ static void connected_callback(uint16_t index, uint16_t length,
if (eir_data.class != 0)
device_set_class(device, eir_data.class);
- adapter_add_connection(adapter, device, ev->addr.type);
+ adapter_add_connection(adapter, device, ev->addr.type,
+ le32_to_cpu(ev->flags));
name_known = device_name_known(device);
diff --git a/src/device.c b/src/device.c
index 41d2d338..270053d9 100644
--- a/src/device.c
+++ b/src/device.c
@@ -474,16 +474,9 @@ static struct bearer_state *get_state(struct btd_device *dev,
bool btd_device_is_initiator(struct btd_device *dev)
{
- if (dev->le_state.connected) {
- /* Mark as initiator if not set yet and auto-connect flag is
- * set and LTK key is for a peripheral.
- */
- if (!dev->le_state.initiator && dev->auto_connect &&
- dev->ltk && !dev->ltk->central)
- dev->le_state.initiator = true;
-
+ if (dev->le_state.connected)
return dev->le_state.initiator;
- } else if (dev->bredr_state.connected)
+ else if (dev->bredr_state.connected)
return dev->bredr_state.initiator;
return dev->att_io ? true : false;
@@ -5651,7 +5644,8 @@ static void clear_temporary_timer(struct btd_device *dev)
}
}
-void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type)
+void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type,
+ uint32_t flags)
{
struct bearer_state *state = get_state(dev, bdaddr_type);
@@ -5678,6 +5672,7 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type)
device_set_le_support(dev, bdaddr_type);
state->connected = true;
+ state->initiator = flags & BIT(3);
#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
if (dev->le_state.connected && dev->bredr_state.connected)
diff --git a/src/device.h b/src/device.h
index 7abd023f..11a60d23 100644
--- a/src/device.h
+++ b/src/device.h
@@ -172,7 +172,8 @@ gboolean device_is_authenticating(struct btd_device *dev, uint8_t bdaddr_type);
#else
gboolean device_is_authenticating(struct btd_device *device);
#endif
-void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type);
+void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type,
+ uint32_t flags);
void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
bool *remove);
void device_request_disconnect(struct btd_device *device, DBusMessage *msg);