* [PATCH v3 1/3] shared/att: Reset fd when disconnected
@ 2018-10-02 8:24 Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 2/3] gatt: Fix attempting to create device on disconnection Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 8:24 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Set att->fd to -1 when considered disconnected.
---
v3: Pass btd_device instead of bt_att since the later may have been
disconnected already.
src/shared/att.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/shared/att.c b/src/shared/att.c
index 8bf3f4611..04577eddd 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -570,6 +570,7 @@ static bool disconnect_cb(struct io *io, void *user_data)
io_destroy(att->io);
att->io = NULL;
+ att->fd = -1;
/* Notify request callbacks */
queue_remove_all(att->req_queue, NULL, NULL, disc_att_send_op);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/3] gatt: Fix attempting to create device on disconnection
2018-10-02 8:24 [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
@ 2018-10-02 8:24 ` Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 3/3] gatt: Fix not cleaning up device state properly Luiz Augusto von Dentz
2018-10-02 11:29 ` [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 8:24 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If ATT is disconnected and the state points to an invalid device it
must have been destroyed in the meantime and should not be recreated.
---
src/gatt-database.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/gatt-database.c b/src/gatt-database.c
index abcf7b759..febc2f840 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -326,8 +326,8 @@ static void att_disconnected(int err, void *user_data)
state->disc_id = 0;
- device = btd_adapter_get_device(state->db->adapter, &state->bdaddr,
- state->bdaddr_type);
+ device = btd_adapter_find_device(state->db->adapter, &state->bdaddr,
+ state->bdaddr_type);
if (!device)
goto remove;
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] gatt: Fix not cleaning up device state properly
2018-10-02 8:24 [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 2/3] gatt: Fix attempting to create device on disconnection Luiz Augusto von Dentz
@ 2018-10-02 8:24 ` Luiz Augusto von Dentz
2018-10-02 11:29 ` [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 8:24 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If the device is removed locally device_free would end up calling
bt_att_unref which won't trigger any disconnect callback necessary
to remove device states.
---
src/device.c | 3 +++
src/gatt-database.c | 28 ++++++++++++++++++++++++++--
src/gatt-database.h | 2 ++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/device.c b/src/device.c
index ef5b8f86a..024e670e0 100644
--- a/src/device.c
+++ b/src/device.c
@@ -580,6 +580,9 @@ static void gatt_server_cleanup(struct btd_device *device)
bt_gatt_server_unref(device->server);
device->server = NULL;
+
+ btd_gatt_database_att_disconnected(
+ btd_adapter_get_database(device->adapter), device);
}
static void attio_cleanup(struct btd_device *device)
diff --git a/src/gatt-database.c b/src/gatt-database.c
index febc2f840..783b692d5 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -242,7 +242,7 @@ static bool dev_state_match(const void *a, const void *b)
}
static struct device_state *
-find_device_state(struct btd_gatt_database *database, bdaddr_t *bdaddr,
+find_device_state(struct btd_gatt_database *database, const bdaddr_t *bdaddr,
uint8_t bdaddr_type)
{
struct device_info dev_info;
@@ -357,8 +357,13 @@ static bool get_dst_info(struct bt_att *att, bdaddr_t *dst, uint8_t *dst_type)
{
GIOChannel *io = NULL;
GError *gerr = NULL;
+ int fd;
- io = g_io_channel_unix_new(bt_att_get_fd(att));
+ fd = bt_att_get_fd(att);
+ if (fd < 0)
+ return false;
+
+ io = g_io_channel_unix_new(fd);
if (!io)
return false;
@@ -3349,6 +3354,25 @@ void btd_gatt_database_att_connected(struct btd_gatt_database *database,
state->pending = NULL;
}
+void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
+ struct btd_device *device)
+{
+ struct device_state *state;
+ const bdaddr_t *addr;
+ uint8_t type;
+
+ DBG("");
+
+ addr = device_get_address(device);
+ type = btd_device_get_bdaddr_type(device);
+
+ state = find_device_state(database, addr, type);
+ if (!state)
+ return;
+
+ att_disconnected(0, state);
+}
+
static void restore_ccc(struct btd_gatt_database *database,
const bdaddr_t *addr, uint8_t addr_type, uint16_t value)
{
diff --git a/src/gatt-database.h b/src/gatt-database.h
index a6c3139c4..a77a0fb20 100644
--- a/src/gatt-database.h
+++ b/src/gatt-database.h
@@ -25,5 +25,7 @@ void btd_gatt_database_destroy(struct btd_gatt_database *database);
struct gatt_db *btd_gatt_database_get_db(struct btd_gatt_database *database);
void btd_gatt_database_att_connected(struct btd_gatt_database *database,
struct bt_att *att);
+void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
+ struct btd_device *device);
void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/3] shared/att: Reset fd when disconnected
2018-10-02 8:24 [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 2/3] gatt: Fix attempting to create device on disconnection Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 3/3] gatt: Fix not cleaning up device state properly Luiz Augusto von Dentz
@ 2018-10-02 11:29 ` Luiz Augusto von Dentz
2018-10-03 7:44 ` Luiz Augusto von Dentz
2 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-02 11:29 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Yunhan Wang, Sukesh Srikakula
On Tue, Oct 2, 2018 at 11:24 AM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Set att->fd to -1 when considered disconnected.
> ---
> v3: Pass btd_device instead of bt_att since the later may have been
> disconnected already.
>
> src/shared/att.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/src/shared/att.c b/src/shared/att.c
> index 8bf3f4611..04577eddd 100644
> --- a/src/shared/att.c
> +++ b/src/shared/att.c
> @@ -570,6 +570,7 @@ static bool disconnect_cb(struct io *io, void *user_data)
>
> io_destroy(att->io);
> att->io = NULL;
> + att->fd = -1;
>
> /* Notify request callbacks */
> queue_remove_all(att->req_queue, NULL, NULL, disc_att_send_op);
> --
> 2.17.1
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/3] shared/att: Reset fd when disconnected
2018-10-02 11:29 ` [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
@ 2018-10-03 7:44 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-10-03 7:44 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Yunhan Wang, Sukesh Srikakula
Hi,
On Tue, Oct 2, 2018 at 2:29 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> On Tue, Oct 2, 2018 at 11:24 AM Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
> >
> > From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> >
> > Set att->fd to -1 when considered disconnected.
> > ---
> > v3: Pass btd_device instead of bt_att since the later may have been
> > disconnected already.
> >
> > src/shared/att.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/src/shared/att.c b/src/shared/att.c
> > index 8bf3f4611..04577eddd 100644
> > --- a/src/shared/att.c
> > +++ b/src/shared/att.c
> > @@ -570,6 +570,7 @@ static bool disconnect_cb(struct io *io, void *user_data)
> >
> > io_destroy(att->io);
> > att->io = NULL;
> > + att->fd = -1;
> >
> > /* Notify request callbacks */
> > queue_remove_all(att->req_queue, NULL, NULL, disc_att_send_op);
> > --
> > 2.17.1
> >
Applied.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-10-03 7:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-02 8:24 [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 2/3] gatt: Fix attempting to create device on disconnection Luiz Augusto von Dentz
2018-10-02 8:24 ` [PATCH v3 3/3] gatt: Fix not cleaning up device state properly Luiz Augusto von Dentz
2018-10-02 11:29 ` [PATCH v3 1/3] shared/att: Reset fd when disconnected Luiz Augusto von Dentz
2018-10-03 7:44 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).