@@ -3582,13 +3582,8 @@ void bt_id_del(struct bt_keys *keys)
35823582 bt_adv_foreach (adv_unpause_enabled , NULL );
35833583}
35843584
3585- static void update_sec_level (struct bt_conn * conn )
3585+ static bool update_sec_level (struct bt_conn * conn )
35863586{
3587- if (!conn -> encrypt ) {
3588- conn -> sec_level = BT_SECURITY_L1 ;
3589- return ;
3590- }
3591-
35923587 if (conn -> le .keys && (conn -> le .keys -> flags & BT_KEYS_AUTHENTICATED )) {
35933588 if (conn -> le .keys -> flags & BT_KEYS_SC &&
35943589 conn -> le .keys -> enc_size == BT_SMP_MAX_ENC_KEY_SIZE ) {
@@ -3600,10 +3595,7 @@ static void update_sec_level(struct bt_conn *conn)
36003595 conn -> sec_level = BT_SECURITY_L2 ;
36013596 }
36023597
3603- if (conn -> required_sec_level > conn -> sec_level ) {
3604- BT_ERR ("Failed to set required security level" );
3605- bt_conn_disconnect (conn , BT_HCI_ERR_AUTH_FAIL );
3606- }
3598+ return !(conn -> required_sec_level > conn -> sec_level );
36073599}
36083600#endif /* CONFIG_BT_SMP */
36093601
@@ -3612,6 +3604,7 @@ static void hci_encrypt_change(struct net_buf *buf)
36123604{
36133605 struct bt_hci_evt_encrypt_change * evt = (void * )buf -> data ;
36143606 uint16_t handle = sys_le16_to_cpu (evt -> handle );
3607+ uint8_t status = evt -> status ;
36153608 struct bt_conn * conn ;
36163609
36173610 BT_DBG ("status 0x%02x handle %u encrypt 0x%02x" , evt -> status , handle ,
@@ -3623,9 +3616,9 @@ static void hci_encrypt_change(struct net_buf *buf)
36233616 return ;
36243617 }
36253618
3626- if (evt -> status ) {
3627- bt_conn_security_changed (conn , evt -> status ,
3628- bt_security_err_get (evt -> status ));
3619+ if (status ) {
3620+ bt_conn_security_changed (conn , status ,
3621+ bt_security_err_get (status ));
36293622 bt_conn_unref (conn );
36303623 return ;
36313624 }
@@ -3645,7 +3638,10 @@ static void hci_encrypt_change(struct net_buf *buf)
36453638 if (conn -> encrypt ) {
36463639 bt_smp_update_keys (conn );
36473640 }
3648- update_sec_level (conn );
3641+
3642+ if (!update_sec_level (conn )) {
3643+ status = BT_HCI_ERR_AUTH_FAIL ;
3644+ }
36493645 }
36503646#endif /* CONFIG_BT_SMP */
36513647#if defined(CONFIG_BT_BREDR )
@@ -3668,14 +3664,20 @@ static void hci_encrypt_change(struct net_buf *buf)
36683664 }
36693665#endif /* CONFIG_BT_BREDR */
36703666
3671- bt_conn_security_changed (conn , evt -> status , BT_SECURITY_ERR_SUCCESS );
3667+ bt_conn_security_changed (conn , status , bt_security_err_get (status ));
3668+
3669+ if (status ) {
3670+ BT_ERR ("Failed to set required security level" );
3671+ bt_conn_disconnect (conn , status );
3672+ }
36723673
36733674 bt_conn_unref (conn );
36743675}
36753676
36763677static void hci_encrypt_key_refresh_complete (struct net_buf * buf )
36773678{
36783679 struct bt_hci_evt_encrypt_key_refresh_complete * evt = (void * )buf -> data ;
3680+ uint8_t status = evt -> status ;
36793681 struct bt_conn * conn ;
36803682 uint16_t handle ;
36813683
@@ -3689,9 +3691,9 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
36893691 return ;
36903692 }
36913693
3692- if (evt -> status ) {
3693- bt_conn_security_changed (conn , evt -> status ,
3694- bt_security_err_get (evt -> status ));
3694+ if (status ) {
3695+ bt_conn_security_changed (conn , status ,
3696+ bt_security_err_get (status ));
36953697 bt_conn_unref (conn );
36963698 return ;
36973699 }
@@ -3705,7 +3707,10 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
37053707#if defined(CONFIG_BT_SMP )
37063708 if (conn -> type == BT_CONN_TYPE_LE ) {
37073709 bt_smp_update_keys (conn );
3708- update_sec_level (conn );
3710+
3711+ if (!update_sec_level (conn )) {
3712+ status = BT_HCI_ERR_AUTH_FAIL ;
3713+ }
37093714 }
37103715#endif /* CONFIG_BT_SMP */
37113716#if defined(CONFIG_BT_BREDR )
@@ -3717,7 +3722,12 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
37173722 }
37183723#endif /* CONFIG_BT_BREDR */
37193724
3720- bt_conn_security_changed (conn , evt -> status , BT_SECURITY_ERR_SUCCESS );
3725+ bt_conn_security_changed (conn , status , bt_security_err_get (status ));
3726+ if (status ) {
3727+ BT_ERR ("Failed to set required security level" );
3728+ bt_conn_disconnect (conn , status );
3729+ }
3730+
37213731 bt_conn_unref (conn );
37223732}
37233733#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
0 commit comments