Skip to content
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

Bluetooth: conn: Expose simplified connection state in get_info #42540

Merged
merged 5 commits into from
Mar 25, 2022

Conversation

Thalley
Copy link
Collaborator

@Thalley Thalley commented Feb 7, 2022

Add a state field in struct bt_conn_info that is a simplified
version of the internal state value (bt_conn_state_t).

This should provide an application to better determine the state
of the connection whne calling bt_conn_get_info, in case the
application does not keep track of the state itself.

Signed-off-by: Emil Gydesen [email protected]

fixes #28009

@github-actions github-actions bot added area: API Changes to public APIs area: Bluetooth area: Bluetooth Host Bluetooth Host (excluding BR/EDR) labels Feb 7, 2022
/** Channel disconnected */
BT_CONN_STATE_DISCONNECTED,
/** Channel in connecting state */
BT_CONN_STATE_CONNECT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to add "ING" -> BT_CONN_STATE_CONNECTING

  • That is what the documentation says
  • It ensures that the name is not a subset of the next name (CONNECTED).

Ditto for DISCONNECT -> DISCONNECTING

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the names were originally chosen to reflect those used by Linux: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/net/bluetooth/bluetooth.h#n222

However, I can see that we're anyway not following these 1:1, so I'm not opposed to changing them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not opposed to changing them either. If we decide to change them, so that change also be applied to the L2CAP, ISO and internal BT CONN states?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it'd make sense to be consistent with the naming across the various layers and protocols

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add additional commit to fix that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that additional commit ever added?
I would like to have it. (But if we decided not to do that, I will approve as is.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has not been added yet, will do that soon™

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it now. Will do the L2CAP renaming in a different PR as that requires an API change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a state field in struct bt_conn_info that is a simplified
version of the internal state value (bt_conn_state_t).

This should provide an application to better determine the state
of the connection whne calling bt_conn_get_info, in case the
application does not keep track of the state itself.

Signed-off-by: Emil Gydesen <[email protected]>
Add `ing` to the `BT_CONN_CONNECT` and `BT_CONN_DISCONNECT`
states, so that the name better matches the actual state.

Signed-off-by: Emil Gydesen <[email protected]>
asbjornsabo
asbjornsabo previously approved these changes Feb 22, 2022
Add `ing` to the `BT_ISO_CONNECT` and `BT_ISO_DISCONNECT`
states, so that the name better matches the actual state.

Signed-off-by: Emil Gydesen <[email protected]>
Change from BT_ISO_<state> to BT_ISO_STATE_<state>
to make the value more descriptive.

Signed-off-by: Emil Gydesen <[email protected]>
Add an enum for the state field, to provide more
semantics to it.

Signed-off-by: Emil Gydesen <[email protected]>
@Thalley
Copy link
Collaborator Author

Thalley commented Feb 22, 2022

@jhedberg @asbjornsabo Changing it from CONNECT to CONNECTING isn't hard, but it will require an API change to L2CAP if we want it to be the same.

I've also updated ISO to use the same naming scheme as introduced by bt_conn_state

@@ -114,7 +114,7 @@ struct bt_iso_chan {
struct bt_iso_chan_ops *ops;
/** Channel QoS reference */
struct bt_iso_chan_qos *qos;
uint8_t state;
enum bt_iso_state state;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that you’re increasing the struct member size here. We’ve used packed enums in some places where it matters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the size of the enum should stay at 8-bit (given the possible values), right?

In any case, this value is for the host only, and the size of it isn't used for any size-specific fields.

I can __packed it, but I thought we generally wanted to avoid that in public APIs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK it’s always promoted to word size if you don’t use packed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, not an issue if it’s not critical to compact the struct here

Copy link
Collaborator Author

@Thalley Thalley Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK it’s always promoted to word size if you don’t use packed.

From what I can tell, that's implementation (compiler) specific, and the only requirement is that an enum shall be able hold value up to values representable by an int.

In any case, this a minor case and I suggest to leave as is. I like the idea of using named enums as fields in the public API, as it gives a direct reference to values that may be used in the field

@Thalley
Copy link
Collaborator Author

Thalley commented Mar 25, 2022

@jhedberg Will you please re-review?

@carlescufi carlescufi merged commit fe91c1d into zephyrproject-rtos:main Mar 25, 2022
@Thalley Thalley deleted the conn_info_state branch July 8, 2022 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Bluetooth Audio area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add connection status to the connection info
5 participants