-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Notification enabled before connection #13316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Vudentz any thoughts on this one? |
The L2CAP needs to be initialized properly in order to start receiving request on the channels, so changing the order is not really an option, besides the use of BT_GATT_CCC is recommended only when the user don't need to descriminate the connections thus why the callback don't have a connection parameter since the application shall be passing NULL to bt_gatt_notify/bt_gatt_indicate and the stack will properly propagate the notifications for the connected peers which had it enabled. We could perhaps add the connection which first change the consolidated setting but the application won't see other connections which just happen to have the same configuration, it is just the first connection to enable and the last to disable that triggers the callback just to inform when the application shall be notifying/indicating or not. A second option is to delay the enabling the changed callback, though with that applications won't be able to react to new connections as quickly as they used to be. |
I tried solving this issue and came up with the following change: Basically, it synchronizes connected callbacks with bt_gatt_connected function, which triggers CCC changed callbacks. @Vudentz, is it acceptable for you or do you see any side effects with this approach (apart from the mentioned delay)? |
@kapi-no That pehaps is not too bad, I though bt_gatt_connected was doing some context initialization but that is done in bt_att_connected so all it is pushing back is CCC logic which perhaps is ok. We could perhaps add some code to initialize the CCC if the application start submitting GATT procedures, though perhaps that is no necessary since those procedures are most likely GATT client since notification/indiction are controlled via CCC. That said Id like to understand why does the application needs to know who is connected on the CCC callback, perhaps that is something we didn't envision when creating that API, or it is the same situation of mesh control points which do need to know the connections in order to react properly. |
@Vudentz , one example can a HID device that is simultaneously connected to several hosts (all of which enabled notifications) and allows user to select to which host HID reports will go to. In short application must know which host enabled notifications (i.e. which hosts are ready to received data) and must be able to target a specific host on it's level (i.e. we cannot assume that stack will select a correct host for us). |
Well, the proposed change only fixes the order of callbacks received by the application: the connected callback should precede ccc_changed callback. I opened a PR for it, where we can discuss further details: As you also noticed, we would like to modify ccc_changed API to include connection object as an additional callback parameter. The reason for it is to better target notification's recipients (GATT clients). We would like to be able to choose a specific |
@kapi-no , the issue is only for the order but all-in-all this two things are connected. |
Well even if we introduce a conn to the CCC callback you had still do the mapping with the actual connection which are enabled to receive notifications.
I supose this means the device would not even be connected, or there is a reason to connect if you won't send any data to them? Or there is some other limitation we are not aware of? Perhaps not supporting directed advertisements? |
Hi @Vudentz , example can be a seamless transition between hosts. You start connection to host 2 while maintaining connection to host 1. You switch data flow to host 2 only after it is connected and ready to receive data. I know some companies may want to have this model. |
Right, here are some options that I can think of:
Both 1 and 2 avoid having to have the application managing connections directly, but option 2 may break the API of bt_gatt_notify since there is no struct to append new fields like in bt_gatt_indicate. |
We need to reopen this one as we see problem with it. |
Describe the bug
Bond peripheral device to Moto G5 (Android 8.1.0). Reboot device which will reconnect.
On the log I observe that before connection callback is received I get callback about notification being enabled.
CCC changes are notified from channel ops callback called from
bt_l2cap_connected
. This last function is called frombt_conn_set_state
onBT_CONN_CONNECTED
state. Now note thatnotify_connected
is called from the same place but afterbt_l2cap_connected
. This explains why information about callback is sent to application after information about notification being enabled.To Reproduce
Described above.
Impact
Application does not know which connection ccc change relates to as there is no
conn
argument in the callback.Screenshots or console output
Environment (please complete the following information):
ncs zephyr
236ec2d2553536835c76dff84adcb188309eaf90
zephyr
dee63e20
Additional context
I this it worked in the past... although I see no changes related to this done recently. Maybe something else changed or this was overlooked...
The text was updated successfully, but these errors were encountered: