@@ -712,6 +712,47 @@ static u8 hci_cc_read_local_version(struct hci_dev *hdev, void *data,
712712 return rp -> status ;
713713}
714714
715+ static u8 hci_cc_read_enc_key_size (struct hci_dev * hdev , void * data ,
716+ struct sk_buff * skb )
717+ {
718+ struct hci_rp_read_enc_key_size * rp = data ;
719+ struct hci_conn * conn ;
720+ u16 handle ;
721+ u8 status = rp -> status ;
722+
723+ bt_dev_dbg (hdev , "status 0x%2.2x" , status );
724+
725+ handle = le16_to_cpu (rp -> handle );
726+
727+ hci_dev_lock (hdev );
728+
729+ conn = hci_conn_hash_lookup_handle (hdev , handle );
730+ if (!conn ) {
731+ status = 0xFF ;
732+ goto done ;
733+ }
734+
735+ /* While unexpected, the read_enc_key_size command may fail. The most
736+ * secure approach is to then assume the key size is 0 to force a
737+ * disconnection.
738+ */
739+ if (status ) {
740+ bt_dev_err (hdev , "failed to read key size for handle %u" ,
741+ handle );
742+ conn -> enc_key_size = 0 ;
743+ } else {
744+ conn -> enc_key_size = rp -> key_size ;
745+ status = 0 ;
746+ }
747+
748+ hci_encrypt_cfm (conn , 0 );
749+
750+ done :
751+ hci_dev_unlock (hdev );
752+
753+ return status ;
754+ }
755+
715756static u8 hci_cc_read_local_commands (struct hci_dev * hdev , void * data ,
716757 struct sk_buff * skb )
717758{
@@ -3534,47 +3575,6 @@ static void hci_remote_name_evt(struct hci_dev *hdev, void *data,
35343575 hci_dev_unlock (hdev );
35353576}
35363577
3537- static void read_enc_key_size_complete (struct hci_dev * hdev , u8 status ,
3538- u16 opcode , struct sk_buff * skb )
3539- {
3540- const struct hci_rp_read_enc_key_size * rp ;
3541- struct hci_conn * conn ;
3542- u16 handle ;
3543-
3544- BT_DBG ("%s status 0x%02x" , hdev -> name , status );
3545-
3546- if (!skb || skb -> len < sizeof (* rp )) {
3547- bt_dev_err (hdev , "invalid read key size response" );
3548- return ;
3549- }
3550-
3551- rp = (void * )skb -> data ;
3552- handle = le16_to_cpu (rp -> handle );
3553-
3554- hci_dev_lock (hdev );
3555-
3556- conn = hci_conn_hash_lookup_handle (hdev , handle );
3557- if (!conn )
3558- goto unlock ;
3559-
3560- /* While unexpected, the read_enc_key_size command may fail. The most
3561- * secure approach is to then assume the key size is 0 to force a
3562- * disconnection.
3563- */
3564- if (rp -> status ) {
3565- bt_dev_err (hdev , "failed to read key size for handle %u" ,
3566- handle );
3567- conn -> enc_key_size = 0 ;
3568- } else {
3569- conn -> enc_key_size = rp -> key_size ;
3570- }
3571-
3572- hci_encrypt_cfm (conn , 0 );
3573-
3574- unlock :
3575- hci_dev_unlock (hdev );
3576- }
3577-
35783578static void hci_encrypt_change_evt (struct hci_dev * hdev , void * data ,
35793579 struct sk_buff * skb )
35803580{
@@ -3639,7 +3639,6 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
36393639 /* Try reading the encryption key size for encrypted ACL links */
36403640 if (!ev -> status && ev -> encrypt && conn -> type == ACL_LINK ) {
36413641 struct hci_cp_read_enc_key_size cp ;
3642- struct hci_request req ;
36433642
36443643 /* Only send HCI_Read_Encryption_Key_Size if the
36453644 * controller really supports it. If it doesn't, assume
@@ -3650,12 +3649,9 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
36503649 goto notify ;
36513650 }
36523651
3653- hci_req_init (& req , hdev );
3654-
36553652 cp .handle = cpu_to_le16 (conn -> handle );
3656- hci_req_add (& req , HCI_OP_READ_ENC_KEY_SIZE , sizeof (cp ), & cp );
3657-
3658- if (hci_req_run_skb (& req , read_enc_key_size_complete )) {
3653+ if (hci_send_cmd (hdev , HCI_OP_READ_ENC_KEY_SIZE ,
3654+ sizeof (cp ), & cp )) {
36593655 bt_dev_err (hdev , "sending read key size failed" );
36603656 conn -> enc_key_size = HCI_LINK_KEY_SIZE ;
36613657 goto notify ;
@@ -4037,6 +4033,8 @@ static const struct hci_cc {
40374033 sizeof (struct hci_rp_read_local_amp_info )),
40384034 HCI_CC (HCI_OP_READ_CLOCK , hci_cc_read_clock ,
40394035 sizeof (struct hci_rp_read_clock )),
4036+ HCI_CC (HCI_OP_READ_ENC_KEY_SIZE , hci_cc_read_enc_key_size ,
4037+ sizeof (struct hci_rp_read_enc_key_size )),
40404038 HCI_CC (HCI_OP_READ_INQ_RSP_TX_POWER , hci_cc_read_inq_rsp_tx_power ,
40414039 sizeof (struct hci_rp_read_inq_rsp_tx_power )),
40424040 HCI_CC (HCI_OP_READ_DEF_ERR_DATA_REPORTING ,
0 commit comments