Commit 45296acd authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg

Bluetooth: Use a more simpler style for HCI event callbacks

The HCI event callbacks have grown over the last years and some
functions handle status checking different than others. For the
simple ones, check the status at the beginning and exit if an
error with the HCI command occured.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent f4537c04
...@@ -175,11 +175,13 @@ static void hci_cc_write_def_link_policy(struct hci_dev *hdev, ...@@ -175,11 +175,13 @@ static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
if (!sent) if (!sent)
return; return;
if (!status)
hdev->link_policy = get_unaligned_le16(sent); hdev->link_policy = get_unaligned_le16(sent);
} }
...@@ -270,27 +272,30 @@ static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -270,27 +272,30 @@ static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
{ {
__u8 status = *((__u8 *) skb->data); __u8 status = *((__u8 *) skb->data);
__u8 param;
void *sent; void *sent;
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
if (!sent) if (!sent)
return; return;
if (!status) { param = *((__u8 *) sent);
__u8 param = *((__u8 *) sent);
if (param) if (param)
set_bit(HCI_ENCRYPT, &hdev->flags); set_bit(HCI_ENCRYPT, &hdev->flags);
else else
clear_bit(HCI_ENCRYPT, &hdev->flags); clear_bit(HCI_ENCRYPT, &hdev->flags);
}
} }
static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
{ {
__u8 param, status = *((__u8 *) skb->data); __u8 status = *((__u8 *) skb->data);
__u8 param;
int old_pscan, old_iscan; int old_pscan, old_iscan;
void *sent; void *sent;
...@@ -602,7 +607,9 @@ static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, ...@@ -602,7 +607,9 @@ static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (!rp->status) if (rp->status)
return;
hdev->flow_ctl_mode = rp->mode; hdev->flow_ctl_mode = rp->mode;
} }
...@@ -649,7 +656,10 @@ static void hci_cc_read_page_scan_activity(struct hci_dev *hdev, ...@@ -649,7 +656,10 @@ static void hci_cc_read_page_scan_activity(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (test_bit(HCI_INIT, &hdev->flags) && !rp->status) { if (rp->status)
return;
if (test_bit(HCI_INIT, &hdev->flags)) {
hdev->page_scan_interval = __le16_to_cpu(rp->interval); hdev->page_scan_interval = __le16_to_cpu(rp->interval);
hdev->page_scan_window = __le16_to_cpu(rp->window); hdev->page_scan_window = __le16_to_cpu(rp->window);
} }
...@@ -681,7 +691,10 @@ static void hci_cc_read_page_scan_type(struct hci_dev *hdev, ...@@ -681,7 +691,10 @@ static void hci_cc_read_page_scan_type(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (test_bit(HCI_INIT, &hdev->flags) && !rp->status) if (rp->status)
return;
if (test_bit(HCI_INIT, &hdev->flags))
hdev->page_scan_type = rp->type; hdev->page_scan_type = rp->type;
} }
...@@ -825,7 +838,9 @@ static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, ...@@ -825,7 +838,9 @@ static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (!rp->status) if (rp->status)
return;
hdev->inq_tx_power = rp->tx_power; hdev->inq_tx_power = rp->tx_power;
} }
...@@ -897,7 +912,9 @@ static void hci_cc_le_read_local_features(struct hci_dev *hdev, ...@@ -897,7 +912,9 @@ static void hci_cc_le_read_local_features(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (!rp->status) if (rp->status)
return;
memcpy(hdev->le_features, rp->features, 8); memcpy(hdev->le_features, rp->features, 8);
} }
...@@ -908,7 +925,9 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, ...@@ -908,7 +925,9 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (!rp->status) if (rp->status)
return;
hdev->adv_tx_power = rp->tx_power; hdev->adv_tx_power = rp->tx_power;
} }
...@@ -1009,13 +1028,15 @@ static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1009,13 +1028,15 @@ static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb)
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR); sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR);
if (!sent) if (!sent)
return; return;
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (!status)
bacpy(&hdev->random_addr, sent); bacpy(&hdev->random_addr, sent);
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
...@@ -1027,11 +1048,11 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1027,11 +1048,11 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE); if (status)
if (!sent)
return; return;
if (status) sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
if (!sent)
return; return;
hci_dev_lock(hdev); hci_dev_lock(hdev);
...@@ -1061,13 +1082,15 @@ static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1061,13 +1082,15 @@ static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM); cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM);
if (!cp) if (!cp)
return; return;
hci_dev_lock(hdev); hci_dev_lock(hdev);
if (!status)
hdev->le_scan_type = cp->type; hdev->le_scan_type = cp->type;
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
...@@ -1110,11 +1133,11 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, ...@@ -1110,11 +1133,11 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); if (status)
if (!cp)
return; return;
if (status) cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
if (!cp)
return; return;
switch (cp->enable) { switch (cp->enable) {
...@@ -1167,7 +1190,9 @@ static void hci_cc_le_read_white_list_size(struct hci_dev *hdev, ...@@ -1167,7 +1190,9 @@ static void hci_cc_le_read_white_list_size(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size); BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
if (!rp->status) if (rp->status)
return;
hdev->le_white_list_size = rp->size; hdev->le_white_list_size = rp->size;
} }
...@@ -1178,7 +1203,9 @@ static void hci_cc_le_clear_white_list(struct hci_dev *hdev, ...@@ -1178,7 +1203,9 @@ static void hci_cc_le_clear_white_list(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (!status) if (status)
return;
hci_white_list_clear(hdev); hci_white_list_clear(hdev);
} }
...@@ -1190,11 +1217,13 @@ static void hci_cc_le_add_to_white_list(struct hci_dev *hdev, ...@@ -1190,11 +1217,13 @@ static void hci_cc_le_add_to_white_list(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_WHITE_LIST); sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_WHITE_LIST);
if (!sent) if (!sent)
return; return;
if (!status)
hci_white_list_add(hdev, &sent->bdaddr, sent->bdaddr_type); hci_white_list_add(hdev, &sent->bdaddr, sent->bdaddr_type);
} }
...@@ -1206,11 +1235,13 @@ static void hci_cc_le_del_from_white_list(struct hci_dev *hdev, ...@@ -1206,11 +1235,13 @@ static void hci_cc_le_del_from_white_list(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_WHITE_LIST); sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_WHITE_LIST);
if (!sent) if (!sent)
return; return;
if (!status)
hci_white_list_del(hdev, &sent->bdaddr, sent->bdaddr_type); hci_white_list_del(hdev, &sent->bdaddr, sent->bdaddr_type);
} }
...@@ -1221,7 +1252,9 @@ static void hci_cc_le_read_supported_states(struct hci_dev *hdev, ...@@ -1221,7 +1252,9 @@ static void hci_cc_le_read_supported_states(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
if (!rp->status) if (rp->status)
return;
memcpy(hdev->le_states, rp->le_states, 8); memcpy(hdev->le_states, rp->le_states, 8);
} }
...@@ -1233,11 +1266,13 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev, ...@@ -1233,11 +1266,13 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
BT_DBG("%s status 0x%2.2x", hdev->name, status); BT_DBG("%s status 0x%2.2x", hdev->name, status);
if (status)
return;
sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
if (!sent) if (!sent)
return; return;
if (!status) {
if (sent->le) { if (sent->le) {
hdev->features[1][0] |= LMP_HOST_LE; hdev->features[1][0] |= LMP_HOST_LE;
set_bit(HCI_LE_ENABLED, &hdev->dev_flags); set_bit(HCI_LE_ENABLED, &hdev->dev_flags);
...@@ -1251,7 +1286,6 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev, ...@@ -1251,7 +1286,6 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
hdev->features[1][0] |= LMP_HOST_LE_BREDR; hdev->features[1][0] |= LMP_HOST_LE_BREDR;
else else
hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
}
} }
static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment