| @@ -6094,23 +6094,18 @@ unlock: · 6093 unmodified lines |
| 6094 | return err; | 6094 | return err; |
| 6095 | } | 6095 | } |
| 6096 | | 6096 | |
| 6097 | static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) | 6097 | static 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 | |
| 6136 | remove: | 6131 | done: |
| 6137 | mgmt_pending_remove(cmd); | 6132 | mgmt_pending_free(cmd); |
| 6138 | unlock: | 6133 | } |
| 6139 | hci_dev_unlock(hdev); | 6134 | |
| | 6135 | static 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 | |
| 6142 | static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, | 6147 | static 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 | |
| 6225 | failed: | 6223 | failed: |