提交 4ebeee2d 编写于 作者: J Johan Hedberg 提交者: Marcel Holtmann

Bluetooth: Add HCI status return parameter to hci_req_sync()

In some cases it may be important to get the exact HCI status rather
than the converted HCI-to-errno value. Add an optional return
parameter to the hci_req_sync() API to allow for this. Since there are
no good HCI translation candidates for cancelation and timeout, use
the "unknown" status code for those cases.
Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 51d7a94d
...@@ -452,7 +452,8 @@ enum { ...@@ -452,7 +452,8 @@ enum {
#define HCI_ERROR_REMOTE_POWER_OFF 0x15 #define HCI_ERROR_REMOTE_POWER_OFF 0x15
#define HCI_ERROR_LOCAL_HOST_TERM 0x16 #define HCI_ERROR_LOCAL_HOST_TERM 0x16
#define HCI_ERROR_PAIRING_NOT_ALLOWED 0x18 #define HCI_ERROR_PAIRING_NOT_ALLOWED 0x18
#define HCI_ERROR_INVALID_LL_PARAMS 0x1E #define HCI_ERROR_INVALID_LL_PARAMS 0x1e
#define HCI_ERROR_UNSPECIFIED 0x1f
#define HCI_ERROR_ADVERTISING_TIMEOUT 0x3c #define HCI_ERROR_ADVERTISING_TIMEOUT 0x3c
/* Flow control modes */ /* Flow control modes */
......
...@@ -768,14 +768,14 @@ static int __hci_init(struct hci_dev *hdev) ...@@ -768,14 +768,14 @@ static int __hci_init(struct hci_dev *hdev)
{ {
int err; int err;
err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT); err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT, NULL);
if (err < 0) if (err < 0)
return err; return err;
if (hci_dev_test_flag(hdev, HCI_SETUP)) if (hci_dev_test_flag(hdev, HCI_SETUP))
hci_debugfs_create_basic(hdev); hci_debugfs_create_basic(hdev);
err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT); err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT, NULL);
if (err < 0) if (err < 0)
return err; return err;
...@@ -786,11 +786,11 @@ static int __hci_init(struct hci_dev *hdev) ...@@ -786,11 +786,11 @@ static int __hci_init(struct hci_dev *hdev)
if (hdev->dev_type != HCI_BREDR) if (hdev->dev_type != HCI_BREDR)
return 0; return 0;
err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT); err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT, NULL);
if (err < 0) if (err < 0)
return err; return err;
err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT); err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT, NULL);
if (err < 0) if (err < 0)
return err; return err;
...@@ -846,7 +846,7 @@ static int __hci_unconf_init(struct hci_dev *hdev) ...@@ -846,7 +846,7 @@ static int __hci_unconf_init(struct hci_dev *hdev)
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
return 0; return 0;
err = __hci_req_sync(hdev, hci_init0_req, 0, HCI_INIT_TIMEOUT); err = __hci_req_sync(hdev, hci_init0_req, 0, HCI_INIT_TIMEOUT, NULL);
if (err < 0) if (err < 0)
return err; return err;
...@@ -1204,7 +1204,7 @@ int hci_inquiry(void __user *arg) ...@@ -1204,7 +1204,7 @@ int hci_inquiry(void __user *arg)
if (do_inquiry) { if (do_inquiry) {
err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir,
timeo); timeo, NULL);
if (err < 0) if (err < 0)
goto done; goto done;
...@@ -1570,7 +1570,7 @@ int hci_dev_do_close(struct hci_dev *hdev) ...@@ -1570,7 +1570,7 @@ int hci_dev_do_close(struct hci_dev *hdev)
if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) &&
!auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
set_bit(HCI_INIT, &hdev->flags); set_bit(HCI_INIT, &hdev->flags);
__hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT); __hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT, NULL);
clear_bit(HCI_INIT, &hdev->flags); clear_bit(HCI_INIT, &hdev->flags);
} }
...@@ -1667,7 +1667,7 @@ static int hci_dev_do_reset(struct hci_dev *hdev) ...@@ -1667,7 +1667,7 @@ static int hci_dev_do_reset(struct hci_dev *hdev)
atomic_set(&hdev->cmd_cnt, 1); atomic_set(&hdev->cmd_cnt, 1);
hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0; hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0;
ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT); ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT, NULL);
hci_req_sync_unlock(hdev); hci_req_sync_unlock(hdev);
return ret; return ret;
...@@ -1802,7 +1802,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg) ...@@ -1802,7 +1802,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
switch (cmd) { switch (cmd) {
case HCISETAUTH: case HCISETAUTH:
err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
HCI_INIT_TIMEOUT); HCI_INIT_TIMEOUT, NULL);
break; break;
case HCISETENCRYPT: case HCISETENCRYPT:
...@@ -1814,18 +1814,18 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg) ...@@ -1814,18 +1814,18 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
if (!test_bit(HCI_AUTH, &hdev->flags)) { if (!test_bit(HCI_AUTH, &hdev->flags)) {
/* Auth must be enabled first */ /* Auth must be enabled first */
err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
HCI_INIT_TIMEOUT); HCI_INIT_TIMEOUT, NULL);
if (err) if (err)
break; break;
} }
err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt,
HCI_INIT_TIMEOUT); HCI_INIT_TIMEOUT, NULL);
break; break;
case HCISETSCAN: case HCISETSCAN:
err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt,
HCI_INIT_TIMEOUT); HCI_INIT_TIMEOUT, NULL);
/* Ensure that the connectable and discoverable states /* Ensure that the connectable and discoverable states
* get correctly modified as this was a non-mgmt change. * get correctly modified as this was a non-mgmt change.
...@@ -1836,7 +1836,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg) ...@@ -1836,7 +1836,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
case HCISETLINKPOL: case HCISETLINKPOL:
err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt,
HCI_INIT_TIMEOUT); HCI_INIT_TIMEOUT, NULL);
break; break;
case HCISETLINKMODE: case HCISETLINKMODE:
......
...@@ -186,7 +186,7 @@ EXPORT_SYMBOL(__hci_cmd_sync); ...@@ -186,7 +186,7 @@ EXPORT_SYMBOL(__hci_cmd_sync);
/* Execute request and wait for completion. */ /* Execute request and wait for completion. */
int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req, int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req,
unsigned long opt), unsigned long opt),
unsigned long opt, __u32 timeout) unsigned long opt, u32 timeout, u8 *hci_status)
{ {
struct hci_request req; struct hci_request req;
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
...@@ -231,14 +231,20 @@ int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req, ...@@ -231,14 +231,20 @@ int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req,
switch (hdev->req_status) { switch (hdev->req_status) {
case HCI_REQ_DONE: case HCI_REQ_DONE:
err = -bt_to_errno(hdev->req_result); err = -bt_to_errno(hdev->req_result);
if (hci_status)
*hci_status = hdev->req_result;
break; break;
case HCI_REQ_CANCELED: case HCI_REQ_CANCELED:
err = -hdev->req_result; err = -hdev->req_result;
if (hci_status)
*hci_status = HCI_ERROR_UNSPECIFIED;
break; break;
default: default:
err = -ETIMEDOUT; err = -ETIMEDOUT;
if (hci_status)
*hci_status = HCI_ERROR_UNSPECIFIED;
break; break;
} }
...@@ -251,7 +257,7 @@ int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req, ...@@ -251,7 +257,7 @@ int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req,
int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req, int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req,
unsigned long opt), unsigned long opt),
unsigned long opt, __u32 timeout) unsigned long opt, u32 timeout, u8 *hci_status)
{ {
int ret; int ret;
...@@ -260,7 +266,7 @@ int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req, ...@@ -260,7 +266,7 @@ int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req,
/* Serialize all requests */ /* Serialize all requests */
hci_req_sync_lock(hdev); hci_req_sync_lock(hdev);
ret = __hci_req_sync(hdev, req, opt, timeout); ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
hci_req_sync_unlock(hdev); hci_req_sync_unlock(hdev);
return ret; return ret;
......
...@@ -46,10 +46,10 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, ...@@ -46,10 +46,10 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req, int hci_req_sync(struct hci_dev *hdev, void (*req)(struct hci_request *req,
unsigned long opt), unsigned long opt),
unsigned long opt, __u32 timeout); unsigned long opt, u32 timeout, u8 *hci_status);
int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req, int __hci_req_sync(struct hci_dev *hdev, void (*func)(struct hci_request *req,
unsigned long opt), unsigned long opt),
unsigned long opt, __u32 timeout); unsigned long opt, u32 timeout, u8 *hci_status);
void hci_req_sync_cancel(struct hci_dev *hdev, int err); void hci_req_sync_cancel(struct hci_dev *hdev, int err);
struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册