@@ -2724,6 +2724,35 @@ static uint8_t get_auth(struct bt_conn *conn, uint8_t auth)
2724
2724
return auth ;
2725
2725
}
2726
2726
2727
+ static uint8_t remote_sec_level_reachable (struct bt_smp * smp )
2728
+ {
2729
+ struct bt_conn * conn = smp -> chan .chan .conn ;
2730
+
2731
+ switch (conn -> required_sec_level ) {
2732
+ case BT_SECURITY_L1 :
2733
+ case BT_SECURITY_L2 :
2734
+ return 0 ;
2735
+
2736
+ case BT_SECURITY_L4 :
2737
+ if (get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
2738
+ return BT_SMP_ERR_ENC_KEY_SIZE ;
2739
+ }
2740
+
2741
+ if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
2742
+ return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2743
+ }
2744
+ __fallthrough ;
2745
+ case BT_SECURITY_L3 :
2746
+ if (smp -> method == JUST_WORKS ) {
2747
+ return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2748
+ }
2749
+
2750
+ return 0 ;
2751
+ default :
2752
+ return BT_SMP_ERR_UNSPECIFIED ;
2753
+ }
2754
+ }
2755
+
2727
2756
static bool sec_level_reachable (struct bt_conn * conn )
2728
2757
{
2729
2758
switch (conn -> required_sec_level ) {
@@ -2905,6 +2934,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2905
2934
struct bt_conn * conn = smp -> chan .chan .conn ;
2906
2935
struct bt_smp_pairing * req = (void * )buf -> data ;
2907
2936
struct bt_smp_pairing * rsp ;
2937
+ uint8_t err ;
2908
2938
2909
2939
BT_DBG ("" );
2910
2940
@@ -2982,15 +3012,17 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2982
3012
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2983
3013
}
2984
3014
3015
+ err = remote_sec_level_reachable (smp );
3016
+ if (err ) {
3017
+ return err ;
3018
+ }
3019
+
2985
3020
if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
2986
3021
#if defined(CONFIG_BT_SMP_SC_PAIR_ONLY )
2987
3022
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2988
3023
#else
2989
3024
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
2990
- uint8_t err ;
2991
-
2992
- err = smp_pairing_accept_query (smp -> chan .chan .conn ,
2993
- req );
3025
+ err = smp_pairing_accept_query (conn , req );
2994
3026
if (err ) {
2995
3027
return err ;
2996
3028
}
@@ -3000,22 +3032,8 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
3000
3032
#endif /* CONFIG_BT_SMP_SC_PAIR_ONLY */
3001
3033
}
3002
3034
3003
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3004
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3005
- smp -> method == JUST_WORKS ) {
3006
- return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3007
- }
3008
-
3009
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3010
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3011
- get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
3012
- return BT_SMP_ERR_ENC_KEY_SIZE ;
3013
- }
3014
-
3015
3035
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
3016
- uint8_t err ;
3017
-
3018
- err = smp_pairing_accept_query (smp -> chan .chan .conn , req );
3036
+ err = smp_pairing_accept_query (conn , req );
3019
3037
if (err ) {
3020
3038
return err ;
3021
3039
}
@@ -3025,7 +3043,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
3025
3043
!atomic_test_bit (smp -> flags , SMP_FLAG_SEC_REQ ) &&
3026
3044
bt_auth && bt_auth -> pairing_confirm ) {
3027
3045
atomic_set_bit (smp -> flags , SMP_FLAG_USER );
3028
- bt_auth -> pairing_confirm (smp -> chan . chan . conn );
3046
+ bt_auth -> pairing_confirm (conn );
3029
3047
return 0 ;
3030
3048
}
3031
3049
@@ -3151,6 +3169,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3151
3169
struct bt_conn * conn = smp -> chan .chan .conn ;
3152
3170
struct bt_smp_pairing * rsp = (void * )buf -> data ;
3153
3171
struct bt_smp_pairing * req = (struct bt_smp_pairing * )& smp -> preq [1 ];
3172
+ uint8_t err ;
3154
3173
3155
3174
BT_DBG ("" );
3156
3175
@@ -3191,13 +3210,16 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3191
3210
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3192
3211
}
3193
3212
3213
+ err = remote_sec_level_reachable (smp );
3214
+ if (err ) {
3215
+ return err ;
3216
+ }
3217
+
3194
3218
if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
3195
3219
#if defined(CONFIG_BT_SMP_SC_PAIR_ONLY )
3196
3220
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3197
3221
#else
3198
3222
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
3199
- uint8_t err ;
3200
-
3201
3223
err = smp_pairing_accept_query (conn , rsp );
3202
3224
if (err ) {
3203
3225
return err ;
@@ -3208,24 +3230,10 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3208
3230
#endif /* CONFIG_BT_SMP_SC_PAIR_ONLY */
3209
3231
}
3210
3232
3211
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3212
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3213
- smp -> method == JUST_WORKS ) {
3214
- return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3215
- }
3216
-
3217
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3218
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3219
- get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
3220
- return BT_SMP_ERR_ENC_KEY_SIZE ;
3221
- }
3222
-
3223
3233
smp -> local_dist &= SEND_KEYS_SC ;
3224
3234
smp -> remote_dist &= RECV_KEYS_SC ;
3225
3235
3226
3236
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
3227
- uint8_t err ;
3228
-
3229
3237
err = smp_pairing_accept_query (conn , rsp );
3230
3238
if (err ) {
3231
3239
return err ;
0 commit comments