History

Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN

Synchronous version of MGMT_OP_SET_SECURE_CONN.

Brian Gix committed 5 years ago

Commit 2f2eb0c1 parent 47db6b43 files · +49 −36Browse files

Unified · Split

3 files
  1. include/net/bluetooth/hci_sync.h +1 −0
  2. net/bluetooth/hci_sync.c +16 −2
  3. net/bluetooth/mgmt.c +32 −34
include/net/bluetooth/hci_sync.h+1−0
@@ -69,6 +69,7 @@ int hci_update_passive_scan_sync(struct hci_dev *hdev); · 68 unmodified lines
69int hci_update_passive_scan(struct hci_dev *hdev);69int hci_update_passive_scan(struct hci_dev *hdev);
70int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle);70int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle);
71int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type);71int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type);
72int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val);
72 73
73int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);74int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
74int hci_update_scan_sync(struct hci_dev *hdev);75int hci_update_scan_sync(struct hci_dev *hdev);
net/bluetooth/hci_sync.c+16−2
@@ -2104,13 +2104,27 @@ int hci_update_passive_scan(struct hci_dev *hdev) · 2103 unmodified lines
2104 return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL);2104 return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL);
2105}2105}
2106 2106
2107static int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)2107int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)
2108{2108{
2109 int err;
2110
2109 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev))2111 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev))
2110 return 0;2112 return 0;
2111 2113
2112 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT,2114 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT,
2113 sizeof(val), &val, HCI_CMD_TIMEOUT);2115 sizeof(val), &val, HCI_CMD_TIMEOUT);
2116
2117 if (!err) {
2118 if (val) {
2119 hdev->features[1][0] |= LMP_HOST_SC;
2120 hci_dev_set_flag(hdev, HCI_SC_ENABLED);
2121 } else {
2122 hdev->features[1][0] &= ~LMP_HOST_SC;
2123 hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
2124 }
2125 }
2126
2127 return err;
2114}2128}
2115 2129
2116static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)2130static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)
net/bluetooth/mgmt.c+32−34
@@ -6094,23 +6094,18 @@ unlock: · 6093 unmodified lines
6094 return err;6094 return err;
6095}6095}
6096 6096
6097static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)6097static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err)
6098{6098{
6099 struct mgmt_pending_cmd *cmd;6099 struct mgmt_pending_cmd *cmd = data;
6100 struct mgmt_mode *cp;6100 struct mgmt_mode *cp;
6101 6101
6102 bt_dev_dbg(hdev, "status %u", status);6102 bt_dev_dbg(hdev, "err %d", err);
6103
6104 hci_dev_lock(hdev);
6105 6103
6106 cmd = pending_find(MGMT_OP_SET_SECURE_CONN, hdev);6104 if (err) {
6107 if (!cmd)6105 u8 mgmt_err = mgmt_status(err);
6108 goto unlock;
6109 6106
6110 if (status) {6107 mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode, mgmt_err);
6111 mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode,6108 goto done;
6112 mgmt_status(status));
6113 goto remove;
6114 }6109 }
6115 6110
6116 cp = cmd->param;6111 cp = cmd->param;
@@ -6130,13 +6125,23 @@ static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) · 13 unmodified lines
6130 break;6125 break;
6131 }6126 }
6132 6127
6133 send_settings_rsp(cmd->sk, MGMT_OP_SET_SECURE_CONN, hdev);6128 send_settings_rsp(cmd->sk, cmd->opcode, hdev);
6134 new_settings(hdev, cmd->sk);6129 new_settings(hdev, cmd->sk);
6135 6130
6136remove:6131done:
6137 mgmt_pending_remove(cmd);6132 mgmt_pending_free(cmd);
6138unlock:6133}
6139 hci_dev_unlock(hdev);6134
6135static int set_secure_conn_sync(struct hci_dev *hdev, void *data)
6136{
6137 struct mgmt_pending_cmd *cmd = data;
6138 struct mgmt_mode *cp = cmd->param;
6139 u8 val = !!cp->val;
6140
6141 /* Force write of val */
6142 hci_dev_set_flag(hdev, HCI_SC_ENABLED);
6143
6144 return hci_write_sc_support_sync(hdev, val);
6140}6145}
6141 6146
6142static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,6147static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
@@ -6144,7 +6149,6 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, · 1 unmodified line
6144{6149{
6145 struct mgmt_mode *cp = data;6150 struct mgmt_mode *cp = data;
6146 struct mgmt_pending_cmd *cmd;6151 struct mgmt_pending_cmd *cmd;
6147 struct hci_request req;
6148 u8 val;6152 u8 val;
6149 int err;6153 int err;
6150 6154
@@ -6163,7 +6167,7 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, · 12 unmodified lines
6163 6167
6164 if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)6168 if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)
6165 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,6169 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6166 MGMT_STATUS_INVALID_PARAMS);6170 MGMT_STATUS_INVALID_PARAMS);
6167 6171
6168 hci_dev_lock(hdev);6172 hci_dev_lock(hdev);
6169 6173
@@ -6194,12 +6198,6 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, · 24 unmodified lines
6194 goto failed;6198 goto failed;
6195 }6199 }
6196 6200
6197 if (pending_find(MGMT_OP_SET_SECURE_CONN, hdev)) {
6198 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6199 MGMT_STATUS_BUSY);
6200 goto failed;
6201 }
6202
6203 val = !!cp->val;6201 val = !!cp->val;
6204 6202
6205 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&6203 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
@@ -6208,18 +6206,18 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, · 2 unmodified lines
6208 goto failed;6206 goto failed;
6209 }6207 }
6210 6208
6211 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len);6209 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len);
6212 if (!cmd) {6210 if (!cmd)
6213 err = -ENOMEM;6211 err = -ENOMEM;
6214 goto failed;6212 else
6215 }6213 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd,
6214 set_secure_conn_complete);
6216 6215
6217 hci_req_init(&req, hdev);
6218 hci_req_add(&req, HCI_OP_WRITE_SC_SUPPORT, 1, &val);
6219 err = hci_req_run(&req, sc_enable_complete);
6220 if (err < 0) {6216 if (err < 0) {
6221 mgmt_pending_remove(cmd);6217 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6222 goto failed;6218 MGMT_STATUS_FAILED);
6219 if (cmd)
6220 mgmt_pending_free(cmd);
6223 }6221 }
6224 6222
6225failed:6223failed:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t