diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index a6c6d3b0366c09..81a96937b08e8f 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -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 __packed 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. @@ -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. @@ -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 */ @@ -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; /** Connection Role. */ uint8_t role; /** Which local identity the connection was created with */ diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 782f4fd87bd4d8..66b8a662f3ec6d 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -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; @@ -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; @@ -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; diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index eac811260c32f8..7b2ed8dd04a667 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -159,7 +159,7 @@ struct acl_data { struct bt_conn { uint16_t handle; - uint8_t type; + enum bt_conn_type type; uint8_t role; ATOMIC_DEFINE(flags, BT_CONN_NUM_FLAGS); @@ -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) { diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 76d836e9bc3e55..cb623cb251be22 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -569,6 +569,8 @@ void conn_addr_str(struct bt_conn *conn, char *addr, size_t len) case BT_CONN_TYPE_LE: bt_addr_le_to_str(info.le.dst, addr, len); break; + default: + break; } } @@ -3276,6 +3278,8 @@ static void connection_info(struct bt_conn *conn, void *user_data) shell_print(ctx_shell, " #%u [ISO][%s] %s", info.id, role_str(info.role), addr); break; #endif + default: + break; } (*conn_count)++; diff --git a/tests/bluetooth/host/keys/mocks/conn.c b/tests/bluetooth/host/keys/mocks/conn.c index cf5dd37177bc7c..0045f3b787fe60 100644 --- a/tests/bluetooth/host/keys/mocks/conn.c +++ b/tests/bluetooth/host/keys/mocks/conn.c @@ -7,5 +7,5 @@ #include #include "mocks/conn.h" -DEFINE_FAKE_VOID_FUNC(bt_conn_foreach, int, bt_conn_foreach_cb, void *); +DEFINE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *); DEFINE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *); diff --git a/tests/bluetooth/host/keys/mocks/conn.h b/tests/bluetooth/host/keys/mocks/conn.h index 506a1757380dee..98ef8cc1e3d74d 100644 --- a/tests/bluetooth/host/keys/mocks/conn.h +++ b/tests/bluetooth/host/keys/mocks/conn.h @@ -16,5 +16,5 @@ typedef void (*bt_conn_foreach_cb) (struct bt_conn *conn, void *data); FAKE(bt_conn_foreach) \ FAKE(bt_conn_get_dst) \ -DECLARE_FAKE_VOID_FUNC(bt_conn_foreach, int, bt_conn_foreach_cb, void *); +DECLARE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *); DECLARE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *);