Skip to content

Commit 2797902

Browse files
committed
Bluetooth: host: Refactor smp handling of conn pointer
Refactor SMP to have a conn pointer where this pointer is used multiple times. Signed-off-by: Joakim Andersson <[email protected]>
1 parent dc2f26a commit 2797902

File tree

1 file changed

+13
-14
lines changed
  • subsys/bluetooth/host

1 file changed

+13
-14
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ static void smp_reset(struct bt_smp *smp)
18121812
*/
18131813
static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
18141814
{
1815+
struct bt_conn *conn = smp->chan.chan.conn;
1816+
18151817
BT_DBG("status 0x%x", status);
18161818

18171819
if (!status) {
@@ -1829,12 +1831,11 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
18291831
bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND);
18301832

18311833
if (bond_flag) {
1832-
bt_keys_store(smp->chan.chan.conn->le.keys);
1834+
bt_keys_store(conn->le.keys);
18331835
}
18341836

18351837
if (bt_auth && bt_auth->pairing_complete) {
1836-
bt_auth->pairing_complete(smp->chan.chan.conn,
1837-
bond_flag);
1838+
bt_auth->pairing_complete(conn, bond_flag);
18381839
}
18391840
} else {
18401841
uint8_t auth_err = auth_err_get(status);
@@ -1843,20 +1844,19 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
18431844
* keys already existed before the pairing procedure or the
18441845
* pairing failed during key distribution.
18451846
*/
1846-
if (smp->chan.chan.conn->le.keys &&
1847-
(!smp->chan.chan.conn->le.keys->enc_size ||
1847+
if (conn->le.keys &&
1848+
(!conn->le.keys->enc_size ||
18481849
atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR))) {
1849-
bt_keys_clear(smp->chan.chan.conn->le.keys);
1850-
smp->chan.chan.conn->le.keys = NULL;
1850+
bt_keys_clear(conn->le.keys);
1851+
conn->le.keys = NULL;
18511852
}
18521853

18531854
if (!atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) {
1854-
bt_conn_security_changed(smp->chan.chan.conn, status,
1855-
auth_err);
1855+
bt_conn_security_changed(conn, status, auth_err);
18561856
}
18571857

18581858
if (bt_auth && bt_auth->pairing_failed) {
1859-
bt_auth->pairing_failed(smp->chan.chan.conn, auth_err);
1859+
bt_auth->pairing_failed(conn, auth_err);
18601860
}
18611861
}
18621862

@@ -3173,8 +3173,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
31733173
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
31743174
uint8_t err;
31753175

3176-
err = smp_pairing_accept_query(smp->chan.chan.conn,
3177-
rsp);
3176+
err = smp_pairing_accept_query(conn, rsp);
31783177
if (err) {
31793178
return err;
31803179
}
@@ -3202,7 +3201,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
32023201
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
32033202
uint8_t err;
32043203

3205-
err = smp_pairing_accept_query(smp->chan.chan.conn, rsp);
3204+
err = smp_pairing_accept_query(conn, rsp);
32063205
if (err) {
32073206
return err;
32083207
}
@@ -3212,7 +3211,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
32123211
atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) &&
32133212
bt_auth && bt_auth->pairing_confirm) {
32143213
atomic_set_bit(smp->flags, SMP_FLAG_USER);
3215-
bt_auth->pairing_confirm(smp->chan.chan.conn);
3214+
bt_auth->pairing_confirm(conn);
32163215
return 0;
32173216
}
32183217

0 commit comments

Comments
 (0)