Skip to content

Commit

Permalink
bluetooth: host: track connection type enum
Browse files Browse the repository at this point in the history
The enum used for connection types gets named bt_conn_type to guard
against accidental usage of generic integers with relation to it.

Signed-off-by: Arkadiusz Kozdra <[email protected]>
  • Loading branch information
kozdra committed Jun 27, 2023
1 parent 1415619 commit d02d074
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
35 changes: 18 additions & 17 deletions include/zephyr/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ struct bt_conn_le_data_len_param {
BT_CONN_LE_DATA_LEN_PARAM(BT_GAP_DATA_LEN_MAX, \
BT_GAP_DATA_TIME_MAX)

/** Connection Type */
enum bt_conn_type {
/** LE Connection Type */
BT_CONN_TYPE_LE = BIT(0),
/** BR/EDR Connection Type */
BT_CONN_TYPE_BR = BIT(1),
/** SCO Connection Type */
BT_CONN_TYPE_SCO = BIT(2),
/** ISO Connection Type */
BT_CONN_TYPE_ISO = BIT(3),
/** All Connection Type */
BT_CONN_TYPE_ALL = BT_CONN_TYPE_LE | BT_CONN_TYPE_BR |
BT_CONN_TYPE_SCO | BT_CONN_TYPE_ISO,
};

/** @brief Increment a connection's reference count.
*
* Increment the reference count of a connection object.
Expand Down Expand Up @@ -233,7 +248,8 @@ void bt_conn_unref(struct bt_conn *conn);
* @param func Function to call for each connection.
* @param data Data to pass to the callback function.
*/
void bt_conn_foreach(int type, void (*func)(struct bt_conn *conn, void *data),
void bt_conn_foreach(enum bt_conn_type type,
void (*func)(struct bt_conn *conn, void *data),
void *data);

/** @brief Look up an existing connection by address.
Expand Down Expand Up @@ -270,21 +286,6 @@ const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn);
*/
uint8_t bt_conn_index(const struct bt_conn *conn);

/** Connection Type */
enum {
/** LE Connection Type */
BT_CONN_TYPE_LE = BIT(0),
/** BR/EDR Connection Type */
BT_CONN_TYPE_BR = BIT(1),
/** SCO Connection Type */
BT_CONN_TYPE_SCO = BIT(2),
/** ISO Connection Type */
BT_CONN_TYPE_ISO = BIT(3),
/** All Connection Type */
BT_CONN_TYPE_ALL = BT_CONN_TYPE_LE | BT_CONN_TYPE_BR |
BT_CONN_TYPE_SCO | BT_CONN_TYPE_ISO,
};

/** LE Connection Info Structure */
struct bt_conn_le_info {
/** Source (Local) Identity Address */
Expand Down Expand Up @@ -390,7 +391,7 @@ struct bt_security_info {
/** Connection Info Structure */
struct bt_conn_info {
/** Connection Type. */
uint8_t type;
enum bt_conn_type type : 8;
/** Connection Role. */
uint8_t role;
/** Which local identity the connection was created with */
Expand Down
7 changes: 5 additions & 2 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
}
}

struct bt_conn *bt_conn_lookup_handle(uint16_t handle, int type)
struct bt_conn *bt_conn_lookup_handle(uint16_t handle, enum bt_conn_type type)
{
struct bt_conn *conn;

Expand Down Expand Up @@ -1243,7 +1243,8 @@ struct bt_conn *bt_conn_lookup_handle(uint16_t handle, int type)
return NULL;
}

void bt_conn_foreach(int type, void (*func)(struct bt_conn *conn, void *data),
void bt_conn_foreach(enum bt_conn_type type,
void (*func)(struct bt_conn *conn, void *data),
void *data)
{
int i;
Expand Down Expand Up @@ -2557,6 +2558,8 @@ int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
}
return 0;
#endif
default:
break;
}

return -EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/host/conn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct acl_data {

struct bt_conn {
uint16_t handle;
uint8_t type;
enum bt_conn_type type : 8;
uint8_t role;

ATOMIC_DEFINE(flags, BT_CONN_NUM_FLAGS);
Expand Down Expand Up @@ -308,7 +308,7 @@ void bt_conn_disconnect_all(uint8_t id);
struct bt_conn *bt_conn_new(struct bt_conn *conns, size_t size);

/* Look up an existing connection */
struct bt_conn *bt_conn_lookup_handle(uint16_t handle, int type);
struct bt_conn *bt_conn_lookup_handle(uint16_t handle, enum bt_conn_type type);

static inline bool bt_conn_is_handle_valid(struct bt_conn *conn)
{
Expand Down

0 comments on commit d02d074

Please sign in to comment.