@@ -3113,6 +3113,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status,
31133113 const struct hci_rp_read_enc_key_size * rp ;
31143114 struct hci_conn * conn ;
31153115 u16 handle ;
3116+ u8 rp_status ;
31163117
31173118 BT_DBG ("%s status 0x%02x" , hdev -> name , status );
31183119
@@ -3122,6 +3123,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status,
31223123 }
31233124
31243125 rp = (void * )skb -> data ;
3126+ rp_status = rp -> status ;
31253127 handle = le16_to_cpu (rp -> handle );
31263128
31273129 hci_dev_lock (hdev );
@@ -3134,15 +3136,30 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status,
31343136 * secure approach is to then assume the key size is 0 to force a
31353137 * disconnection.
31363138 */
3137- if (rp -> status ) {
3139+ if (rp_status ) {
31383140 bt_dev_err (hdev , "failed to read key size for handle %u" ,
31393141 handle );
31403142 conn -> enc_key_size = 0 ;
31413143 } else {
31423144 conn -> enc_key_size = rp -> key_size ;
3145+ rp_status = 0 ;
3146+
3147+ if (conn -> enc_key_size < hdev -> min_enc_key_size ) {
3148+ /* As slave role, the conn->state has been set to
3149+ * BT_CONNECTED and l2cap conn req might not be received
3150+ * yet, at this moment the l2cap layer almost does
3151+ * nothing with the non-zero status.
3152+ * So we also clear encrypt related bits, and then the
3153+ * handler of l2cap conn req will get the right secure
3154+ * state at a later time.
3155+ */
3156+ rp_status = HCI_ERROR_AUTH_FAILURE ;
3157+ clear_bit (HCI_CONN_ENCRYPT , & conn -> flags );
3158+ clear_bit (HCI_CONN_AES_CCM , & conn -> flags );
3159+ }
31433160 }
31443161
3145- hci_encrypt_cfm (conn , 0 );
3162+ hci_encrypt_cfm (conn , rp_status );
31463163
31473164unlock :
31483165 hci_dev_unlock (hdev );
0 commit comments