@@ -3582,13 +3582,8 @@ void bt_id_del(struct bt_keys *keys)
3582
3582
bt_adv_foreach (adv_unpause_enabled , NULL );
3583
3583
}
3584
3584
3585
- static void update_sec_level (struct bt_conn * conn )
3585
+ static bool update_sec_level (struct bt_conn * conn )
3586
3586
{
3587
- if (!conn -> encrypt ) {
3588
- conn -> sec_level = BT_SECURITY_L1 ;
3589
- return ;
3590
- }
3591
-
3592
3587
if (conn -> le .keys && (conn -> le .keys -> flags & BT_KEYS_AUTHENTICATED )) {
3593
3588
if (conn -> le .keys -> flags & BT_KEYS_SC &&
3594
3589
conn -> le .keys -> enc_size == BT_SMP_MAX_ENC_KEY_SIZE ) {
@@ -3600,10 +3595,7 @@ static void update_sec_level(struct bt_conn *conn)
3600
3595
conn -> sec_level = BT_SECURITY_L2 ;
3601
3596
}
3602
3597
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 );
3607
3599
}
3608
3600
#endif /* CONFIG_BT_SMP */
3609
3601
@@ -3612,6 +3604,7 @@ static void hci_encrypt_change(struct net_buf *buf)
3612
3604
{
3613
3605
struct bt_hci_evt_encrypt_change * evt = (void * )buf -> data ;
3614
3606
uint16_t handle = sys_le16_to_cpu (evt -> handle );
3607
+ uint8_t status = evt -> status ;
3615
3608
struct bt_conn * conn ;
3616
3609
3617
3610
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)
3623
3616
return ;
3624
3617
}
3625
3618
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 ));
3629
3622
bt_conn_unref (conn );
3630
3623
return ;
3631
3624
}
@@ -3645,7 +3638,10 @@ static void hci_encrypt_change(struct net_buf *buf)
3645
3638
if (conn -> encrypt ) {
3646
3639
bt_smp_update_keys (conn );
3647
3640
}
3648
- update_sec_level (conn );
3641
+
3642
+ if (!update_sec_level (conn )) {
3643
+ status = BT_HCI_ERR_AUTH_FAIL ;
3644
+ }
3649
3645
}
3650
3646
#endif /* CONFIG_BT_SMP */
3651
3647
#if defined(CONFIG_BT_BREDR )
@@ -3668,14 +3664,20 @@ static void hci_encrypt_change(struct net_buf *buf)
3668
3664
}
3669
3665
#endif /* CONFIG_BT_BREDR */
3670
3666
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
+ }
3672
3673
3673
3674
bt_conn_unref (conn );
3674
3675
}
3675
3676
3676
3677
static void hci_encrypt_key_refresh_complete (struct net_buf * buf )
3677
3678
{
3678
3679
struct bt_hci_evt_encrypt_key_refresh_complete * evt = (void * )buf -> data ;
3680
+ uint8_t status = evt -> status ;
3679
3681
struct bt_conn * conn ;
3680
3682
uint16_t handle ;
3681
3683
@@ -3689,9 +3691,9 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
3689
3691
return ;
3690
3692
}
3691
3693
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 ));
3695
3697
bt_conn_unref (conn );
3696
3698
return ;
3697
3699
}
@@ -3705,7 +3707,10 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
3705
3707
#if defined(CONFIG_BT_SMP )
3706
3708
if (conn -> type == BT_CONN_TYPE_LE ) {
3707
3709
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
+ }
3709
3714
}
3710
3715
#endif /* CONFIG_BT_SMP */
3711
3716
#if defined(CONFIG_BT_BREDR )
@@ -3717,7 +3722,12 @@ static void hci_encrypt_key_refresh_complete(struct net_buf *buf)
3717
3722
}
3718
3723
#endif /* CONFIG_BT_BREDR */
3719
3724
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
+
3721
3731
bt_conn_unref (conn );
3722
3732
}
3723
3733
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
0 commit comments