@@ -2697,6 +2697,35 @@ static uint8_t get_auth(struct bt_conn *conn, uint8_t auth)
2697
2697
return auth ;
2698
2698
}
2699
2699
2700
+ static uint8_t remote_sec_level_reachable (struct bt_smp * smp )
2701
+ {
2702
+ struct bt_conn * conn = smp -> chan .chan .conn ;
2703
+
2704
+ switch (conn -> required_sec_level ) {
2705
+ case BT_SECURITY_L1 :
2706
+ case BT_SECURITY_L2 :
2707
+ return 0 ;
2708
+
2709
+ case BT_SECURITY_L4 :
2710
+ if (get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
2711
+ return BT_SMP_ERR_ENC_KEY_SIZE ;
2712
+ }
2713
+
2714
+ if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
2715
+ return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2716
+ }
2717
+ __fallthrough ;
2718
+ case BT_SECURITY_L3 :
2719
+ if (smp -> method == JUST_WORKS ) {
2720
+ return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2721
+ }
2722
+
2723
+ return 0 ;
2724
+ default :
2725
+ return BT_SMP_ERR_UNSPECIFIED ;
2726
+ }
2727
+ }
2728
+
2700
2729
static bool sec_level_reachable (struct bt_conn * conn )
2701
2730
{
2702
2731
switch (conn -> required_sec_level ) {
@@ -2877,6 +2906,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2877
2906
struct bt_conn * conn = smp -> chan .chan .conn ;
2878
2907
struct bt_smp_pairing * req = (void * )buf -> data ;
2879
2908
struct bt_smp_pairing * rsp ;
2909
+ uint8_t err ;
2880
2910
2881
2911
BT_DBG ("" );
2882
2912
@@ -2954,15 +2984,17 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2954
2984
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2955
2985
}
2956
2986
2987
+ err = remote_sec_level_reachable (smp );
2988
+ if (err ) {
2989
+ return err ;
2990
+ }
2991
+
2957
2992
if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
2958
2993
#if defined(CONFIG_BT_SMP_SC_PAIR_ONLY )
2959
2994
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2960
2995
#else
2961
2996
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
2962
- uint8_t err ;
2963
-
2964
- err = smp_pairing_accept_query (smp -> chan .chan .conn ,
2965
- req );
2997
+ err = smp_pairing_accept_query (conn , req );
2966
2998
if (err ) {
2967
2999
return err ;
2968
3000
}
@@ -2972,22 +3004,8 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2972
3004
#endif /* CONFIG_BT_SMP_SC_PAIR_ONLY */
2973
3005
}
2974
3006
2975
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
2976
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
2977
- smp -> method == JUST_WORKS ) {
2978
- return BT_SMP_ERR_AUTH_REQUIREMENTS ;
2979
- }
2980
-
2981
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
2982
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
2983
- get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
2984
- return BT_SMP_ERR_ENC_KEY_SIZE ;
2985
- }
2986
-
2987
3007
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
2988
- uint8_t err ;
2989
-
2990
- err = smp_pairing_accept_query (smp -> chan .chan .conn , req );
3008
+ err = smp_pairing_accept_query (conn , req );
2991
3009
if (err ) {
2992
3010
return err ;
2993
3011
}
@@ -2997,7 +3015,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
2997
3015
!atomic_test_bit (smp -> flags , SMP_FLAG_SEC_REQ ) &&
2998
3016
bt_auth && bt_auth -> pairing_confirm ) {
2999
3017
atomic_set_bit (smp -> flags , SMP_FLAG_USER );
3000
- bt_auth -> pairing_confirm (smp -> chan . chan . conn );
3018
+ bt_auth -> pairing_confirm (conn );
3001
3019
return 0 ;
3002
3020
}
3003
3021
@@ -3116,6 +3134,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3116
3134
struct bt_conn * conn = smp -> chan .chan .conn ;
3117
3135
struct bt_smp_pairing * rsp = (void * )buf -> data ;
3118
3136
struct bt_smp_pairing * req = (struct bt_smp_pairing * )& smp -> preq [1 ];
3137
+ uint8_t err ;
3119
3138
3120
3139
BT_DBG ("" );
3121
3140
@@ -3156,15 +3175,17 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3156
3175
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3157
3176
}
3158
3177
3178
+ err = remote_sec_level_reachable (smp );
3179
+ if (err ) {
3180
+ return err ;
3181
+ }
3182
+
3159
3183
if (!atomic_test_bit (smp -> flags , SMP_FLAG_SC )) {
3160
3184
#if defined(CONFIG_BT_SMP_SC_PAIR_ONLY )
3161
3185
return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3162
3186
#else
3163
3187
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
3164
- uint8_t err ;
3165
-
3166
- err = smp_pairing_accept_query (smp -> chan .chan .conn ,
3167
- rsp );
3188
+ err = smp_pairing_accept_query (conn , rsp );
3168
3189
if (err ) {
3169
3190
return err ;
3170
3191
}
@@ -3174,25 +3195,11 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
3174
3195
#endif /* CONFIG_BT_SMP_SC_PAIR_ONLY */
3175
3196
}
3176
3197
3177
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3178
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3179
- smp -> method == JUST_WORKS ) {
3180
- return BT_SMP_ERR_AUTH_REQUIREMENTS ;
3181
- }
3182
-
3183
- if ((IS_ENABLED (CONFIG_BT_SMP_SC_ONLY ) ||
3184
- conn -> required_sec_level == BT_SECURITY_L4 ) &&
3185
- get_encryption_key_size (smp ) != BT_SMP_MAX_ENC_KEY_SIZE ) {
3186
- return BT_SMP_ERR_ENC_KEY_SIZE ;
3187
- }
3188
-
3189
3198
smp -> local_dist &= SEND_KEYS_SC ;
3190
3199
smp -> remote_dist &= RECV_KEYS_SC ;
3191
3200
3192
3201
if (IS_ENABLED (CONFIG_BT_SMP_APP_PAIRING_ACCEPT )) {
3193
- uint8_t err ;
3194
-
3195
- err = smp_pairing_accept_query (smp -> chan .chan .conn , rsp );
3202
+ err = smp_pairing_accept_query (conn , rsp );
3196
3203
if (err ) {
3197
3204
return err ;
3198
3205
}
0 commit comments