Skip to content

Commit a29c664

Browse files
tmp
1 parent b1a0d08 commit a29c664

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/conn_state/ble_conn_state.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ LOG_MODULE_REGISTER(ble_bms, CONFIG_CONN_STATE_LOG_LEVEL);
2222
#define TOTAL_FLAG_COLLECTION_COUNT (CONN_STATE_DEFAULT_FLAG_COLLECTION_COUNT + \
2323
CONFIG_BLE_CONN_STATE_USER_FLAG_COUNT)
2424

25+
/** Connection handles in the same order as they are indexed in the atomics */
26+
struct ble_conn_state_conn_handle_list connections;
27+
28+
int conn_id_get(uint8_t conn_idx)
29+
{
30+
return connections.conn_handles[conn_idx];
31+
}
32+
33+
int conn_idx_get(uint32_t conn_id)
34+
{
35+
for (int i = 0; i < connections.len; i++) {
36+
if (connections.conn_handles[i] == conn_id) {
37+
return i;
38+
}
39+
}
40+
41+
/* conn_id not found in list */
42+
43+
for (int i = 0; i < BLE_CONN_STATE_MAX_CONNECTIONS; i++) {
44+
if (atomic_test_bit(&bcs.flags.connected_flags, conn_handle) == false) {
45+
record_invalidate(i);
46+
connections.conn_handles[i] = conn_id;
47+
return i;
48+
}
49+
}
50+
51+
return -1;
52+
}
53+
2554
/**
2655
* @brief Structure containing all the flag collections maintained by the Connection State module.
2756
*/

0 commit comments

Comments
 (0)