提交 d81a494c 编写于 作者: B Brian Gix 提交者: Marcel Holtmann

Bluetooth: hci_sync: Convert MGMT_OP_SET_LE

Uses:
  hci_disable_advertising_sync
  hci_remove_ext_adv_instance_sync
  hci_write_le_host_supported_sync
  hci_setup_ext_adv_instance_sync
  hci_update_scan_rsp_data_sync
Signed-off-by: NBrian Gix <brian.gix@intel.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 5a750137
...@@ -75,6 +75,10 @@ int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp); ...@@ -75,6 +75,10 @@ int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp);
int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable); int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
int hci_update_scan_sync(struct hci_dev *hdev); int hci_update_scan_sync(struct hci_dev *hdev);
int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul);
int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
struct sock *sk);
int hci_dev_open_sync(struct hci_dev *hdev); int hci_dev_open_sync(struct hci_dev *hdev);
int hci_dev_close_sync(struct hci_dev *hdev); int hci_dev_close_sync(struct hci_dev *hdev);
......
...@@ -2149,8 +2149,7 @@ static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) ...@@ -2149,8 +2149,7 @@ static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)
return hci_write_sc_support_sync(hdev, 0x01); return hci_write_sc_support_sync(hdev, 0x01);
} }
static int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul)
u8 simul)
{ {
struct hci_cp_write_le_host_supported cp; struct hci_cp_write_le_host_supported cp;
......
...@@ -1902,18 +1902,17 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) ...@@ -1902,18 +1902,17 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
return err; return err;
} }
static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) static void set_le_complete(struct hci_dev *hdev, void *data, int err)
{ {
struct cmd_lookup match = { NULL, hdev }; struct cmd_lookup match = { NULL, hdev };
u8 status = mgmt_status(err);
hci_dev_lock(hdev); bt_dev_dbg(hdev, "err %d", err);
if (status) { if (status) {
u8 mgmt_err = mgmt_status(status);
mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp,
&mgmt_err); &status);
goto unlock; return;
} }
mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match);
...@@ -1922,39 +1921,54 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) ...@@ -1922,39 +1921,54 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
if (match.sk) if (match.sk)
sock_put(match.sk); sock_put(match.sk);
}
static int set_le_sync(struct hci_dev *hdev, void *data)
{
struct mgmt_pending_cmd *cmd = data;
struct mgmt_mode *cp = cmd->param;
u8 val = !!cp->val;
int err;
if (!val) {
if (hci_dev_test_flag(hdev, HCI_LE_ADV))
hci_disable_advertising_sync(hdev);
if (ext_adv_capable(hdev))
hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk);
} else {
hci_dev_set_flag(hdev, HCI_LE_ENABLED);
}
err = hci_write_le_host_supported_sync(hdev, val, 0);
/* Make sure the controller has a good default for /* Make sure the controller has a good default for
* advertising data. Restrict the update to when LE * advertising data. Restrict the update to when LE
* has actually been enabled. During power on, the * has actually been enabled. During power on, the
* update in powered_update_hci will take care of it. * update in powered_update_hci will take care of it.
*/ */
if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
struct hci_request req;
hci_req_init(&req, hdev);
if (ext_adv_capable(hdev)) { if (ext_adv_capable(hdev)) {
int err; int status;
err = __hci_req_setup_ext_adv_instance(&req, 0x00); status = hci_setup_ext_adv_instance_sync(hdev, 0x00);
if (!err) if (!status)
__hci_req_update_scan_rsp_data(&req, 0x00); hci_update_scan_rsp_data_sync(hdev, 0x00);
} else { } else {
__hci_req_update_adv_data(&req, 0x00); hci_update_adv_data_sync(hdev, 0x00);
__hci_req_update_scan_rsp_data(&req, 0x00); hci_update_scan_rsp_data_sync(hdev, 0x00);
} }
hci_req_run(&req, NULL);
hci_update_passive_scan(hdev); hci_update_passive_scan(hdev);
} }
unlock: return err;
hci_dev_unlock(hdev);
} }
static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
{ {
struct mgmt_mode *cp = data; struct mgmt_mode *cp = data;
struct hci_cp_write_le_host_supported hci_cp;
struct mgmt_pending_cmd *cmd; struct mgmt_pending_cmd *cmd;
struct hci_request req;
int err; int err;
u8 val, enabled; u8 val, enabled;
...@@ -2024,33 +2038,20 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) ...@@ -2024,33 +2038,20 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
} }
cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len);
if (!cmd) { if (!cmd)
err = -ENOMEM; err = -ENOMEM;
goto unlock; else
} err = hci_cmd_sync_queue(hdev, set_le_sync, cmd,
set_le_complete);
hci_req_init(&req, hdev);
memset(&hci_cp, 0, sizeof(hci_cp));
if (val) { if (err < 0) {
hci_cp.le = val; err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
hci_cp.simul = 0x00; MGMT_STATUS_FAILED);
} else {
if (hci_dev_test_flag(hdev, HCI_LE_ADV))
__hci_req_disable_advertising(&req);
if (ext_adv_capable(hdev)) if (cmd)
__hci_req_clear_ext_adv_sets(&req); mgmt_pending_remove(cmd);
} }
hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
&hci_cp);
err = hci_req_run(&req, le_enable_complete);
if (err < 0)
mgmt_pending_remove(cmd);
unlock: unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
return err; return err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册