bluetooth: host: Rename bt_conn_get_id and make it public.

There is not an easy way to relate an application's user_data to a
connection. One way is to save a pointer to bt_conn in the
application's user_data array upon connection establishment.
Each connection related callback function will have to loop for all
user_data and compare the saved pointer to the passed bt_conn
pointer. This is inefficient if there are many callback activations
during the connection.

This change makes the internal bt_conn mapping function accessible to
applications in conn.h. The function name is changed to
bt_conn_index() to clearly indicate that the function returns an
index of an array.
Add an ASSERT to catch illegal parameter.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
This commit is contained in:
Kim Sekkelund 2018-11-26 09:10:06 +01:00 committed by Johan Hedberg
commit bf11698ed9
5 changed files with 22 additions and 7 deletions

View file

@ -2249,9 +2249,12 @@ int bt_conn_auth_pairing_confirm(struct bt_conn *conn)
}
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
u8_t bt_conn_get_id(struct bt_conn *conn)
u8_t bt_conn_index(struct bt_conn *conn)
{
return conn - conns;
u8_t index = conn - conns;
__ASSERT(index < CONFIG_BT_MAX_CONN, "Invalid bt_conn pointer");
return index;
}
struct bt_conn *bt_conn_lookup_id(u8_t id)