History

Bluetooth: hci_sync: Convert MGMT_OP_SSP

mgmt-tester paths: Set SSP on - Success 2 Set Device ID - SSP off and Power on

Brian Gix committed 5 years ago

Commit 32448451 parent 5e233ed5 files · +80 −83Browse files

Unified · Split

5 files
  1. include/net/bluetooth/hci_core.h +0 −1
  2. include/net/bluetooth/hci_sync.h +1 −0
  3. net/bluetooth/hci_event.c +1 −3
  4. net/bluetooth/hci_sync.c +6 −1
  5. net/bluetooth/mgmt.c +72 −78
include/net/bluetooth/hci_core.h+0−1
@@ -1806,7 +1806,6 @@ int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, · 1805 unmodified lines
18061806 u8 entered);
18071807 void mgmt_auth_failed(struct hci_conn *conn, u8 status);
18081808 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
1809−void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
18101809 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
18111810 u8 status);
18121811 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
include/net/bluetooth/hci_sync.h+1−0
@@ -47,6 +47,7 @@ int hci_update_class_sync(struct hci_dev *hdev); · 46 unmodified lines
4747 int hci_update_eir_sync(struct hci_dev *hdev);
4848 int hci_update_class_sync(struct hci_dev *hdev);
4949 int hci_update_name_sync(struct hci_dev *hdev);
50+int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode);
5051
5152 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
5253 bool rpa, u8 *own_addr_type);
net/bluetooth/hci_event.c+1−3
@@ -545,9 +545,7 @@ static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) · 544 unmodified lines
545545 hdev->features[1][0] &= ~LMP_HOST_SSP;
546546 }
547547
548− if (hci_dev_test_flag(hdev, HCI_MGMT))
549− mgmt_ssp_enable_complete(hdev, sent->mode, status);
550− else if (!status) {
548+ if (!status) {
551549 if (sent->mode)
552550 hci_dev_set_flag(hdev, HCI_SSP_ENABLED);
553551 else
net/bluetooth/hci_sync.c+6−1
@@ -2142,7 +2142,7 @@ int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) · 2141 unmodified lines
21422142 return err;
21432143 }
21442144
2145−static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)
2145+int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)
21462146 {
21472147 int err;
21482148
@@ -2150,6 +2150,11 @@ static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) · 1 unmodified line
21502150 lmp_host_ssp_capable(hdev))
21512151 return 0;
21522152
2153+ if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
2154+ __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE,
2155+ sizeof(mode), &mode, HCI_CMD_TIMEOUT);
2156+ }
2157+
21532158 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE,
21542159 sizeof(mode), &mode, HCI_CMD_TIMEOUT);
21552160 if (err)
net/bluetooth/mgmt.c+72−78
@@ -1760,6 +1760,69 @@ failed: · 1759 unmodified lines
17601760 return err;
17611761 }
17621762
1763+static void set_ssp_complete(struct hci_dev *hdev, void *data, int err)
1764+{
1765+ struct cmd_lookup match = { NULL, hdev };
1766+ struct mgmt_pending_cmd *cmd = data;
1767+ struct mgmt_mode *cp = cmd->param;
1768+ u8 enable = cp->val;
1769+ bool changed;
1770+
1771+ if (err) {
1772+ u8 mgmt_err = mgmt_status(err);
1773+
1774+ if (enable && hci_dev_test_and_clear_flag(hdev,
1775+ HCI_SSP_ENABLED)) {
1776+ hci_dev_clear_flag(hdev, HCI_HS_ENABLED);
1777+ new_settings(hdev, NULL);
1778+ }
1779+
1780+ mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp,
1781+ &mgmt_err);
1782+ return;
1783+ }
1784+
1785+ if (enable) {
1786+ changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED);
1787+ } else {
1788+ changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED);
1789+
1790+ if (!changed)
1791+ changed = hci_dev_test_and_clear_flag(hdev,
1792+ HCI_HS_ENABLED);
1793+ else
1794+ hci_dev_clear_flag(hdev, HCI_HS_ENABLED);
1795+ }
1796+
1797+ mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match);
1798+
1799+ if (changed)
1800+ new_settings(hdev, match.sk);
1801+
1802+ if (match.sk)
1803+ sock_put(match.sk);
1804+
1805+ hci_update_eir_sync(hdev);
1806+}
1807+
1808+static int set_ssp_sync(struct hci_dev *hdev, void *data)
1809+{
1810+ struct mgmt_pending_cmd *cmd = data;
1811+ struct mgmt_mode *cp = cmd->param;
1812+ bool changed = false;
1813+ int err;
1814+
1815+ if (cp->val)
1816+ changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED);
1817+
1818+ err = hci_write_ssp_mode_sync(hdev, cp->val);
1819+
1820+ if (!err && changed)
1821+ hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
1822+
1823+ return err;
1824+}
1825+
17631826 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
17641827 {
17651828 struct mgmt_mode *cp = data;
@@ -1821,19 +1884,18 @@ static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) · 55 unmodified lines
18211884 }
18221885
18231886 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len);
1824− if (!cmd) {
1887+ if (!cmd)
18251888 err = -ENOMEM;
1826− goto failed;
1827− }
1828−
1829− if (!cp->val && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS))
1830− hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE,
1831− sizeof(cp->val), &cp->val);
1889+ else
1890+ err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd,
1891+ set_ssp_complete);
18321892
1833− err = hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &cp->val);
18341893 if (err < 0) {
1835− mgmt_pending_remove(cmd);
1836− goto failed;
1894+ err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP,
1895+ MGMT_STATUS_FAILED);
1896+
1897+ if (cmd)
1898+ mgmt_pending_remove(cmd);
18371899 }
18381900
18391901 failed:
@@ -9309,74 +9371,6 @@ void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) · 7469 unmodified lines
93099371 sock_put(match.sk);
93109372 }
93119373
9312−static void clear_eir(struct hci_request *req)
9313−{
9314− struct hci_dev *hdev = req->hdev;
9315− struct hci_cp_write_eir cp;
9316−
9317− if (!lmp_ext_inq_capable(hdev))
9318− return;
9319−
9320− memset(hdev->eir, 0, sizeof(hdev->eir));
9321−
9322− memset(&cp, 0, sizeof(cp));
9323−
9324− hci_req_add(req, HCI_OP_WRITE_EIR, sizeof(cp), &cp);
9325−}
9326−
9327−void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
9328−{
9329− struct cmd_lookup match = { NULL, hdev };
9330− struct hci_request req;
9331− bool changed = false;
9332−
9333− if (status) {
9334− u8 mgmt_err = mgmt_status(status);
9335−
9336− if (enable && hci_dev_test_and_clear_flag(hdev,
9337− HCI_SSP_ENABLED)) {
9338− hci_dev_clear_flag(hdev, HCI_HS_ENABLED);
9339− new_settings(hdev, NULL);
9340− }
9341−
9342− mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp,
9343− &mgmt_err);
9344− return;
9345− }
9346−
9347− if (enable) {
9348− changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED);
9349− } else {
9350− changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED);
9351− if (!changed)
9352− changed = hci_dev_test_and_clear_flag(hdev,
9353− HCI_HS_ENABLED);
9354− else
9355− hci_dev_clear_flag(hdev, HCI_HS_ENABLED);
9356− }
9357−
9358− mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match);
9359−
9360− if (changed)
9361− new_settings(hdev, match.sk);
9362−
9363− if (match.sk)
9364− sock_put(match.sk);
9365−
9366− hci_req_init(&req, hdev);
9367−
9368− if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) {
9369− if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS))
9370− hci_req_add(&req, HCI_OP_WRITE_SSP_DEBUG_MODE,
9371− sizeof(enable), &enable);
9372− __hci_req_update_eir(&req);
9373− } else {
9374− clear_eir(&req);
9375− }
9376−
9377− hci_req_run(&req, NULL);
9378−}
9379−
93809374 static void sk_lookup(struct mgmt_pending_cmd *cmd, void *data)
93819375 {
93829376 struct cmd_lookup *match = data;

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