Skip to content

Commit 258f56d

Browse files
josephsihholtmann
authored andcommitted
Bluetooth: aosp: Support AOSP Bluetooth Quality Report
This patch adds the support of the AOSP Bluetooth Quality Report (BQR) events. Multiple vendors have supported the AOSP Bluetooth Quality Report. When a Bluetooth controller supports the capability, it can enable the aosp capability through hci_set_aosp_capable. Then hci_core will set up the hdev->aosp_set_quality_report callback through aosp_do_open if the controller responds to support the quality report capability. Note that Intel also supports a distinct telemetry quality report specification. Intel sets up the hdev->set_quality_report callback in the btusb driver module. Reviewed-by: Miao-chen Chou <mcchou@chromium.org> Signed-off-by: Joseph Hwang <josephsih@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 749a6c5 commit 258f56d

3 files changed

Lines changed: 112 additions & 5 deletions

File tree

‎net/bluetooth/aosp.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,90 @@ void aosp_do_close(struct hci_dev *hdev)
112112

113113
bt_dev_dbg(hdev, "Cleanup of AOSP extension");
114114
}
115+
116+
/* BQR command */
117+
#define BQR_OPCODE hci_opcode_pack(0x3f, 0x015e)
118+
119+
/* BQR report action */
120+
#define REPORT_ACTION_ADD 0x00
121+
#define REPORT_ACTION_DELETE 0x01
122+
#define REPORT_ACTION_CLEAR 0x02
123+
124+
/* BQR event masks */
125+
#define QUALITY_MONITORING BIT(0)
126+
#define APPRAOCHING_LSTO BIT(1)
127+
#define A2DP_AUDIO_CHOPPY BIT(2)
128+
#define SCO_VOICE_CHOPPY BIT(3)
129+
130+
#define DEFAULT_BQR_EVENT_MASK (QUALITY_MONITORING | APPRAOCHING_LSTO | \
131+
A2DP_AUDIO_CHOPPY | SCO_VOICE_CHOPPY)
132+
133+
/* Reporting at milliseconds so as not to stress the controller too much.
134+
* Range: 0 ~ 65535 ms
135+
*/
136+
#define DEFALUT_REPORT_INTERVAL_MS 5000
137+
138+
struct aosp_bqr_cp {
139+
__u8 report_action;
140+
__u32 event_mask;
141+
__u16 min_report_interval;
142+
} __packed;
143+
144+
static int enable_quality_report(struct hci_dev *hdev)
145+
{
146+
struct sk_buff *skb;
147+
struct aosp_bqr_cp cp;
148+
149+
cp.report_action = REPORT_ACTION_ADD;
150+
cp.event_mask = DEFAULT_BQR_EVENT_MASK;
151+
cp.min_report_interval = DEFALUT_REPORT_INTERVAL_MS;
152+
153+
skb = __hci_cmd_sync(hdev, BQR_OPCODE, sizeof(cp), &cp,
154+
HCI_CMD_TIMEOUT);
155+
if (IS_ERR(skb)) {
156+
bt_dev_err(hdev, "Enabling Android BQR failed (%ld)",
157+
PTR_ERR(skb));
158+
return PTR_ERR(skb);
159+
}
160+
161+
kfree_skb(skb);
162+
return 0;
163+
}
164+
165+
static int disable_quality_report(struct hci_dev *hdev)
166+
{
167+
struct sk_buff *skb;
168+
struct aosp_bqr_cp cp = { 0 };
169+
170+
cp.report_action = REPORT_ACTION_CLEAR;
171+
172+
skb = __hci_cmd_sync(hdev, BQR_OPCODE, sizeof(cp), &cp,
173+
HCI_CMD_TIMEOUT);
174+
if (IS_ERR(skb)) {
175+
bt_dev_err(hdev, "Disabling Android BQR failed (%ld)",
176+
PTR_ERR(skb));
177+
return PTR_ERR(skb);
178+
}
179+
180+
kfree_skb(skb);
181+
return 0;
182+
}
183+
184+
bool aosp_has_quality_report(struct hci_dev *hdev)
185+
{
186+
return hdev->aosp_quality_report;
187+
}
188+
189+
int aosp_set_quality_report(struct hci_dev *hdev, bool enable)
190+
{
191+
if (!aosp_has_quality_report(hdev))
192+
return -EOPNOTSUPP;
193+
194+
bt_dev_dbg(hdev, "quality report enable %d", enable);
195+
196+
/* Enable or disable the quality report feature. */
197+
if (enable)
198+
return enable_quality_report(hdev);
199+
else
200+
return disable_quality_report(hdev);
201+
}

‎net/bluetooth/aosp.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88
void aosp_do_open(struct hci_dev *hdev);
99
void aosp_do_close(struct hci_dev *hdev);
1010

11+
bool aosp_has_quality_report(struct hci_dev *hdev);
12+
int aosp_set_quality_report(struct hci_dev *hdev, bool enable);
13+
1114
#else
1215

1316
static inline void aosp_do_open(struct hci_dev *hdev) {}
1417
static inline void aosp_do_close(struct hci_dev *hdev) {}
1518

19+
static inline bool aosp_has_quality_report(struct hci_dev *hdev)
20+
{
21+
return false;
22+
}
23+
24+
static inline int aosp_set_quality_report(struct hci_dev *hdev, bool enable)
25+
{
26+
return -EOPNOTSUPP;
27+
}
28+
1629
#endif

‎net/bluetooth/mgmt.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "mgmt_config.h"
4040
#include "msft.h"
4141
#include "eir.h"
42+
#include "aosp.h"
4243

4344
#define MGMT_VERSION 1
4445
#define MGMT_REVISION 21
@@ -3934,7 +3935,8 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
39343935
idx++;
39353936
}
39363937

3937-
if (hdev && hdev->set_quality_report) {
3938+
if (hdev && (aosp_has_quality_report(hdev) ||
3939+
hdev->set_quality_report)) {
39383940
if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT))
39393941
flags = BIT(0);
39403942
else
@@ -4198,21 +4200,26 @@ static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev,
41984200
val = !!cp->param[0];
41994201
changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT));
42004202

4201-
if (!hdev->set_quality_report) {
4203+
if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) {
42024204
err = mgmt_cmd_status(sk, hdev->id,
42034205
MGMT_OP_SET_EXP_FEATURE,
42044206
MGMT_STATUS_NOT_SUPPORTED);
42054207
goto unlock_quality_report;
42064208
}
42074209

42084210
if (changed) {
4209-
err = hdev->set_quality_report(hdev, val);
4211+
if (hdev->set_quality_report)
4212+
err = hdev->set_quality_report(hdev, val);
4213+
else
4214+
err = aosp_set_quality_report(hdev, val);
4215+
42104216
if (err) {
42114217
err = mgmt_cmd_status(sk, hdev->id,
42124218
MGMT_OP_SET_EXP_FEATURE,
42134219
MGMT_STATUS_FAILED);
42144220
goto unlock_quality_report;
42154221
}
4222+
42164223
if (val)
42174224
hci_dev_set_flag(hdev, HCI_QUALITY_REPORT);
42184225
else
@@ -4224,8 +4231,8 @@ static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev,
42244231
memcpy(rp.uuid, quality_report_uuid, 16);
42254232
rp.flags = cpu_to_le32(val ? BIT(0) : 0);
42264233
hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
4227-
err = mgmt_cmd_complete(sk, hdev->id,
4228-
MGMT_OP_SET_EXP_FEATURE, 0,
4234+
4235+
err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0,
42294236
&rp, sizeof(rp));
42304237

42314238
if (changed)

0 commit comments

Comments
 (0)