-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Conversation
bb516d6
to
bb06dd6
Compare
include/bluetooth/conn.h
Outdated
/** Channel disconnected */ | ||
BT_CONN_STATE_DISCONNECTED, | ||
/** Channel in connecting state */ | ||
BT_CONN_STATE_CONNECT, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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™
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bb06dd6
to
ccbd0db
Compare
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]>
ccbd0db
to
d9e7824
Compare
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]>
@jhedberg @asbjornsabo Changing it from I've also updated ISO to use the same naming scheme as introduced by |
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@jhedberg Will you please re-review? |
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