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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
fcdb2eef25
commit
9752cee3d7
1 changed files with 13 additions and 14 deletions
|
@ -1812,6 +1812,8 @@ static void smp_reset(struct bt_smp *smp)
|
||||||
*/
|
*/
|
||||||
static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
|
static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
|
||||||
{
|
{
|
||||||
|
struct bt_conn *conn = smp->chan.chan.conn;
|
||||||
|
|
||||||
BT_DBG("status 0x%x", status);
|
BT_DBG("status 0x%x", status);
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
|
@ -1829,12 +1831,11 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
|
||||||
bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND);
|
bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND);
|
||||||
|
|
||||||
if (bond_flag) {
|
if (bond_flag) {
|
||||||
bt_keys_store(smp->chan.chan.conn->le.keys);
|
bt_keys_store(conn->le.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bt_auth && bt_auth->pairing_complete) {
|
if (bt_auth && bt_auth->pairing_complete) {
|
||||||
bt_auth->pairing_complete(smp->chan.chan.conn,
|
bt_auth->pairing_complete(conn, bond_flag);
|
||||||
bond_flag);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t auth_err = auth_err_get(status);
|
uint8_t auth_err = auth_err_get(status);
|
||||||
|
@ -1843,20 +1844,19 @@ static void smp_pairing_complete(struct bt_smp *smp, uint8_t status)
|
||||||
* keys already existed before the pairing procedure or the
|
* keys already existed before the pairing procedure or the
|
||||||
* pairing failed during key distribution.
|
* pairing failed during key distribution.
|
||||||
*/
|
*/
|
||||||
if (smp->chan.chan.conn->le.keys &&
|
if (conn->le.keys &&
|
||||||
(!smp->chan.chan.conn->le.keys->enc_size ||
|
(!conn->le.keys->enc_size ||
|
||||||
atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR))) {
|
atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR))) {
|
||||||
bt_keys_clear(smp->chan.chan.conn->le.keys);
|
bt_keys_clear(conn->le.keys);
|
||||||
smp->chan.chan.conn->le.keys = NULL;
|
conn->le.keys = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) {
|
if (!atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) {
|
||||||
bt_conn_security_changed(smp->chan.chan.conn, status,
|
bt_conn_security_changed(conn, status, auth_err);
|
||||||
auth_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bt_auth && bt_auth->pairing_failed) {
|
if (bt_auth && bt_auth->pairing_failed) {
|
||||||
bt_auth->pairing_failed(smp->chan.chan.conn, auth_err);
|
bt_auth->pairing_failed(conn, auth_err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3173,8 +3173,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
|
||||||
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
|
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
|
||||||
uint8_t err;
|
uint8_t err;
|
||||||
|
|
||||||
err = smp_pairing_accept_query(smp->chan.chan.conn,
|
err = smp_pairing_accept_query(conn, rsp);
|
||||||
rsp);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -3202,7 +3201,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
|
||||||
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
|
if (IS_ENABLED(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)) {
|
||||||
uint8_t err;
|
uint8_t err;
|
||||||
|
|
||||||
err = smp_pairing_accept_query(smp->chan.chan.conn, rsp);
|
err = smp_pairing_accept_query(conn, rsp);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -3212,7 +3211,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
|
||||||
atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) &&
|
atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) &&
|
||||||
bt_auth && bt_auth->pairing_confirm) {
|
bt_auth && bt_auth->pairing_confirm) {
|
||||||
atomic_set_bit(smp->flags, SMP_FLAG_USER);
|
atomic_set_bit(smp->flags, SMP_FLAG_USER);
|
||||||
bt_auth->pairing_confirm(smp->chan.chan.conn);
|
bt_auth->pairing_confirm(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue