Skip to content

Commit 46f3f28

Browse files
Yagoorrlubos
authored andcommitted
[nrf fromtree] Bluetooth: Host: Conn callbacks registration with BT_CONN_CB_DEFINE
This commit registers the connection callbacks using BT_CONN_CB_DEFINE, which ensures they are set up at link time rather than runtime. Signed-off-by: Yago Fontoura do Rosario <[email protected]> (cherry picked from commit e0d22a3) Signed-off-by: Sean Madigan <[email protected]>
1 parent 307315b commit 46f3f28

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,17 @@ static void gatt_store_ccc_cf(uint8_t id, const bt_addr_le_t *peer_addr)
15111511
}
15121512
}
15131513

1514+
#if defined(CONFIG_BT_SETTINGS) && defined(CONFIG_BT_SMP)
1515+
BT_CONN_CB_DEFINE(gatt_conn_cb) = {
1516+
/* Also update the address of CCC or CF writes that happened before the
1517+
* identity resolution. Note that to increase security in the future, we
1518+
* might want to explicitly not do this and treat a bonded device as a
1519+
* brand-new peer.
1520+
*/
1521+
.identity_resolved = bt_gatt_identity_resolved,
1522+
};
1523+
#endif /* CONFIG_BT_SETTINGS && CONFIG_BT_SMP */
1524+
15141525
static void bt_gatt_service_init(void)
15151526
{
15161527
if (atomic_test_and_set_bit(gatt_flags, GATT_SERVICE_INITIALIZED)) {
@@ -1567,17 +1578,6 @@ void bt_gatt_init(void)
15671578
* and CF storage on pairing complete.
15681579
*/
15691580
bt_conn_auth_info_cb_register(&gatt_conn_auth_info_cb);
1570-
1571-
static struct bt_conn_cb gatt_conn_cb = {
1572-
.identity_resolved = bt_gatt_identity_resolved,
1573-
};
1574-
1575-
/* Also update the address of CCC or CF writes that happened before the
1576-
* identity resolution. Note that to increase security in the future, we
1577-
* might want to explicitly not do this and treat a bonded device as a
1578-
* brand-new peer.
1579-
*/
1580-
bt_conn_cb_register(&gatt_conn_cb);
15811581
#endif /* CONFIG_BT_SETTINGS && CONFIG_BT_SMP */
15821582
}
15831583

subsys/bluetooth/host/shell/bt.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ static void le_cs_config_removed(struct bt_conn *conn, uint8_t config_id)
11911191
}
11921192
#endif
11931193

1194-
static struct bt_conn_cb conn_callbacks = {
1194+
BT_CONN_CB_DEFINE(conn_callbacks) = {
11951195
.connected = connected,
11961196
.disconnected = disconnected,
11971197
.le_param_req = le_param_req,
@@ -1374,10 +1374,6 @@ static void bt_ready(int err)
13741374

13751375
#if defined(CONFIG_BT_CONN)
13761376
default_conn = NULL;
1377-
1378-
/* Unregister to avoid register repeatedly */
1379-
bt_conn_cb_unregister(&conn_callbacks);
1380-
bt_conn_cb_register(&conn_callbacks);
13811377
#endif /* CONFIG_BT_CONN */
13821378

13831379
#if defined(CONFIG_BT_PER_ADV_SYNC)

0 commit comments

Comments
 (0)