All of lore.kernel.org
 help / color / mirror / Atom feed
* Enabling indications/notifications results in wrong sequence of events.
@ 2016-01-20 13:32 Ad Zeevaarders
  2016-01-20 18:10 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Ad Zeevaarders @ 2016-01-20 13:32 UTC (permalink / raw)
  To: linux-bluetooth



Hello everyone,

When using some code from btgatt-client.c for a project of mine, I found that when enabling a value indication/notification on a certain characteristic of a peripheral device I have (Blood pressure meter) the order of events is not linear. I'm using the MGMT API in combination with l2cap sockets and am using btgatt-client.c and btmgmt.c as references. At first I thought it was a problem with my own code, but running the vanilla btgatt-client I found out that:

When enabling notifications, two callbacks are given to the bt_gatt_register_notify method, one to report back if the notification succeeded, and the other one to catch values emitted by the peripheral. The expected order of the callbacks being called is 
1. Notifications/indications success
2. Value A received 
3.Value B received and so on. 

However, the order is actually: 

1. Value A received
2. Notifications/indications success
3. Value A received again
4. Value B received and so on.

My own program starts notifications as soon as GATT Service Discovery is completed. (It calls a StartNotifications method from within that callback actually) and that is also why normal use of btgatt-client does not surface this possible bug; after GATT Service Discovery is completed the user will be prompted for a command again. When I changed some code in btgatt-client.c to immediately start notifications on a characteristic as soon as the GATT Service Discovery completed callback or "ready_cb" was called it exhibited the behavior.

I hope I have been clear and readers will be able to reproduce the error, please let me know what you think.

Thanks for your time and best regards,

Ad Zeevaarders

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Enabling indications/notifications results in wrong sequence of events.
  2016-01-20 13:32 Enabling indications/notifications results in wrong sequence of events Ad Zeevaarders
@ 2016-01-20 18:10 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2016-01-20 18:10 UTC (permalink / raw)
  To: Ad Zeevaarders; +Cc: linux-bluetooth

Hi,

On Wed, Jan 20, 2016 at 3:32 PM, Ad Zeevaarders
<ad.zeevaarders@veynex.com> wrote:
>
>
> Hello everyone,
>
> When using some code from btgatt-client.c for a project of mine, I found that when enabling a value indication/notification on a certain characteristic of a peripheral device I have (Blood pressure meter) the order of events is not linear. I'm using the MGMT API in combination with l2cap sockets and am using btgatt-client.c and btmgmt.c as references. At first I thought it was a problem with my own code, but running the vanilla btgatt-client I found out that:
>
> When enabling notifications, two callbacks are given to the bt_gatt_register_notify method, one to report back if the notification succeeded, and the other one to catch values emitted by the peripheral. The expected order of the callbacks being called is
> 1. Notifications/indications success
> 2. Value A received
> 3.Value B received and so on.
>
> However, the order is actually:
>
> 1. Value A received
> 2. Notifications/indications success
> 3. Value A received again
> 4. Value B received and so on.

Do you have the HCI trace to back this up, I wouldn't be surprise the
value arrive before the notification response, in which we can
probably just assume the write to CCC succeeded anyway.

> My own program starts notifications as soon as GATT Service Discovery is completed. (It calls a StartNotifications method from within that callback actually) and that is also why normal use of btgatt-client does not surface this possible bug; after GATT Service Discovery is completed the user will be prompted for a command again. When I changed some code in btgatt-client.c to immediately start notifications on a characteristic as soon as the GATT Service Discovery completed callback or "ready_cb" was called it exhibited the behavior.

You mean you start notifying before the CCC is written? Well that
explain the sequence above, I guess then it makes sense to assume CCC
write has been accepted otherwise if we don't invoke the callback the
value would be lost. Also note in practice 'blind' notifies might be
discarded so this would just consume power transmitting data that the
remote don't care.

>
> I hope I have been clear and readers will be able to reproduce the error, please let me know what you think.
>
> Thanks for your time and best regards,
>
> Ad Zeevaarders--
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-20 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 13:32 Enabling indications/notifications results in wrong sequence of events Ad Zeevaarders
2016-01-20 18:10 ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.