]>
Commit | Line | Data |
---|---|---|
7f87a3cd SL |
1 | From a18146e51c874d5e9cfddb143e56023462004f3f Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Tue, 6 Apr 2021 21:55:52 +0200 | |
4 | Subject: Bluetooth: Add support for reading AOSP vendor capabilities | |
5 | ||
6 | From: Marcel Holtmann <marcel@holtmann.org> | |
7 | ||
8 | [ Upstream commit f67743f9e03a67dbbf931d1787e6faf50766e521 ] | |
9 | ||
10 | When drivers indicate support for AOSP vendor extension, initialize them | |
11 | and read its capabilities. | |
12 | ||
13 | Signed-off-by: Marcel Holtmann <marcel@holtmann.org> | |
14 | Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | |
15 | Stable-dep-of: 51eda36d33e4 ("Bluetooth: SCO: Fix not validating setsockopt user input") | |
16 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
17 | --- | |
18 | include/net/bluetooth/hci_core.h | 11 ++++++++++ | |
19 | net/bluetooth/Kconfig | 7 +++++++ | |
20 | net/bluetooth/Makefile | 1 + | |
21 | net/bluetooth/aosp.c | 35 ++++++++++++++++++++++++++++++++ | |
22 | net/bluetooth/aosp.h | 16 +++++++++++++++ | |
23 | net/bluetooth/hci_core.c | 3 +++ | |
24 | 6 files changed, 73 insertions(+) | |
25 | create mode 100644 net/bluetooth/aosp.c | |
26 | create mode 100644 net/bluetooth/aosp.h | |
27 | ||
28 | diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h | |
29 | index 33873266b2bc7..daafca376cb7c 100644 | |
30 | --- a/include/net/bluetooth/hci_core.h | |
31 | +++ b/include/net/bluetooth/hci_core.h | |
32 | @@ -569,6 +569,10 @@ struct hci_dev { | |
33 | void *msft_data; | |
34 | #endif | |
35 | ||
36 | +#if IS_ENABLED(CONFIG_BT_AOSPEXT) | |
37 | + bool aosp_capable; | |
38 | +#endif | |
39 | + | |
40 | int (*open)(struct hci_dev *hdev); | |
41 | int (*close)(struct hci_dev *hdev); | |
42 | int (*flush)(struct hci_dev *hdev); | |
43 | @@ -1222,6 +1226,13 @@ static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode) | |
44 | #endif | |
45 | } | |
46 | ||
47 | +static inline void hci_set_aosp_capable(struct hci_dev *hdev) | |
48 | +{ | |
49 | +#if IS_ENABLED(CONFIG_BT_AOSPEXT) | |
50 | + hdev->aosp_capable = true; | |
51 | +#endif | |
52 | +} | |
53 | + | |
54 | int hci_dev_open(__u16 dev); | |
55 | int hci_dev_close(__u16 dev); | |
56 | int hci_dev_do_close(struct hci_dev *hdev); | |
57 | diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig | |
58 | index 64e669acd42f9..11a563d95e67b 100644 | |
59 | --- a/net/bluetooth/Kconfig | |
60 | +++ b/net/bluetooth/Kconfig | |
61 | @@ -99,6 +99,13 @@ config BT_MSFTEXT | |
62 | This options enables support for the Microsoft defined HCI | |
63 | vendor extensions. | |
64 | ||
65 | +config BT_AOSPEXT | |
66 | + bool "Enable Android Open Source Project extensions" | |
67 | + depends on BT | |
68 | + help | |
69 | + This options enables support for the Android Open Source | |
70 | + Project defined HCI vendor extensions. | |
71 | + | |
72 | config BT_DEBUGFS | |
73 | bool "Export Bluetooth internals in debugfs" | |
74 | depends on BT && DEBUG_FS | |
75 | diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile | |
76 | index 1c645fba8c493..cc0995301f93f 100644 | |
77 | --- a/net/bluetooth/Makefile | |
78 | +++ b/net/bluetooth/Makefile | |
79 | @@ -20,5 +20,6 @@ bluetooth-$(CONFIG_BT_BREDR) += sco.o | |
80 | bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o | |
81 | bluetooth-$(CONFIG_BT_LEDS) += leds.o | |
82 | bluetooth-$(CONFIG_BT_MSFTEXT) += msft.o | |
83 | +bluetooth-$(CONFIG_BT_AOSPEXT) += aosp.o | |
84 | bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o | |
85 | bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o | |
86 | diff --git a/net/bluetooth/aosp.c b/net/bluetooth/aosp.c | |
87 | new file mode 100644 | |
88 | index 0000000000000..a1b7762335a51 | |
89 | --- /dev/null | |
90 | +++ b/net/bluetooth/aosp.c | |
91 | @@ -0,0 +1,35 @@ | |
92 | +// SPDX-License-Identifier: GPL-2.0-only | |
93 | +/* | |
94 | + * Copyright (C) 2021 Intel Corporation | |
95 | + */ | |
96 | + | |
97 | +#include <net/bluetooth/bluetooth.h> | |
98 | +#include <net/bluetooth/hci_core.h> | |
99 | + | |
100 | +#include "aosp.h" | |
101 | + | |
102 | +void aosp_do_open(struct hci_dev *hdev) | |
103 | +{ | |
104 | + struct sk_buff *skb; | |
105 | + | |
106 | + if (!hdev->aosp_capable) | |
107 | + return; | |
108 | + | |
109 | + bt_dev_dbg(hdev, "Initialize AOSP extension"); | |
110 | + | |
111 | + /* LE Get Vendor Capabilities Command */ | |
112 | + skb = __hci_cmd_sync(hdev, hci_opcode_pack(0x3f, 0x153), 0, NULL, | |
113 | + HCI_CMD_TIMEOUT); | |
114 | + if (IS_ERR(skb)) | |
115 | + return; | |
116 | + | |
117 | + kfree_skb(skb); | |
118 | +} | |
119 | + | |
120 | +void aosp_do_close(struct hci_dev *hdev) | |
121 | +{ | |
122 | + if (!hdev->aosp_capable) | |
123 | + return; | |
124 | + | |
125 | + bt_dev_dbg(hdev, "Cleanup of AOSP extension"); | |
126 | +} | |
127 | diff --git a/net/bluetooth/aosp.h b/net/bluetooth/aosp.h | |
128 | new file mode 100644 | |
129 | index 0000000000000..328fc6d39f703 | |
130 | --- /dev/null | |
131 | +++ b/net/bluetooth/aosp.h | |
132 | @@ -0,0 +1,16 @@ | |
133 | +// SPDX-License-Identifier: GPL-2.0-only | |
134 | +/* | |
135 | + * Copyright (C) 2021 Intel Corporation | |
136 | + */ | |
137 | + | |
138 | +#if IS_ENABLED(CONFIG_BT_AOSPEXT) | |
139 | + | |
140 | +void aosp_do_open(struct hci_dev *hdev); | |
141 | +void aosp_do_close(struct hci_dev *hdev); | |
142 | + | |
143 | +#else | |
144 | + | |
145 | +static inline void aosp_do_open(struct hci_dev *hdev) {} | |
146 | +static inline void aosp_do_close(struct hci_dev *hdev) {} | |
147 | + | |
148 | +#endif | |
149 | diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c | |
150 | index b9cf5bc9364c1..f4fc5a81ae928 100644 | |
151 | --- a/net/bluetooth/hci_core.c | |
152 | +++ b/net/bluetooth/hci_core.c | |
153 | @@ -44,6 +44,7 @@ | |
154 | #include "smp.h" | |
155 | #include "leds.h" | |
156 | #include "msft.h" | |
157 | +#include "aosp.h" | |
158 | ||
159 | static void hci_rx_work(struct work_struct *work); | |
160 | static void hci_cmd_work(struct work_struct *work); | |
161 | @@ -1586,6 +1587,7 @@ static int hci_dev_do_open(struct hci_dev *hdev) | |
162 | ret = hdev->set_diag(hdev, true); | |
163 | ||
164 | msft_do_open(hdev); | |
165 | + aosp_do_open(hdev); | |
166 | ||
167 | clear_bit(HCI_INIT, &hdev->flags); | |
168 | ||
169 | @@ -1788,6 +1790,7 @@ int hci_dev_do_close(struct hci_dev *hdev) | |
170 | ||
171 | hci_sock_dev_event(hdev, HCI_DEV_DOWN); | |
172 | ||
173 | + aosp_do_close(hdev); | |
174 | msft_do_close(hdev); | |
175 | ||
176 | if (hdev->flush) | |
177 | -- | |
178 | 2.43.0 | |
179 |