Bluetooth: Classify HCI cmd complete event under corresponding config option
Subsystems (2)
PATCH 1/3 Bluetooth: Classify HCI cmd complete event under corresponding config option
According to Bluetooth spec, HCI command are supported by related controllers, we can sort them under corresponding kernel config option
Signed-off-by Arron Wang <[email protected]>
--- net/bluetooth/hci_event.c | 770 +++++++++++++++++++++++---------------------- 1 file changed, 392 insertions(+), 378 deletions(-)
net/bluetooth/hci_event.c +392 -378
@@ -41,6 +41,219 @@/* Handle HCI Event packets */ +static void hci_cc_reset (struct hci_dev *hdev,struct sk_buff *skb) +{ +__u8 status = *((__u8 *) skb->data); + +BT_DBG ("%s status 0x%2.2x" , hdev->name, status); + +clear_bit (HCI_RESET , &hdev->flags); + +if (status) +return ; + +/* Reset all non-persistent flags */ +hci_dev_clear_volatile_flags (hdev); + +hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); + + hdev->inq_tx_power =HCI_TX_POWER_INVALID ; + hdev->adv_tx_power =HCI_TX_POWER_INVALID ; + +memset (hdev->adv_data,0 ,sizeof (hdev->adv_data)); + hdev->adv_data_len =0 ; + +memset (hdev->scan_rsp_data,0 ,sizeof (hdev->scan_rsp_data)); + hdev->scan_rsp_data_len =0 ; + + hdev->le_scan_type =LE_SCAN_PASSIVE ; + + hdev->ssp_debug_mode =0 ; + +hci_bdaddr_list_clear (&hdev->le_white_list); +} + +static void hci_cc_read_local_version (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_read_local_version *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + +if (hci_dev_test_flag (hdev,HCI_SETUP ) || +hci_dev_test_flag (hdev,HCI_CONFIG )) { + hdev->hci_ver = rp->hci_ver; + hdev->hci_rev =__le16_to_cpu (rp->hci_rev); + hdev->lmp_ver = rp->lmp_ver; + hdev->manufacturer =__le16_to_cpu (rp->manufacturer); + hdev->lmp_subver =__le16_to_cpu (rp->lmp_subver); + } +} + +static void hci_cc_read_local_commands (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_read_local_commands *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + +if (hci_dev_test_flag (hdev,HCI_SETUP ) || +hci_dev_test_flag (hdev,HCI_CONFIG )) +memcpy (hdev->commands, rp->commands,sizeof (hdev->commands)); +} + +static void hci_cc_read_local_features (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_read_local_features *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + +memcpy (hdev->features, rp->features,8 ); + +/* Adjust default settings according to features +* supported by device. +*/ + +if (hdev->features[0 ][0 ] &LMP_3SLOT ) + hdev->pkt_type |= (HCI_DM3 |HCI_DH3 ); + +if (hdev->features[0 ][0 ] &LMP_5SLOT ) + hdev->pkt_type |= (HCI_DM5 |HCI_DH5 ); + +if (hdev->features[0 ][1 ] &LMP_HV2 ) { + hdev->pkt_type |= (HCI_HV2 ); + hdev->esco_type |= (ESCO_HV2 ); + } + +if (hdev->features[0 ][1 ] &LMP_HV3 ) { + hdev->pkt_type |= (HCI_HV3 ); + hdev->esco_type |= (ESCO_HV3 ); + } + +if (lmp_esco_capable (hdev)) + hdev->esco_type |= (ESCO_EV3 ); + +if (hdev->features[0 ][4 ] &LMP_EV4 ) + hdev->esco_type |= (ESCO_EV4 ); + +if (hdev->features[0 ][4 ] &LMP_EV5 ) + hdev->esco_type |= (ESCO_EV5 ); + +if (hdev->features[0 ][5 ] &LMP_EDR_ESCO_2M ) + hdev->esco_type |= (ESCO_2EV3 ); + +if (hdev->features[0 ][5 ] &LMP_EDR_ESCO_3M ) + hdev->esco_type |= (ESCO_3EV3 ); + +if (hdev->features[0 ][5 ] &LMP_EDR_3S_ESCO ) + hdev->esco_type |= (ESCO_2EV5 |ESCO_3EV5 ); +} + +static void hci_cc_read_buffer_size (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_read_buffer_size *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + + hdev->acl_mtu =__le16_to_cpu (rp->acl_mtu); + hdev->sco_mtu = rp->sco_mtu; + hdev->acl_pkts =__le16_to_cpu (rp->acl_max_pkt); + hdev->sco_pkts =__le16_to_cpu (rp->sco_max_pkt); + +if (test_bit (HCI_QUIRK_FIXUP_BUFFER_SIZE , &hdev->quirks)) { + hdev->sco_mtu =64 ; + hdev->sco_pkts =8 ; + } + + hdev->acl_cnt = hdev->acl_pkts; + hdev->sco_cnt = hdev->sco_pkts; + +BT_DBG ("%s acl mtu %d:%d sco mtu %d:%d" , hdev->name, hdev->acl_mtu, + hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); +} + +static void hci_cc_read_bd_addr (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_read_bd_addr *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + +if (test_bit (HCI_INIT , &hdev->flags)) +bacpy (&hdev->bdaddr, &rp->bdaddr); + +if (hci_dev_test_flag (hdev,HCI_SETUP )) +bacpy (&hdev->setup_addr, &rp->bdaddr); +} + +static void hci_cc_read_rssi (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_read_rssi *rp = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (rp->handle)); +if (conn) + conn->rssi = rp->rssi; + +hci_dev_unlock (hdev); +} + +static void hci_cc_read_tx_power (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_cp_read_tx_power *sent; +struct hci_rp_read_tx_power *rp = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + + sent =hci_sent_cmd_data (hdev,HCI_OP_READ_TX_POWER ); +if (!sent) +return ; + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (rp->handle)); +if (!conn) + goto unlock; + +switch (sent->type) { +case 0x00 : + conn->tx_power = rp->tx_power; +break ; +case 0x01 : + conn->max_tx_power = rp->tx_power; +break ; + } + +unlock: +hci_dev_unlock (hdev); +} + +#if IS_ENABLED (CONFIG_BT_BREDR )static void hci_cc_inquiry_cancel (struct hci_dev *hdev,struct sk_buff *skb) {__u8 status = *((__u8 *) skb->data);
@@ -186,38 +399,6 @@ static void hci_cc_write_def_link_policy(struct hci_dev *hdev, hdev->link_policy =get_unaligned_le16 (sent); } -static void hci_cc_reset (struct hci_dev *hdev,struct sk_buff *skb) -{ -__u8 status = *((__u8 *) skb->data); - -BT_DBG ("%s status 0x%2.2x" , hdev->name, status); - -clear_bit (HCI_RESET , &hdev->flags); - -if (status) -return ; - -/* Reset all non-persistent flags */ -hci_dev_clear_volatile_flags (hdev); - -hci_discovery_set_state (hdev,DISCOVERY_STOPPED ); - - hdev->inq_tx_power =HCI_TX_POWER_INVALID ; - hdev->adv_tx_power =HCI_TX_POWER_INVALID ; - -memset (hdev->adv_data,0 ,sizeof (hdev->adv_data)); - hdev->adv_data_len =0 ; - -memset (hdev->scan_rsp_data,0 ,sizeof (hdev->scan_rsp_data)); - hdev->scan_rsp_data_len =0 ; - - hdev->le_scan_type =LE_SCAN_PASSIVE ; - - hdev->ssp_debug_mode =0 ; - -hci_bdaddr_list_clear (&hdev->le_white_list); -} -static void hci_cc_read_stored_link_key (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -539,90 +720,6 @@ static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb)hci_dev_unlock (hdev); } -static void hci_cc_read_local_version (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_read_local_version *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - -if (hci_dev_test_flag (hdev,HCI_SETUP ) || -hci_dev_test_flag (hdev,HCI_CONFIG )) { - hdev->hci_ver = rp->hci_ver; - hdev->hci_rev =__le16_to_cpu (rp->hci_rev); - hdev->lmp_ver = rp->lmp_ver; - hdev->manufacturer =__le16_to_cpu (rp->manufacturer); - hdev->lmp_subver =__le16_to_cpu (rp->lmp_subver); - } -} - -static void hci_cc_read_local_commands (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_read_local_commands *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - -if (hci_dev_test_flag (hdev,HCI_SETUP ) || -hci_dev_test_flag (hdev,HCI_CONFIG )) -memcpy (hdev->commands, rp->commands,sizeof (hdev->commands)); -} - -static void hci_cc_read_local_features (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_read_local_features *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - -memcpy (hdev->features, rp->features,8 ); - -/* Adjust default settings according to features -* supported by device. */ - -if (hdev->features[0 ][0 ] &LMP_3SLOT ) - hdev->pkt_type |= (HCI_DM3 |HCI_DH3 ); - -if (hdev->features[0 ][0 ] &LMP_5SLOT ) - hdev->pkt_type |= (HCI_DM5 |HCI_DH5 ); - -if (hdev->features[0 ][1 ] &LMP_HV2 ) { - hdev->pkt_type |= (HCI_HV2 ); - hdev->esco_type |= (ESCO_HV2 ); - } - -if (hdev->features[0 ][1 ] &LMP_HV3 ) { - hdev->pkt_type |= (HCI_HV3 ); - hdev->esco_type |= (ESCO_HV3 ); - } - -if (lmp_esco_capable (hdev)) - hdev->esco_type |= (ESCO_EV3 ); - -if (hdev->features[0 ][4 ] &LMP_EV4 ) - hdev->esco_type |= (ESCO_EV4 ); - -if (hdev->features[0 ][4 ] &LMP_EV5 ) - hdev->esco_type |= (ESCO_EV5 ); - -if (hdev->features[0 ][5 ] &LMP_EDR_ESCO_2M ) - hdev->esco_type |= (ESCO_2EV3 ); - -if (hdev->features[0 ][5 ] &LMP_EDR_ESCO_3M ) - hdev->esco_type |= (ESCO_3EV3 ); - -if (hdev->features[0 ][5 ] &LMP_EDR_3S_ESCO ) - hdev->esco_type |= (ESCO_2EV5 |ESCO_3EV5 ); -} -static void hci_cc_read_local_ext_features (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -653,48 +750,6 @@ static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, hdev->flow_ctl_mode = rp->mode; } -static void hci_cc_read_buffer_size (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_read_buffer_size *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - - hdev->acl_mtu =__le16_to_cpu (rp->acl_mtu); - hdev->sco_mtu = rp->sco_mtu; - hdev->acl_pkts =__le16_to_cpu (rp->acl_max_pkt); - hdev->sco_pkts =__le16_to_cpu (rp->sco_max_pkt); - -if (test_bit (HCI_QUIRK_FIXUP_BUFFER_SIZE , &hdev->quirks)) { - hdev->sco_mtu =64 ; - hdev->sco_pkts =8 ; - } - - hdev->acl_cnt = hdev->acl_pkts; - hdev->sco_cnt = hdev->sco_pkts; - -BT_DBG ("%s acl mtu %d:%d sco mtu %d:%d" , hdev->name, hdev->acl_mtu, - hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); -} - -static void hci_cc_read_bd_addr (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_read_bd_addr *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - -if (test_bit (HCI_INIT , &hdev->flags)) -bacpy (&hdev->bdaddr, &rp->bdaddr); - -if (hci_dev_test_flag (hdev,HCI_SETUP )) -bacpy (&hdev->setup_addr, &rp->bdaddr); -} -static void hci_cc_read_page_scan_activity (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -815,28 +870,6 @@ unlock:hci_dev_unlock (hdev); } -static void hci_cc_read_local_amp_info (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_read_local_amp_info *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - - hdev->amp_status = rp->amp_status; - hdev->amp_total_bw =__le32_to_cpu (rp->total_bw); - hdev->amp_max_bw =__le32_to_cpu (rp->max_bw); - hdev->amp_min_latency =__le32_to_cpu (rp->min_latency); - hdev->amp_max_pdu =__le32_to_cpu (rp->max_pdu); - hdev->amp_type = rp->amp_type; - hdev->amp_pal_cap =__le16_to_cpu (rp->pal_cap); - hdev->amp_assoc_size =__le16_to_cpu (rp->max_assoc_size); - hdev->amp_be_flush_to =__le32_to_cpu (rp->be_flush_to); - hdev->amp_max_flush_to =__le32_to_cpu (rp->max_flush_to); -} -static void hci_cc_read_inq_rsp_tx_power (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -893,6 +926,126 @@ static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)hci_dev_unlock (hdev); } +static void hci_cc_user_confirm_reply (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_user_confirm_reply *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +hci_dev_lock (hdev); + +if (hci_dev_test_flag (hdev,HCI_MGMT )) +mgmt_user_confirm_reply_complete (hdev, &rp->bdaddr,ACL_LINK ,0 , + rp->status); + +hci_dev_unlock (hdev); +} + +static void hci_cc_user_confirm_neg_reply (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_user_confirm_reply *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +hci_dev_lock (hdev); + +if (hci_dev_test_flag (hdev,HCI_MGMT )) +mgmt_user_confirm_neg_reply_complete (hdev, &rp->bdaddr, +ACL_LINK ,0 , rp->status); + +hci_dev_unlock (hdev); +} + +static void hci_cc_user_passkey_reply (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_rp_user_confirm_reply *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +hci_dev_lock (hdev); + +if (hci_dev_test_flag (hdev,HCI_MGMT )) +mgmt_user_passkey_reply_complete (hdev, &rp->bdaddr,ACL_LINK , +0 , rp->status); + +hci_dev_unlock (hdev); +} + +static void hci_cc_user_passkey_neg_reply (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_user_confirm_reply *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +hci_dev_lock (hdev); + +if (hci_dev_test_flag (hdev,HCI_MGMT )) +mgmt_user_passkey_neg_reply_complete (hdev, &rp->bdaddr, +ACL_LINK ,0 , rp->status); + +hci_dev_unlock (hdev); +} + +static void hci_cc_read_local_oob_data (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_read_local_oob_data *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); +} + +static void hci_cc_read_local_oob_ext_data (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); +} + +static void hci_cc_write_ssp_debug_mode (struct hci_dev *hdev, +struct sk_buff *skb) +{ +u8 status = *((u8 *) skb->data); +u8 *mode; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, status); + +if (status) +return ; + + mode =hci_sent_cmd_data (hdev,HCI_OP_WRITE_SSP_DEBUG_MODE ); +if (mode) + hdev->ssp_debug_mode = *mode; +} +#endif + +#if IS_ENABLED (CONFIG_BT_HS ) +static void hci_cc_read_local_amp_info (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_rp_read_local_amp_info *rp = (void *) skb->data; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); + +if (rp->status) +return ; + + hdev->amp_status = rp->amp_status; + hdev->amp_total_bw =__le32_to_cpu (rp->total_bw); + hdev->amp_max_bw =__le32_to_cpu (rp->max_bw); + hdev->amp_min_latency =__le32_to_cpu (rp->min_latency); + hdev->amp_max_pdu =__le32_to_cpu (rp->max_pdu); + hdev->amp_type = rp->amp_type; + hdev->amp_pal_cap =__le16_to_cpu (rp->pal_cap); + hdev->amp_assoc_size =__le16_to_cpu (rp->max_assoc_size); + hdev->amp_be_flush_to =__le32_to_cpu (rp->be_flush_to); + hdev->amp_max_flush_to =__le32_to_cpu (rp->max_flush_to); +} +#endif + +#if IS_ENABLED (CONFIG_BT_LE )static void hci_cc_le_read_buffer_size (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -937,84 +1090,6 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, hdev->adv_tx_power = rp->tx_power; } -static void hci_cc_user_confirm_reply (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_user_confirm_reply *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -hci_dev_lock (hdev); - -if (hci_dev_test_flag (hdev,HCI_MGMT )) -mgmt_user_confirm_reply_complete (hdev, &rp->bdaddr,ACL_LINK ,0 , - rp->status); - -hci_dev_unlock (hdev); -} - -static void hci_cc_user_confirm_neg_reply (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_user_confirm_reply *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -hci_dev_lock (hdev); - -if (hci_dev_test_flag (hdev,HCI_MGMT )) -mgmt_user_confirm_neg_reply_complete (hdev, &rp->bdaddr, -ACL_LINK ,0 , rp->status); - -hci_dev_unlock (hdev); -} - -static void hci_cc_user_passkey_reply (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_user_confirm_reply *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -hci_dev_lock (hdev); - -if (hci_dev_test_flag (hdev,HCI_MGMT )) -mgmt_user_passkey_reply_complete (hdev, &rp->bdaddr,ACL_LINK , -0 , rp->status); - -hci_dev_unlock (hdev); -} - -static void hci_cc_user_passkey_neg_reply (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_user_confirm_reply *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -hci_dev_lock (hdev); - -if (hci_dev_test_flag (hdev,HCI_MGMT )) -mgmt_user_passkey_neg_reply_complete (hdev, &rp->bdaddr, -ACL_LINK ,0 , rp->status); - -hci_dev_unlock (hdev); -} - -static void hci_cc_read_local_oob_data (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_read_local_oob_data *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); -} - -static void hci_cc_read_local_oob_ext_data (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); -} -static void hci_cc_le_set_random_addr (struct hci_dev *hdev,struct sk_buff *skb) {__u8 status = *((__u8 *) skb->data);
@@ -1368,74 +1443,7 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) hdev->adv_addr_type = cp->own_address_type; hci_dev_unlock(hdev); } - -static void hci_cc_read_rssi (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_rp_read_rssi *rp = (void *) skb->data; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (rp->handle)); -if (conn) - conn->rssi = rp->rssi; - -hci_dev_unlock (hdev); -} - -static void hci_cc_read_tx_power (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_cp_read_tx_power *sent; -struct hci_rp_read_tx_power *rp = (void *) skb->data; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, rp->status); - -if (rp->status) -return ; - - sent =hci_sent_cmd_data (hdev,HCI_OP_READ_TX_POWER ); -if (!sent) -return ; - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (rp->handle)); -if (!conn) - goto unlock; - -switch (sent->type) { -case 0x00 : - conn->tx_power = rp->tx_power; -break ; -case 0x01 : - conn->max_tx_power = rp->tx_power; -break ; - } - -unlock: -hci_dev_unlock (hdev); -} - -static void hci_cc_write_ssp_debug_mode (struct hci_dev *hdev,struct sk_buff *skb) -{ -u8 status = *((u8 *) skb->data); -u8 *mode; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, status); - -if (status) -return ; - - mode =hci_sent_cmd_data (hdev,HCI_OP_WRITE_SSP_DEBUG_MODE ); -if (mode) - hdev->ssp_debug_mode = *mode; -} +#endif static void hci_cs_inquiry (struct hci_dev *hdev,__u8 status) {
@@ -2751,6 +2759,39 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,skb_pull (skb,sizeof (*ev));switch (*opcode) { +case HCI_OP_RESET : +hci_cc_reset (hdev, skb); +break ; + +case HCI_OP_READ_LOCAL_VERSION : +hci_cc_read_local_version (hdev, skb); +break ; + +case HCI_OP_READ_LOCAL_COMMANDS : +hci_cc_read_local_commands (hdev, skb); +break ; + +case HCI_OP_READ_LOCAL_FEATURES : +hci_cc_read_local_features (hdev, skb); +break ; + +case HCI_OP_READ_BUFFER_SIZE : +hci_cc_read_buffer_size (hdev, skb); +break ; + +case HCI_OP_READ_BD_ADDR : +hci_cc_read_bd_addr (hdev, skb); +break ; + +case HCI_OP_READ_RSSI : +hci_cc_read_rssi (hdev, skb); +break ; + +case HCI_OP_READ_TX_POWER : +hci_cc_read_tx_power (hdev, skb); +break ; + +#if IS_ENABLED (CONFIG_BT_BREDR )case HCI_OP_INQUIRY_CANCEL :hci_cc_inquiry_cancel (hdev, skb);break ;
@@ -2787,10 +2828,6 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cc_write_def_link_policy (hdev, skb);break ; -case HCI_OP_RESET : -hci_cc_reset (hdev, skb); -break ; -case HCI_OP_READ_STORED_LINK_KEY :hci_cc_read_stored_link_key (hdev, skb);break ;
@@ -2847,30 +2884,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cc_write_sc_support (hdev, skb);break ; -case HCI_OP_READ_LOCAL_VERSION : -hci_cc_read_local_version (hdev, skb); -break ; - -case HCI_OP_READ_LOCAL_COMMANDS : -hci_cc_read_local_commands (hdev, skb); -break ; - -case HCI_OP_READ_LOCAL_FEATURES : -hci_cc_read_local_features (hdev, skb); -break ; -case HCI_OP_READ_LOCAL_EXT_FEATURES :hci_cc_read_local_ext_features (hdev, skb);break ; -case HCI_OP_READ_BUFFER_SIZE : -hci_cc_read_buffer_size (hdev, skb); -break ; - -case HCI_OP_READ_BD_ADDR : -hci_cc_read_bd_addr (hdev, skb); -break ; -case HCI_OP_READ_PAGE_SCAN_ACTIVITY :hci_cc_read_page_scan_activity (hdev, skb);break ;
@@ -2895,10 +2912,6 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cc_read_flow_control_mode (hdev, skb);break ; -case HCI_OP_READ_LOCAL_AMP_INFO : -hci_cc_read_local_amp_info (hdev, skb); -break ; -case HCI_OP_READ_CLOCK :hci_cc_read_clock (hdev, skb);break ;
@@ -2923,18 +2936,6 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cc_read_local_oob_ext_data (hdev, skb);break ; -case HCI_OP_LE_READ_BUFFER_SIZE : -hci_cc_le_read_buffer_size (hdev, skb); -break ; - -case HCI_OP_LE_READ_LOCAL_FEATURES : -hci_cc_le_read_local_features (hdev, skb); -break ; - -case HCI_OP_LE_READ_ADV_TX_POWER : -hci_cc_le_read_adv_tx_power (hdev, skb); -break ; -case HCI_OP_USER_CONFIRM_REPLY :hci_cc_user_confirm_reply (hdev, skb);break ;
@@ -2951,6 +2952,30 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cc_user_passkey_neg_reply (hdev, skb);break ; +case HCI_OP_WRITE_SSP_DEBUG_MODE : +hci_cc_write_ssp_debug_mode (hdev, skb); +break ; +#endif + +#if IS_ENABLED (CONFIG_BT_HS ) +case HCI_OP_READ_LOCAL_AMP_INFO : +hci_cc_read_local_amp_info (hdev, skb); +break ; +#endif + +#if IS_ENABLED (CONFIG_BT_LE ) +case HCI_OP_LE_READ_BUFFER_SIZE : +hci_cc_le_read_buffer_size (hdev, skb); +break ; + +case HCI_OP_LE_READ_LOCAL_FEATURES : +hci_cc_le_read_local_features (hdev, skb); +break ; + +case HCI_OP_LE_READ_ADV_TX_POWER : +hci_cc_le_read_adv_tx_power (hdev, skb); +break ; +case HCI_OP_LE_SET_RANDOM_ADDR :hci_cc_le_set_random_addr (hdev, skb);break ;
@@ -3006,18 +3031,7 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,case HCI_OP_LE_SET_ADV_PARAM :hci_cc_set_adv_param (hdev, skb);break ; - -case HCI_OP_READ_RSSI : -hci_cc_read_rssi (hdev, skb); -break ; - -case HCI_OP_READ_TX_POWER : -hci_cc_read_tx_power (hdev, skb); -break ; - -case HCI_OP_WRITE_SSP_DEBUG_MODE : -hci_cc_write_ssp_debug_mode (hdev, skb); -break ; +#endif default :BT_DBG ("%s opcode 0x%4.4x" , hdev->name, *opcode);
Signature · 1 line
1.7.9.5
PATCH 2/3 Bluetooth: Classify HCI cmd status event under corresponding config option
Signed-off-by Arron Wang <[email protected]>
--- net/bluetooth/hci_event.c | 74 +++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 33 deletions(-)
net/bluetooth/hci_event.c +41 -33
@@ -1445,6 +1445,29 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) }#endif +static void hci_cs_disconnect (struct hci_dev *hdev,u8 status) +{ +struct hci_cp_disconnect *cp; +struct hci_conn *conn; + +if (!status) +return ; + + cp =hci_sent_cmd_data (hdev,HCI_OP_DISCONNECT ); +if (!cp) +return ; + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (cp->handle)); +if (conn) +mgmt_disconnect_failed (hdev, &conn->dst, conn->type, + conn->dst_type, status); + +hci_dev_unlock (hdev); +} + +#if IS_ENABLED (CONFIG_BT_BREDR )static void hci_cs_inquiry (struct hci_dev *hdev,__u8 status) {BT_DBG ("%s status 0x%2.2x" , hdev->name, status);
@@ -1876,28 +1899,31 @@ static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)hci_dev_unlock (hdev); } -static void hci_cs_disconnect (struct hci_dev *hdev,u8 status) +static void hci_cs_switch_role (struct hci_dev *hdev,u8 status) { -struct hci_cp_disconnect *cp; +struct hci_cp_switch_role *cp;struct hci_conn *conn; +BT_DBG ("%s status 0x%2.2x" , hdev->name, status); +if (!status)return ; - cp =hci_sent_cmd_data (hdev,HCI_OP_DISCONNECT ); + cp =hci_sent_cmd_data (hdev,HCI_OP_SWITCH_ROLE );if (!cp)return ;hci_dev_lock (hdev); - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (cp->handle)); + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &cp->bdaddr);if (conn) -mgmt_disconnect_failed (hdev, &conn->dst, conn->type, - conn->dst_type, status); +clear_bit (HCI_CONN_RSWITCH_PEND , &conn->flags);hci_dev_unlock (hdev); } +#endif +#if IS_ENABLED (CONFIG_BT_LE )static void hci_cs_le_create_conn (struct hci_dev *hdev,u8 status) {struct hci_cp_le_create_conn *cp;
@@ -2005,29 +2031,7 @@ static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) unlock: hci_dev_unlock(hdev); } - -static void hci_cs_switch_role (struct hci_dev *hdev,u8 status) -{ -struct hci_cp_switch_role *cp; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, status); - -if (!status) -return ; - - cp =hci_sent_cmd_data (hdev,HCI_OP_SWITCH_ROLE ); -if (!cp) -return ; - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &cp->bdaddr); -if (conn) -clear_bit (HCI_CONN_RSWITCH_PEND , &conn->flags); - -hci_dev_unlock (hdev); -} +#endif static void hci_inquiry_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) {
@@ -3064,6 +3068,11 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb, *status = ev->status;switch (*opcode) { +case HCI_OP_DISCONNECT : +hci_cs_disconnect (hdev, ev->status); +break ; + +#if IS_ENABLED (CONFIG_BT_BREDR )case HCI_OP_INQUIRY :hci_cs_inquiry (hdev, ev->status);break ;
@@ -3072,10 +3081,6 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,hci_cs_create_conn (hdev, ev->status);break ; -case HCI_OP_DISCONNECT : -hci_cs_disconnect (hdev, ev->status); -break ; -case HCI_OP_ADD_SCO :hci_cs_add_sco (hdev, ev->status);break ;
@@ -3115,7 +3120,9 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,case HCI_OP_SWITCH_ROLE :hci_cs_switch_role (hdev, ev->status);break ; +#endif +#if IS_ENABLED (CONFIG_BT_LE )case HCI_OP_LE_CREATE_CONN :hci_cs_le_create_conn (hdev, ev->status);break ;
@@ -3127,6 +3134,7 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,case HCI_OP_LE_START_ENC :hci_cs_le_start_enc (hdev, ev->status);break ; +#endif default :BT_DBG ("%s opcode 0x%4.4x" , hdev->name, *opcode);
Signature · 1 line
1.7.9.5
PATCH 3/3 Bluetooth: Classify HCI cmd event under corresponding config option
In reply to Arron WangSigned-off-by Arron Wang <[email protected]>
--- net/bluetooth/hci_event.c | 757 +++++++++++++++++++++++---------------------- 1 file changed, 385 insertions(+), 372 deletions(-)
net/bluetooth/hci_event.c +385 -372
@@ -2033,6 +2033,260 @@ unlock: }#endif +static u8 hci_to_mgmt_reason (u8 err) +{ +switch (err) { +case HCI_ERROR_CONNECTION_TIMEOUT : +return MGMT_DEV_DISCONN_TIMEOUT ; +case HCI_ERROR_REMOTE_USER_TERM : +case HCI_ERROR_REMOTE_LOW_RESOURCES : +case HCI_ERROR_REMOTE_POWER_OFF : +return MGMT_DEV_DISCONN_REMOTE ; +case HCI_ERROR_LOCAL_HOST_TERM : +return MGMT_DEV_DISCONN_LOCAL_HOST ; +default : +return MGMT_DEV_DISCONN_UNKNOWN ; + } +} + +static void hci_disconn_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_ev_disconn_complete *ev = (void *) skb->data; +u8 reason =hci_to_mgmt_reason (ev->reason); +struct hci_conn_params *params; +struct hci_conn *conn; +bool mgmt_connected; +u8 type; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); +if (!conn) + goto unlock; + +if (ev->status) { +mgmt_disconnect_failed (hdev, &conn->dst, conn->type, + conn->dst_type, ev->status); + goto unlock; + } + + conn->state =BT_CLOSED ; + + mgmt_connected =test_and_clear_bit (HCI_CONN_MGMT_CONNECTED , + &conn->flags); +mgmt_device_disconnected (hdev, &conn->dst, conn->type, conn->dst_type, + reason, mgmt_connected); + +if (conn->type ==ACL_LINK ) { +if (test_bit (HCI_CONN_FLUSH_KEY , &conn->flags)) +hci_remove_link_key (hdev, &conn->dst); + +hci_update_page_scan (hdev); + } + + params =hci_conn_params_lookup (hdev, &conn->dst, conn->dst_type); +if (params) { +switch (params->auto_connect) { +case HCI_AUTO_CONN_LINK_LOSS : +if (ev->reason !=HCI_ERROR_CONNECTION_TIMEOUT ) +break ; +/* Fall through */ + +case HCI_AUTO_CONN_DIRECT : +case HCI_AUTO_CONN_ALWAYS : +list_del_init (¶ms->action); +list_add (¶ms->action, &hdev->pend_le_conns); +hci_update_background_scan (hdev); +break ; + +default : +break ; + } + } + + type = conn->type; + +hci_disconn_cfm (conn, ev->reason); +hci_conn_del (conn); + +/* Re-enable advertising if necessary, since it might +* have been disabled by the connection. From the +* HCI_LE_Set_Advertise_Enable command description in +* the core specification (v4.0): +* "The Controller shall continue advertising until the Host +* issues an LE_Set_Advertise_Enable command with +* Advertising_Enable set to 0x00 (Advertising is disabled) +* or until a connection is created or until the Advertising +* is timed out due to Directed Advertising." +*/ +if (type ==LE_LINK ) +mgmt_reenable_advertising (hdev); + +unlock: +hci_dev_unlock (hdev); +} + +static void read_enc_key_size_complete (struct hci_dev *hdev,u8 status, +u16 opcode,struct sk_buff *skb) +{ +const struct hci_rp_read_enc_key_size *rp; +struct hci_conn *conn; +u16 handle; + +BT_DBG ("%s status 0x%02x" , hdev->name, status); + +if (!skb || skb->len <sizeof (*rp)) { +BT_ERR ("%s invalid HCI Read Encryption Key Size response" , + hdev->name); +return ; + } + + rp = (void *)skb->data; + handle =le16_to_cpu (rp->handle); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev, handle); +if (!conn) + goto unlock; + +/* If we fail to read the encryption key size, assume maximum +* (which is the same we do also when this HCI command isn't +* supported. +*/ +if (rp->status) { +BT_ERR ("%s failed to read key size for handle %u" , hdev->name, + handle); + conn->enc_key_size =HCI_LINK_KEY_SIZE ; + }else { + conn->enc_key_size = rp->key_size; + } + +if (conn->state ==BT_CONFIG ) { + conn->state =BT_CONNECTED ; +hci_connect_cfm (conn,0 ); +hci_conn_drop (conn); + }else { +u8 encrypt; + +if (!test_bit (HCI_CONN_ENCRYPT , &conn->flags)) + encrypt =0x00 ; +else if (test_bit (HCI_CONN_AES_CCM , &conn->flags)) + encrypt =0x02 ; +else + encrypt =0x01 ; + +hci_encrypt_cfm (conn,0 , encrypt); + } + +unlock: +hci_dev_unlock (hdev); +} + +static void hci_encrypt_change_evt (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_ev_encrypt_change *ev = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); +if (!conn) + goto unlock; + +if (!ev->status) { +if (ev->encrypt) { +/* Encryption implies authentication */ +set_bit (HCI_CONN_AUTH , &conn->flags); +set_bit (HCI_CONN_ENCRYPT , &conn->flags); + conn->sec_level = conn->pending_sec_level; + +/* P-256 authentication key implies FIPS */ +if (conn->key_type ==HCI_LK_AUTH_COMBINATION_P256 ) +set_bit (HCI_CONN_FIPS , &conn->flags); + +if ((conn->type ==ACL_LINK && ev->encrypt ==0x02 ) || + conn->type ==LE_LINK ) +set_bit (HCI_CONN_AES_CCM , &conn->flags); + }else { +clear_bit (HCI_CONN_ENCRYPT , &conn->flags); +clear_bit (HCI_CONN_AES_CCM , &conn->flags); + } + } + +/* We should disregard the current RPA and generate a new one +* whenever the encryption procedure fails. +*/ +if (ev->status && conn->type ==LE_LINK ) +hci_dev_set_flag (hdev,HCI_RPA_EXPIRED ); + +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); + +if (ev->status && conn->state ==BT_CONNECTED ) { +hci_disconnect (conn,HCI_ERROR_AUTH_FAILURE ); +hci_conn_drop (conn); + goto unlock; + } + +/* In Secure Connections Only mode, do not allow any connections +* that are not encrypted with AES-CCM using a P-256 authenticated +* combination key. +*/ +if (hci_dev_test_flag (hdev,HCI_SC_ONLY ) && + (!test_bit (HCI_CONN_AES_CCM , &conn->flags) || + conn->key_type !=HCI_LK_AUTH_COMBINATION_P256 )) { +hci_connect_cfm (conn,HCI_ERROR_AUTH_FAILURE ); +hci_conn_drop (conn); + goto unlock; + } + +/* Try reading the encryption key size for encrypted ACL links */ +if (!ev->status && ev->encrypt && conn->type ==ACL_LINK ) { +struct hci_cp_read_enc_key_size cp; +struct hci_request req; + +/* Only send HCI_Read_Encryption_Key_Size if the +* controller really supports it. If it doesn't, assume +* the default size (16). +*/ +if (!(hdev->commands[20 ] &0x10 )) { + conn->enc_key_size =HCI_LINK_KEY_SIZE ; + goto notify; + } + +hci_req_init (&req, hdev); + + cp.handle =cpu_to_le16 (conn->handle); +hci_req_add (&req,HCI_OP_READ_ENC_KEY_SIZE ,sizeof (cp), &cp); + +if (hci_req_run_skb (&req, read_enc_key_size_complete)) { +BT_ERR ("Sending HCI Read Encryption Key Size failed" ); + conn->enc_key_size =HCI_LINK_KEY_SIZE ; + goto notify; + } + + goto unlock; + } + +notify: +if (conn->state ==BT_CONFIG ) { +if (!ev->status) + conn->state =BT_CONNECTED ; + +hci_connect_cfm (conn, ev->status); +hci_conn_drop (conn); + }else +hci_encrypt_cfm (conn, ev->status, ev->encrypt); + +unlock: +hci_dev_unlock (hdev); +} + +#if IS_ENABLED (CONFIG_BT_BREDR )static void hci_inquiry_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) {__u8 status = *((__u8 *) skb->data);
@@ -2319,100 +2573,6 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) } } -static u8 hci_to_mgmt_reason (u8 err) -{ -switch (err) { -case HCI_ERROR_CONNECTION_TIMEOUT : -return MGMT_DEV_DISCONN_TIMEOUT ; -case HCI_ERROR_REMOTE_USER_TERM : -case HCI_ERROR_REMOTE_LOW_RESOURCES : -case HCI_ERROR_REMOTE_POWER_OFF : -return MGMT_DEV_DISCONN_REMOTE ; -case HCI_ERROR_LOCAL_HOST_TERM : -return MGMT_DEV_DISCONN_LOCAL_HOST ; -default : -return MGMT_DEV_DISCONN_UNKNOWN ; - } -} - -static void hci_disconn_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_ev_disconn_complete *ev = (void *) skb->data; -u8 reason =hci_to_mgmt_reason (ev->reason); -struct hci_conn_params *params; -struct hci_conn *conn; -bool mgmt_connected; -u8 type; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); -if (!conn) - goto unlock; - -if (ev->status) { -mgmt_disconnect_failed (hdev, &conn->dst, conn->type, - conn->dst_type, ev->status); - goto unlock; - } - - conn->state =BT_CLOSED ; - - mgmt_connected =test_and_clear_bit (HCI_CONN_MGMT_CONNECTED , &conn->flags); -mgmt_device_disconnected (hdev, &conn->dst, conn->type, conn->dst_type, - reason, mgmt_connected); - -if (conn->type ==ACL_LINK ) { -if (test_bit (HCI_CONN_FLUSH_KEY , &conn->flags)) -hci_remove_link_key (hdev, &conn->dst); - -hci_update_page_scan (hdev); - } - - params =hci_conn_params_lookup (hdev, &conn->dst, conn->dst_type); -if (params) { -switch (params->auto_connect) { -case HCI_AUTO_CONN_LINK_LOSS : -if (ev->reason !=HCI_ERROR_CONNECTION_TIMEOUT ) -break ; -/* Fall through */ - -case HCI_AUTO_CONN_DIRECT : -case HCI_AUTO_CONN_ALWAYS : -list_del_init (¶ms->action); -list_add (¶ms->action, &hdev->pend_le_conns); -hci_update_background_scan (hdev); -break ; - -default : -break ; - } - } - - type = conn->type; - -hci_disconn_cfm (conn, ev->reason); -hci_conn_del (conn); - -/* Re-enable advertising if necessary, since it might -* have been disabled by the connection. From the -* HCI_LE_Set_Advertise_Enable command description in -* the core specification (v4.0): -* "The Controller shall continue advertising until the Host -* issues an LE_Set_Advertise_Enable command with -* Advertising_Enable set to 0x00 (Advertising is disabled) -* or until a connection is created or until the Advertising -* is timed out due to Directed Advertising." -*/ -if (type ==LE_LINK ) -mgmt_reenable_advertising (hdev); - -unlock: -hci_dev_unlock (hdev); -} -static void hci_auth_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) {struct hci_ev_auth_complete *ev = (void *) skb->data;
@@ -2483,196 +2643,38 @@ static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)struct hci_ev_remote_name *ev = (void *) skb->data;struct hci_conn *conn; -BT_DBG ("%s" , hdev->name); - -hci_conn_check_pending (hdev); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr); - -if (!hci_dev_test_flag (hdev,HCI_MGMT )) - goto check_auth; - -if (ev->status ==0 ) -hci_check_pending_name (hdev, conn, &ev->bdaddr, ev->name, -strnlen (ev->name,HCI_MAX_NAME_LENGTH )); -else -hci_check_pending_name (hdev, conn, &ev->bdaddr,NULL ,0 ); - -check_auth: -if (!conn) - goto unlock; - -if (!hci_outgoing_auth_needed (hdev, conn)) - goto unlock; - -if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) { -struct hci_cp_auth_requested cp; - -set_bit (HCI_CONN_AUTH_INITIATOR , &conn->flags); - - cp.handle =__cpu_to_le16 (conn->handle); -hci_send_cmd (hdev,HCI_OP_AUTH_REQUESTED ,sizeof (cp), &cp); - } - -unlock: -hci_dev_unlock (hdev); -} - -static void read_enc_key_size_complete (struct hci_dev *hdev,u8 status, -u16 opcode,struct sk_buff *skb) -{ -const struct hci_rp_read_enc_key_size *rp; -struct hci_conn *conn; -u16 handle; - -BT_DBG ("%s status 0x%02x" , hdev->name, status); - -if (!skb || skb->len <sizeof (*rp)) { -BT_ERR ("%s invalid HCI Read Encryption Key Size response" , - hdev->name); -return ; - } - - rp = (void *)skb->data; - handle =le16_to_cpu (rp->handle); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev, handle); -if (!conn) - goto unlock; - -/* If we fail to read the encryption key size, assume maximum -* (which is the same we do also when this HCI command isn't -* supported. -*/ -if (rp->status) { -BT_ERR ("%s failed to read key size for handle %u" , hdev->name, - handle); - conn->enc_key_size =HCI_LINK_KEY_SIZE ; - }else { - conn->enc_key_size = rp->key_size; - } - -if (conn->state ==BT_CONFIG ) { - conn->state =BT_CONNECTED ; -hci_connect_cfm (conn,0 ); -hci_conn_drop (conn); - }else { -u8 encrypt; - -if (!test_bit (HCI_CONN_ENCRYPT , &conn->flags)) - encrypt =0x00 ; -else if (test_bit (HCI_CONN_AES_CCM , &conn->flags)) - encrypt =0x02 ; -else - encrypt =0x01 ; - -hci_encrypt_cfm (conn,0 , encrypt); - } - -unlock: -hci_dev_unlock (hdev); -} - -static void hci_encrypt_change_evt (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_ev_encrypt_change *ev = (void *) skb->data; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); -if (!conn) - goto unlock; - -if (!ev->status) { -if (ev->encrypt) { -/* Encryption implies authentication */ -set_bit (HCI_CONN_AUTH , &conn->flags); -set_bit (HCI_CONN_ENCRYPT , &conn->flags); - conn->sec_level = conn->pending_sec_level; - -/* P-256 authentication key implies FIPS */ -if (conn->key_type ==HCI_LK_AUTH_COMBINATION_P256 ) -set_bit (HCI_CONN_FIPS , &conn->flags); - -if ((conn->type ==ACL_LINK && ev->encrypt ==0x02 ) || - conn->type ==LE_LINK ) -set_bit (HCI_CONN_AES_CCM , &conn->flags); - }else { -clear_bit (HCI_CONN_ENCRYPT , &conn->flags); -clear_bit (HCI_CONN_AES_CCM , &conn->flags); - } - } - -/* We should disregard the current RPA and generate a new one -* whenever the encryption procedure fails. -*/ -if (ev->status && conn->type ==LE_LINK ) -hci_dev_set_flag (hdev,HCI_RPA_EXPIRED ); - -clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); - -if (ev->status && conn->state ==BT_CONNECTED ) { -hci_disconnect (conn,HCI_ERROR_AUTH_FAILURE ); -hci_conn_drop (conn); - goto unlock; - } - -/* In Secure Connections Only mode, do not allow any connections -* that are not encrypted with AES-CCM using a P-256 authenticated -* combination key. -*/ -if (hci_dev_test_flag (hdev,HCI_SC_ONLY ) && - (!test_bit (HCI_CONN_AES_CCM , &conn->flags) || - conn->key_type !=HCI_LK_AUTH_COMBINATION_P256 )) { -hci_connect_cfm (conn,HCI_ERROR_AUTH_FAILURE ); -hci_conn_drop (conn); - goto unlock; - } - -/* Try reading the encryption key size for encrypted ACL links */ -if (!ev->status && ev->encrypt && conn->type ==ACL_LINK ) { -struct hci_cp_read_enc_key_size cp; -struct hci_request req; +BT_DBG ("%s" , hdev->name); -/* Only send HCI_Read_Encryption_Key_Size if the -* controller really supports it. If it doesn't, assume -* the default size (16). -*/ -if (!(hdev->commands[20 ] &0x10 )) { - conn->enc_key_size =HCI_LINK_KEY_SIZE ; - goto notify; - } +hci_conn_check_pending (hdev); -hci_req_init (&req, hdev); +hci_dev_lock (hdev); - cp.handle =cpu_to_le16 (conn->handle); -hci_req_add (&req,HCI_OP_READ_ENC_KEY_SIZE ,sizeof (cp), &cp); + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr); -if (hci_req_run_skb (&req, read_enc_key_size_complete)) { -BT_ERR ("Sending HCI Read Encryption Key Size failed" ); - conn->enc_key_size =HCI_LINK_KEY_SIZE ; - goto notify; - } +if (!hci_dev_test_flag (hdev,HCI_MGMT )) + goto check_auth; + +if (ev->status ==0 ) +hci_check_pending_name (hdev, conn, &ev->bdaddr, ev->name, +strnlen (ev->name,HCI_MAX_NAME_LENGTH )); +else +hci_check_pending_name (hdev, conn, &ev->bdaddr,NULL ,0 ); +check_auth: +if (!conn) goto unlock; - } -notify: -if (conn->state ==BT_CONFIG ) { -if (!ev->status) - conn->state =BT_CONNECTED ; +if (!hci_outgoing_auth_needed (hdev, conn)) + goto unlock; -hci_connect_cfm (conn, ev->status); -hci_conn_drop (conn); - }else -hci_encrypt_cfm (conn, ev->status, ev->encrypt); +if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) { +struct hci_cp_auth_requested cp; + +set_bit (HCI_CONN_AUTH_INITIATOR , &conn->flags); + + cp.handle =__cpu_to_le16 (conn->handle); +hci_send_cmd (hdev,HCI_OP_AUTH_REQUESTED ,sizeof (cp), &cp); + } unlock:hci_dev_unlock (hdev);
@@ -2749,6 +2751,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev, unlock:hci_dev_unlock (hdev); } +#endif static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, u16 *opcode, u8 *status,
@@ -3171,28 +3174,6 @@ static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb)queue_work (hdev->req_workqueue, &hdev->error_reset); } -static void hci_role_change_evt (struct hci_dev *hdev,struct sk_buff *skb) -{ -struct hci_ev_role_change *ev = (void *) skb->data; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr); -if (conn) { -if (!ev->status) - conn->role = ev->role; - -clear_bit (HCI_CONN_RSWITCH_PEND , &conn->flags); - -hci_role_switch_cfm (conn, ev->status, ev->role); - } - -hci_dev_unlock (hdev); -} -static void hci_num_comp_pkts_evt (struct hci_dev *hdev,struct sk_buff *skb) {struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
@@ -3259,6 +3240,79 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)queue_work (hdev->workqueue, &hdev->tx_work); } +static void hci_key_refresh_complete_evt (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_ev_key_refresh_complete *ev = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status 0x%2.2x handle 0x%4.4x" , hdev->name, ev->status, +__le16_to_cpu (ev->handle)); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); +if (!conn) + goto unlock; + +/* For BR/EDR the necessary steps are taken through the +* auth_complete event. +*/ +if (conn->type !=LE_LINK ) + goto unlock; + +if (!ev->status) + conn->sec_level = conn->pending_sec_level; + +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); + +if (ev->status && conn->state ==BT_CONNECTED ) { +hci_disconnect (conn,HCI_ERROR_AUTH_FAILURE ); +hci_conn_drop (conn); + goto unlock; + } + +if (conn->state ==BT_CONFIG ) { +if (!ev->status) + conn->state =BT_CONNECTED ; + +hci_connect_cfm (conn, ev->status); +hci_conn_drop (conn); + }else { +hci_auth_cfm (conn, ev->status); + +hci_conn_hold (conn); + conn->disc_timeout =HCI_DISCONN_TIMEOUT ; +hci_conn_drop (conn); + } + +unlock: +hci_dev_unlock (hdev); +} + +#if IS_ENABLED (CONFIG_BT_BREDR ) +static void hci_role_change_evt (struct hci_dev *hdev,struct sk_buff *skb) +{ +struct hci_ev_role_change *ev = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status 0x%2.2x" , hdev->name, ev->status); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_ba (hdev,ACL_LINK , &ev->bdaddr); +if (conn) { +if (!ev->status) + conn->role = ev->role; + +clear_bit (HCI_CONN_RSWITCH_PEND , &conn->flags); + +hci_role_switch_cfm (conn, ev->status, ev->role); + } + +hci_dev_unlock (hdev); +} +static struct hci_conn *__hci_conn_lookup_handle (struct hci_dev *hdev,__u16 handle) {
@@ -3859,56 +3913,6 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,hci_dev_unlock (hdev); } -static void hci_key_refresh_complete_evt (struct hci_dev *hdev, -struct sk_buff *skb) -{ -struct hci_ev_key_refresh_complete *ev = (void *) skb->data; -struct hci_conn *conn; - -BT_DBG ("%s status 0x%2.2x handle 0x%4.4x" , hdev->name, ev->status, -__le16_to_cpu (ev->handle)); - -hci_dev_lock (hdev); - - conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); -if (!conn) - goto unlock; - -/* For BR/EDR the necessary steps are taken through the -* auth_complete event. -*/ -if (conn->type !=LE_LINK ) - goto unlock; - -if (!ev->status) - conn->sec_level = conn->pending_sec_level; - -clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); - -if (ev->status && conn->state ==BT_CONNECTED ) { -hci_disconnect (conn,HCI_ERROR_AUTH_FAILURE ); -hci_conn_drop (conn); - goto unlock; - } - -if (conn->state ==BT_CONFIG ) { -if (!ev->status) - conn->state =BT_CONNECTED ; - -hci_connect_cfm (conn, ev->status); -hci_conn_drop (conn); - }else { -hci_auth_cfm (conn, ev->status); - -hci_conn_hold (conn); - conn->disc_timeout =HCI_DISCONN_TIMEOUT ; -hci_conn_drop (conn); - } - -unlock: -hci_dev_unlock (hdev); -} -static u8 hci_get_auth_req (struct hci_conn *conn) {/* If remote requests no-bonding follow that lead */
@@ -4309,6 +4313,7 @@ static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, unlock: hci_dev_unlock(hdev); } +#endif #if IS_ENABLED (CONFIG_BT_HS )static void hci_chan_selected_evt (struct hci_dev *hdev,struct sk_buff *skb)
@@ -4452,6 +4457,7 @@ static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, }#endif +#if IS_ENABLED (CONFIG_BT_LE )static void hci_le_conn_complete_evt (struct hci_dev *hdev,struct sk_buff *skb) {struct hci_ev_le_conn_complete *ev = (void *) skb->data;
@@ -5141,6 +5147,7 @@ static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) break; } } +#endif static bool hci_get_cmd_complete (struct hci_dev *hdev,u16 opcode,u8 event,struct sk_buff *skb)
@@ -5216,6 +5223,15 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)skb_pull (skb,HCI_EVENT_HDR_SIZE );switch (event) { +case HCI_EV_DISCONN_COMPLETE : +hci_disconn_complete_evt (hdev, skb); +break ; + +case HCI_EV_ENCRYPT_CHANGE : +hci_encrypt_change_evt (hdev, skb); +break ; + +#if IS_ENABLED (CONFIG_BT_BREDR )case HCI_EV_INQUIRY_COMPLETE :hci_inquiry_complete_evt (hdev, skb);break ;
@@ -5232,10 +5248,6 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_conn_request_evt (hdev, skb);break ; -case HCI_EV_DISCONN_COMPLETE : -hci_disconn_complete_evt (hdev, skb); -break ; -case HCI_EV_AUTH_COMPLETE :hci_auth_complete_evt (hdev, skb);break ;
@@ -5244,10 +5256,6 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_remote_name_evt (hdev, skb);break ; -case HCI_EV_ENCRYPT_CHANGE : -hci_encrypt_change_evt (hdev, skb); -break ; -case HCI_EV_CHANGE_LINK_KEY_COMPLETE :hci_change_link_key_complete_evt (hdev, skb);break ;
@@ -5255,6 +5263,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)case HCI_EV_REMOTE_FEATURES :hci_remote_features_evt (hdev, skb);break ; +#endif case HCI_EV_CMD_COMPLETE : hci_cmd_complete_evt(hdev, skb, &opcode, &status,
@@ -5270,14 +5279,19 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_hardware_error_evt (hdev, skb);break ; -case HCI_EV_ROLE_CHANGE : -hci_role_change_evt (hdev, skb); -break ; -case HCI_EV_NUM_COMP_PKTS :hci_num_comp_pkts_evt (hdev, skb);break ; +case HCI_EV_KEY_REFRESH_COMPLETE : +hci_key_refresh_complete_evt (hdev, skb); +break ; + +#if IS_ENABLED (CONFIG_BT_BREDR ) +case HCI_EV_ROLE_CHANGE : +hci_role_change_evt (hdev, skb); +break ; +case HCI_EV_MODE_CHANGE :hci_mode_change_evt (hdev, skb);break ;
@@ -5322,10 +5336,6 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_extended_inquiry_result_evt (hdev, skb);break ; -case HCI_EV_KEY_REFRESH_COMPLETE : -hci_key_refresh_complete_evt (hdev, skb); -break ; -case HCI_EV_IO_CAPA_REQUEST :hci_io_capa_request_evt (hdev, skb);break ;
@@ -5358,14 +5368,21 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_remote_host_features_evt (hdev, skb);break ; -case HCI_EV_LE_META : -hci_le_meta_evt (hdev, skb); -break ; -case HCI_EV_REMOTE_OOB_DATA_REQUEST :hci_remote_oob_data_request_evt (hdev, skb);break ; +case HCI_EV_NUM_COMP_BLOCKS : +hci_num_comp_blocks_evt (hdev, skb); +break ; +#endif + +#if IS_ENABLED (CONFIG_BT_LE ) +case HCI_EV_LE_META : +hci_le_meta_evt (hdev, skb); +break ; +#endif +#if IS_ENABLED (CONFIG_BT_HS )case HCI_EV_CHANNEL_SELECTED :hci_chan_selected_evt (hdev, skb);
@@ -5388,10 +5405,6 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)break ;#endif -case HCI_EV_NUM_COMP_BLOCKS : -hci_num_comp_blocks_evt (hdev, skb); -break ; -default :BT_DBG ("%s event 0x%2.2x" , hdev->name, event);break ;
Signature · 1 line
1.7.9.5