Skip to contentSkip to conversation

Bluetooth: hci_core: return cmd status in __hci_cmd_sync()

PATCH Superseded Frederic Danis 1 participant 1 message Apr 30, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: hci_core: return cmd status in __hci_cmd_sync()

Handle command complete event and extract error/status.

---
 drivers/bluetooth/btbcm.c        |  27 +++++-----
 drivers/bluetooth/btintel.c      |  14 +++---
 drivers/bluetooth/btmrvl_main.c  |   2 +-
 drivers/bluetooth/btusb.c        | 104 +++++++++++++++++++++------------------
 drivers/bluetooth/hci_ath.c      |   3 +-
 drivers/bluetooth/hci_ldisc.c    |   2 +-
 include/net/bluetooth/hci_core.h |   2 +-
 net/bluetooth/hci_core.c         |  17 +++++--
 8 files changed, 95 insertions(+), 76 deletions(-)
drivers/bluetooth/btbcm.c +15 -12
index 4bba866..5635d6d 100644
@@ -38,9 +38,10 @@ int btbcm_check_bdaddr(struct hci_dev *hdev)
 {
 	struct hci_rp_read_bd_addr *bda;
 	struct sk_buff *skb;
+	u8 status;
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
-			     HCI_INIT_TIMEOUT);
+			     HCI_INIT_TIMEOUT, &status);
 	if (IS_ERR(skb)) {
 		int err = PTR_ERR(skb);
 		BT_ERR("%s: BCM: Reading device address failed (%d)",
@@ -54,14 +55,15 @@ int btbcm_check_bdaddr(struct hci_dev *hdev)
 		return -EIO;
 	}
 
-	bda = (struct hci_rp_read_bd_addr *)skb->data;
-	if (bda->status) {
+	if (status) {
 		BT_ERR("%s: BCM: Device address result failed (%02x)",
-		       hdev->name, bda->status);
+		       hdev->name, status);
 		kfree_skb(skb);
-		return -bt_to_errno(bda->status);
+		return -bt_to_errno(status);
 	}
 
+	bda = (struct hci_rp_read_bd_addr *)skb->data;
+
 	/* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
 	 * with no configured address.
 	 */
@@ -82,7 +84,7 @@ int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	struct sk_buff *skb;
 	int err;
 
-	skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		BT_ERR("%s: BCM: Change address command failed (%d)",
@@ -112,7 +114,7 @@ int btbcm_patchram(struct hci_dev *hdev, const char *firmware)
 	}
 
 	/* Start Download */
-	skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		BT_ERR("%s: BCM: Download Minidrv command failed (%d)",
@@ -148,7 +150,7 @@ int btbcm_patchram(struct hci_dev *hdev, const char *firmware)
 		opcode = le16_to_cpu(cmd->opcode);
 
 		skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
-				     HCI_INIT_TIMEOUT);
+				     HCI_INIT_TIMEOUT, NULL);
 		if (IS_ERR(skb)) {
 			err = PTR_ERR(skb);
 			BT_ERR("%s: BCM: Patch command %04x failed (%d)",
@@ -171,7 +173,8 @@ static int btbcm_reset(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
 
-	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT,
+			     NULL);
 	if (IS_ERR(skb)) {
 		int err = PTR_ERR(skb);
 		BT_ERR("%s: BCM: Reset failed (%d)", hdev->name, err);
@@ -187,7 +190,7 @@ static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
 	struct sk_buff *skb;
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
-			     HCI_INIT_TIMEOUT);
+			     HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		BT_ERR("%s: BCM: Reading local version info failed (%ld)",
 		       hdev->name, PTR_ERR(skb));
@@ -207,7 +210,7 @@ static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
 
-	skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		BT_ERR("%s: BCM: Read verbose config info failed (%ld)",
 		       hdev->name, PTR_ERR(skb));
@@ -227,7 +230,7 @@ static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
 
-	skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		BT_ERR("%s: BCM: Read USB product info failed (%ld)",
 		       hdev->name, PTR_ERR(skb));
drivers/bluetooth/btintel.c +8 -6
index 2d43d42..1a17dd3 100644
@@ -36,9 +36,10 @@ int btintel_check_bdaddr(struct hci_dev *hdev)
 {
 	struct hci_rp_read_bd_addr *bda;
 	struct sk_buff *skb;
+	u8 status;
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
-			     HCI_INIT_TIMEOUT);
+			     HCI_INIT_TIMEOUT, &status);
 	if (IS_ERR(skb)) {
 		int err = PTR_ERR(skb);
 		BT_ERR("%s: Reading Intel device address failed (%d)",
@@ -52,14 +53,15 @@ int btintel_check_bdaddr(struct hci_dev *hdev)
 		return -EIO;
 	}
 
-	bda = (struct hci_rp_read_bd_addr *)skb->data;
-	if (bda->status) {
+	if (status) {
 		BT_ERR("%s: Intel device address result failed (%02x)",
-		       hdev->name, bda->status);
+		       hdev->name, status);
 		kfree_skb(skb);
-		return -bt_to_errno(bda->status);
+		return -bt_to_errno(status);
 	}
 
+	bda = (struct hci_rp_read_bd_addr *)skb->data;
+
 	/* For some Intel based controllers, the default Bluetooth device
 	 * address 00:03:19:9E:8B:00 can be found. These controllers are
 	 * fully operational, but have the danger of duplicate addresses
@@ -82,7 +84,7 @@ int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	struct sk_buff *skb;
 	int err;
 
-	skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		BT_ERR("%s: Changing Intel device address failed (%d)",
drivers/bluetooth/btmrvl_main.c +1 -1
index de05deb..f9005f3 100644
@@ -593,7 +593,7 @@ static int btmrvl_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	memcpy(buf + 2, bdaddr, sizeof(bdaddr_t));
 
 	skb = __hci_cmd_sync(hdev, BT_CMD_SET_BDADDR, sizeof(buf), buf,
-			     HCI_INIT_TIMEOUT);
+			     HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		ret = PTR_ERR(skb);
 		BT_ERR("%s: changing btmrvl device address failed (%ld)",
drivers/bluetooth/btusb.c +55 -49

313 lines not on this page · raw message

drivers/bluetooth/hci_ath.c +2 -1
index ec8fa0e..19a8f92 100644
@@ -156,7 +156,8 @@ static int ath_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 	buf[3] = sizeof(bdaddr_t);
 	memcpy(buf + 4, bdaddr, sizeof(bdaddr_t));
 
-	skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT);
+	skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT,
+			     NULL);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
 		BT_ERR("%s: Change address command failed (%d)",
drivers/bluetooth/hci_ldisc.c +1 -1
index 5c9a73f..2b5d946 100644
@@ -278,7 +278,7 @@ static int hci_uart_setup(struct hci_dev *hdev)
 		return 0;
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
-			     HCI_INIT_TIMEOUT);
+			     HCI_INIT_TIMEOUT, NULL);
 	if (IS_ERR(skb)) {
 		BT_ERR("%s: Reading local version information failed (%ld)",
 		       hdev->name, PTR_ERR(skb));
include/net/bluetooth/hci_core.h +1 -1
index a056c2b..ea02e00 100644
@@ -1282,7 +1282,7 @@ int hci_register_cb(struct hci_cb *hcb);
 int hci_unregister_cb(struct hci_cb *hcb);
 
 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
-			       const void *param, u32 timeout);
+			       const void *param, u32 timeout, u8 *status);
 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
 				  const void *param, u8 event, u32 timeout);
 
net/bluetooth/hci_core.c +12 -5
index 476709b..45f5061 100644
@@ -94,6 +94,7 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
 	char buf[32];
 	size_t buf_size = min(count, (sizeof(buf)-1));
 	bool enable;
+	u8 status;
 	int err;
 
 	if (!test_bit(HCI_UP, &hdev->flags))
@@ -112,16 +113,16 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
 	hci_req_lock(hdev);
 	if (enable)
 		skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL,
-				     HCI_CMD_TIMEOUT);
+				     HCI_CMD_TIMEOUT, &status);
 	else
 		skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
-				     HCI_CMD_TIMEOUT);
+				     HCI_CMD_TIMEOUT, &status);
 	hci_req_unlock(hdev);
 
 	if (IS_ERR(skb))
 		return PTR_ERR(skb);
 
-	err = -bt_to_errno(skb->data[0]);
+	err = -bt_to_errno(status);
 	kfree_skb(skb);
 
 	if (err < 0)
@@ -232,9 +233,15 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
 EXPORT_SYMBOL(__hci_cmd_sync_ev);
 
 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
-			       const void *param, u32 timeout)
+			       const void *param, u32 timeout, u8 *status)
 {
-	return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
+	struct sk_buff *skb;
+
+	skb = __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
+	if (!IS_ERR(skb) && status)
+		*status = skb->data[0];
+
+	return skb;
 }
 EXPORT_SYMBOL(__hci_cmd_sync);
 
Signature · 1 line
1.9.1