1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include "common/postable_context.h"
22 #include "include/hardware/bt_bqr.h"
23 #include "osi/include/osi.h"
24 #include "types/raw_address.h"
25 
26 namespace bluetooth {
27 namespace bqr {
28 
29 // Bluetooth Quality Report (BQR)
30 //
31 // It is a feature to start the mechanism in the Bluetooth controller to report
32 // Bluetooth Quality event to the host and the following options can be enabled:
33 //   [Quality Monitoring Mode]
34 //     The controller shall periodically send Bluetooth Quality Report sub-event
35 //     to the host.
36 //
37 //   [Approaching LSTO]
38 //     Once no packets are received from the connected Bluetooth device for a
39 //     duration longer than the half of LSTO (Link Supervision TimeOut) value,
40 //     the controller shall report Approaching LSTO event to the host.
41 //
42 //   [A2DP Audio Choppy]
43 //     When the controller detects the factors which will cause audio choppy,
44 //     the controller shall report A2DP Audio Choppy event to the host.
45 //
46 //   [(e)SCO Voice Choppy]
47 //     When the controller detects the factors which will cause voice choppy,
48 //     the controller shall report (e)SCO Voice Choppy event to the host.
49 //
50 //   [Root Inflammation]
51 //     When the controller encounters an error it shall report Root Inflammation
52 //     event indicating the error code to the host.
53 //
54 //   [Vendor Specific Quality]
55 //     Used for the controller vendor to define the vendor proprietary quality
56 //     event(s).
57 //
58 //   [LMP/LL message trace]
59 //     The controller sends the LMP/LL message handshaking with the remote
60 //     device to the host.
61 //
62 //   [Bluetooth Multi-profile/Coex scheduling trace]
63 //     The controller sends its scheduling information on handling the Bluetooth
64 //     multiple profiles and wireless coexistence in the 2.4 Ghz band to the
65 //     host.
66 //
67 //   [Enable the Controller Debug Information mechanism]
68 //     After enabling the Controller Debug Information mechanism, the controller
69 //     just can autonomously report debug logging information via the Controller
70 //     Debug Info sub-event to the host.
71 //
72 //   [Connect Fail]
73 //     When the controller fails to create connection with remote side,
74 //     and remote responds for at least one time, the controller shall report
75 //     connection fail event to the host. However, if remote doesn't respond
76 //     at all(most likely remote is powered off or out of range), controller
77 //     will not report this event.
78 
79 // Bit masks for the selected quality event reporting.
80 static constexpr uint32_t kQualityEventMaskAllOff = 0;
81 static constexpr uint32_t kQualityEventMaskMonitorMode = 0x1 << 0;
82 static constexpr uint32_t kQualityEventMaskApproachLsto = 0x1 << 1;
83 static constexpr uint32_t kQualityEventMaskA2dpAudioChoppy = 0x1 << 2;
84 static constexpr uint32_t kQualityEventMaskScoVoiceChoppy = 0x1 << 3;
85 static constexpr uint32_t kQualityEventMaskRootInflammation = 0x1 << 4;
86 static constexpr uint32_t kQualityEventMaskEnergyMonitoring = 0x1 << 5;
87 static constexpr uint32_t kQualityEventMaskLeAudioChoppy = 0x1 << 6;
88 static constexpr uint32_t kQualityEventMaskConnectFail = 0x1 << 7;
89 static constexpr uint32_t kQualityEventMaskAdvRFStatsEvent = 0x1 << 8;
90 static constexpr uint32_t kQualityEventMaskAdvRFStatsMonitor = 0x1 << 9;
91 static constexpr uint32_t kQualityEventMaskHealthMonitorStatsEvent = 0x1 << 10;
92 static constexpr uint32_t kQualityEventMaskControllerHealthMonitor = 0x1 << 11;
93 static constexpr uint32_t kQualityEventMaskVendorSpecificQuality = 0x1 << 15;
94 static constexpr uint32_t kQualityEventMaskLmpMessageTrace = 0x1 << 16;
95 static constexpr uint32_t kQualityEventMaskBtSchedulingTrace = 0x1 << 17;
96 static constexpr uint32_t kQualityEventMaskControllerDbgInfo = 0x1 << 18;
97 static constexpr uint32_t kQualityEventMaskVendorSpecificTrace = 0x1 << 31;
98 static constexpr uint32_t kQualityEventMaskAll =
99         kQualityEventMaskMonitorMode | kQualityEventMaskApproachLsto |
100         kQualityEventMaskA2dpAudioChoppy | kQualityEventMaskScoVoiceChoppy |
101         kQualityEventMaskRootInflammation | kQualityEventMaskEnergyMonitoring |
102         kQualityEventMaskLeAudioChoppy | kQualityEventMaskConnectFail |
103         kQualityEventMaskAdvRFStatsEvent | kQualityEventMaskAdvRFStatsMonitor |
104         kQualityEventMaskHealthMonitorStatsEvent | kQualityEventMaskControllerHealthMonitor |
105         kQualityEventMaskVendorSpecificQuality | kQualityEventMaskLmpMessageTrace |
106         kQualityEventMaskBtSchedulingTrace | kQualityEventMaskControllerDbgInfo |
107         kQualityEventMaskVendorSpecificTrace;
108 // Define the minimum time interval (in ms) of quality event reporting for the
109 // selected quality event(s). Controller Firmware should not report the next
110 // event within the defined Minimum Report Interval * Report Interval
111 // Multiple.
112 static constexpr uint16_t kMinReportIntervalNoLimit = 0;
113 static constexpr uint16_t kMinReportIntervalMaxMs = 0xFFFF;
114 // Define the Report Interval Multiple of quality event reporting for the
115 // selected quality event(s). Controller Firmware should not report the next
116 // event within interval: Minimum Report interval * Report Interval Multiple.
117 // When Report Interval Multiple set to 0 is equal set to 1
118 static constexpr uint32_t kReportIntervalMultipleNoLimit = 0;
119 static constexpr uint32_t kReportIntervalMultipleMax = 0xFFFFFFFF;
120 // The maximum count of Log Dump related event can be written in the log file.
121 static constexpr uint16_t kLogDumpEventPerFile = 0x00FF;
122 // Total length of all parameters of the link Quality related event except
123 // Vendor Specific Parameters.
124 static constexpr uint8_t kLinkQualityParamTotalLen = 48;
125 // 7.8.116 LE Read ISO Link Quality command
126 static constexpr uint8_t kISOLinkQualityParamTotalLen = 24;
127 // Total length of all parameters of the ROOT_INFLAMMATION event except Vendor
128 // Specific Parameters.
129 static constexpr uint8_t kRootInflammationParamTotalLen = 3;
130 // Total length of all parameters of the Log Dump related event except Vendor
131 // Specific Parameters.
132 static constexpr uint8_t kLogDumpParamTotalLen = 3;
133 // Remote address and calibration failure count parameters len
134 // Added in BQR V5.0
135 static constexpr uint8_t kVersion5_0ParamsTotalLen = 7;
136 // Added in BQR V6.0
137 static constexpr uint8_t kVersion6_0ParamsTotalLen = 6;
138 
139 // Warning criteria of the RSSI value.
140 static constexpr int8_t kCriWarnRssi = -80;
141 // Warning criteria of the unused AFH channel count.
142 static constexpr uint8_t kCriWarnUnusedCh = 55;
143 // The queue size of recording the BQR events.
144 static constexpr uint8_t kBqrEventQueueSize = 25;
145 // The Property of BQR event mask configuration.
146 static constexpr const char* kpPropertyEventMask = "persist.bluetooth.bqr.event_mask";
147 // The Property of BQR Vendor Quality configuration.
148 static constexpr const char* kpPropertyVndQualityMask = "persist.bluetooth.bqr.vnd_quality_mask";
149 // The Property of BQR Vendor Trace configuration.
150 static constexpr const char* kpPropertyVndTraceMask = "persist.bluetooth.bqr.vnd_trace_mask";
151 // The Property of BQR minimum report interval configuration.
152 static constexpr const char* kpPropertyMinReportIntervalMs =
153         "persist.bluetooth.bqr.min_interval_ms";
154 // The Property of BQR minimum report interval multiple.
155 static constexpr const char* kpPropertyIntervalMultiple = "persist.bluetooth.bqr.interval_multiple";
156 // Path of the LMP/LL message trace log file.
157 static constexpr const char* kpLmpLlMessageTraceLogPath =
158         "/data/misc/bluetooth/logs/lmp_ll_message_trace.log";
159 // Path of the last LMP/LL message trace log file.
160 static constexpr const char* kpLmpLlMessageTraceLastLogPath =
161         "/data/misc/bluetooth/logs/lmp_ll_message_trace.log.last";
162 // Path of the Bluetooth Multi-profile/Coex scheduling trace log file.
163 static constexpr const char* kpBtSchedulingTraceLogPath =
164         "/data/misc/bluetooth/logs/bt_scheduling_trace.log";
165 // Path of the last Bluetooth Multi-profile/Coex scheduling trace log file.
166 static constexpr const char* kpBtSchedulingTraceLastLogPath =
167         "/data/misc/bluetooth/logs/bt_scheduling_trace.log.last";
168 // The Property of BQR a2dp choppy report and sco choppy report thresholds.
169 // A2dp choppy will be reported only when a2dp choppy times is >=
170 // a2dp_choppy_threshold. The default value in firmware side is 1. It is same
171 // for sco choppy. Value format is a2dp_choppy_threshold,sco_choppy_threshold
172 static constexpr const char* kpPropertyChoppyThreshold = "persist.bluetooth.bqr.choppy_threshold";
173 
174 // The version supports ISO packets start from v1.01(257)
175 static constexpr uint16_t kBqrIsoVersion = 0x101;
176 // The version supports vendor quality and trace log starting v1.02(258)
177 static constexpr uint16_t kBqrVndLogVersion = 0x102;
178 // The version supports remote address info and calibration failure count
179 // start from v1.03(259)
180 static constexpr uint16_t kBqrVersion5_0 = 0x103;
181 // The REPORT_ACTION_QUERY and BQR_Report_interval starting v1.04(260)
182 static constexpr uint16_t kBqrVersion6_0 = 0x104;
183 static constexpr uint16_t kBqrVersion7_0 = 0x105;
184 // Action definition
185 //
186 // Action to Add, Delete or Clear the reporting of quality event(s).
187 // Delete will clear specific quality event(s) reporting. Clear will clear all
188 // quality events reporting.
189 enum BqrReportAction : uint8_t {
190   REPORT_ACTION_ADD = 0x00,
191   REPORT_ACTION_DELETE = 0x01,
192   REPORT_ACTION_CLEAR = 0x02,
193   REPORT_ACTION_QUERY = 0x03
194 };
195 
196 // Report ID definition
197 enum BqrQualityReportId : uint8_t {
198   QUALITY_REPORT_ID_MONITOR_MODE = 0x01,
199   QUALITY_REPORT_ID_APPROACH_LSTO = 0x02,
200   QUALITY_REPORT_ID_A2DP_AUDIO_CHOPPY = 0x03,
201   QUALITY_REPORT_ID_SCO_VOICE_CHOPPY = 0x04,
202   QUALITY_REPORT_ID_ROOT_INFLAMMATION = 0x05,
203   QUALITY_REPORT_ID_ENERGY_MONITOR = 0x06,
204   QUALITY_REPORT_ID_LE_AUDIO_CHOPPY = 0x07,
205   QUALITY_REPORT_ID_CONNECT_FAIL = 0x08,
206   QUALITY_REPORT_ID_RF_STATS = 0x09,
207   QUALITY_REPORT_ID_VENDOR_SPECIFIC_QUALITY = 0x10,
208   QUALITY_REPORT_ID_LMP_LL_MESSAGE_TRACE = 0x11,
209   QUALITY_REPORT_ID_BT_SCHEDULING_TRACE = 0x12,
210   QUALITY_REPORT_ID_CONTROLLER_DBG_INFO = 0x13,
211   QUALITY_REPORT_ID_VENDOR_SPECIFIC_TRACE = 0x20,
212 };
213 
214 // Packet Type definition
215 enum BqrPacketType : uint8_t {
216   PACKET_TYPE_ID = 0x01,
217   PACKET_TYPE_NULL,
218   PACKET_TYPE_POLL,
219   PACKET_TYPE_FHS,
220   PACKET_TYPE_HV1,
221   PACKET_TYPE_HV2,
222   PACKET_TYPE_HV3,
223   PACKET_TYPE_DV,
224   PACKET_TYPE_EV3,
225   PACKET_TYPE_EV4,
226   PACKET_TYPE_EV5,
227   PACKET_TYPE_2EV3,
228   PACKET_TYPE_2EV5,
229   PACKET_TYPE_3EV3,
230   PACKET_TYPE_3EV5,
231   PACKET_TYPE_DM1,
232   PACKET_TYPE_DH1,
233   PACKET_TYPE_DM3,
234   PACKET_TYPE_DH3,
235   PACKET_TYPE_DM5,
236   PACKET_TYPE_DH5,
237   PACKET_TYPE_AUX1,
238   PACKET_TYPE_2DH1,
239   PACKET_TYPE_2DH3,
240   PACKET_TYPE_2DH5,
241   PACKET_TYPE_3DH1,
242   PACKET_TYPE_3DH3,
243   PACKET_TYPE_3DH5,
244   PACKET_TYPE_ISO = 0x51
245 };
246 
247 // Configuration Parameters
248 typedef struct {
249   BqrReportAction report_action;
250   uint32_t quality_event_mask;
251   uint16_t minimum_report_interval_ms;
252   uint32_t vnd_quality_mask;
253   uint32_t vnd_trace_mask;
254   uint32_t report_interval_multiple;
255 } BqrConfiguration;
256 
257 // Link quality related BQR event
258 typedef struct {
259   // Quality report ID.
260   uint8_t quality_report_id;
261   // Packet type of the connection.
262   uint8_t packet_types;
263   // Connection handle of the connection.
264   uint16_t connection_handle;
265   // Performing Role for the connection.
266   uint8_t connection_role;
267   // Current Transmit Power Level for the connection. This value is the same as
268   // the controller's response to the HCI_Read_Transmit_Power_Level HCI command.
269   int8_t tx_power_level;
270   // Received Signal Strength Indication (RSSI) value for the connection. This
271   // value is an absolute receiver signal strength value.
272   int8_t rssi;
273   // Signal-to-Noise Ratio (SNR) value for the connection. It is the average
274   // SNR of all the channels used by the link currently.
275   uint8_t snr;
276   // Indicates the number of unused channels in AFH_channel_map.
277   uint8_t unused_afh_channel_count;
278   // Indicates the number of the channels which are interfered and quality is
279   // bad but are still selected for AFH.
280   uint8_t afh_select_unideal_channel_count;
281   // Current Link Supervision Timeout Setting.
282   // Unit: N * 0.3125 ms (1 Bluetooth Clock)
283   uint16_t lsto;
284   // Piconet Clock for the specified Connection_Handle. This value is the same
285   // as the controller's response to HCI_Read_Clock HCI command with the
286   // parameter "Which_Clock" of 0x01 (Piconet Clock).
287   // Unit: N * 0.3125 ms (1 Bluetooth Clock)
288   uint32_t connection_piconet_clock;
289   // The count of retransmission.
290   uint32_t retransmission_count;
291   // The count of no RX.
292   uint32_t no_rx_count;
293   // The count of NAK (Negative Acknowledge).
294   uint32_t nak_count;
295   // Timestamp of last TX ACK.
296   // Unit: N * 0.3125 ms (1 Bluetooth Clock)
297   uint32_t last_tx_ack_timestamp;
298   // The count of Flow-off (STOP).
299   uint32_t flow_off_count;
300   // Timestamp of last Flow-on (GO).
301   // Unit: N * 0.3125 ms (1 Bluetooth Clock)
302   uint32_t last_flow_on_timestamp;
303   // Buffer overflow count (how many bytes of TX data are dropped) since the
304   // last event.
305   uint32_t buffer_overflow_bytes;
306   // Buffer underflow count (in byte).
307   uint32_t buffer_underflow_bytes;
308   // Remote device address
309   RawAddress bdaddr;
310   // The count of calibration failed items
311   uint8_t cal_failed_item_count;
312   // The number of packets that are sent out.
313   uint32_t tx_total_packets;
314   // The number of packets that don't receive an acknowledgment.
315   uint32_t tx_unacked_packets;
316   // The number of packets that are not sent out by its flush point.
317   uint32_t tx_flushed_packets;
318   // The number of packets that Link Layer transmits a CIS Data PDU in the last
319   // subevent of a CIS event.
320   uint32_t tx_last_subevent_packets;
321   // The number of received packages with CRC error since the last event.
322   uint32_t crc_error_packets;
323   // The number of duplicate(retransmission) packages that are received since
324   // the last event.
325   uint32_t rx_duplicate_packets;
326   // The number of unreceived packets is the same as the parameter of LE Read
327   // ISO Link Quality command.
328   uint32_t rx_unreceived_packets;
329   // Bitmask to indicate various coex related information
330   uint16_t coex_info_mask;
331   // For the controller vendor to obtain more vendor specific parameters.
332   const uint8_t* vendor_specific_parameter;
333 } BqrLinkQualityEvent;
334 
335 // Energy Monitor BQR event
336 typedef struct {
337   // Quality report ID.
338   uint8_t quality_report_id;
339   // Average current consumption of all activities consumed by the controller (mA)
340   uint16_t avg_current_consume;
341   // Total time in the idle (low power states, sleep) state. (ms)
342   uint32_t idle_total_time;
343   // Indicates how many times the controller enters the idle state.
344   uint32_t idle_state_enter_count;
345   // Total time in the active (inquiring, paging, ACL/SCO/eSCO/BIS/CIS traffic, processing any task)
346   // state. (ms)
347   uint32_t active_total_time;
348   // Indicates how many times the controller enters the active states.
349   uint32_t active_state_enter_count;
350   // Total time in the BR/EDR specific Tx(Transmitting for ACL/SCO/eSCO traffic)state (ms)
351   uint32_t bredr_tx_total_time;
352   // Indicates how many times the controller enters the BR/EDR specific Tx state.
353   uint32_t bredr_tx_state_enter_count;
354   // Average Tx power level of all the BR/EDR link(s) (dBm)
355   uint8_t bredr_tx_avg_power_lv;
356   // Total time in the BR/EDR specific Rx (Receiving from ACL/SCO/eSCO traffic) state. (ms)
357   uint32_t bredr_rx_total_time;
358   // Indicates how many times the controller enters the BR/EDR specific Rx state. (ms)
359   uint32_t bredr_rx_state_enter_count;
360   // Total time in the LE specific Tx (Transmitting for either ACL/BIS/CIS or LE advertising
361   // traffic) state (ms)
362   uint32_t le_tx_total_time;
363   // Indicates how many times the controller enters theLE specific Tx state.
364   uint32_t le_tx_state_enter_count;
365   // Average Tx power level of all the LE link(s) (dBm)
366   uint8_t le_tx_avg_power_lv;
367   // Total time in the LE specific Rx (Receiving from either ACL/BIS/CIS or LE scanning traffic)
368   // state. (ms)
369   uint32_t le_rx_total_time;
370   // Indicates how many times the controller enters the LE specific Rx state
371   uint32_t le_rx_state_enter_count;
372   // The total time duration to collect power related information (ms)
373   uint32_t tm_period;
374   // The time duration of RX active in one chain
375   uint32_t rx_active_one_chain_time;
376   // The time duration of RX active in two chain
377   uint32_t rx_active_two_chain_time;
378   // The time duration of internal TX active in one chain
379   uint32_t tx_ipa_active_one_chain_time;
380   // The time duration of internal TX active in two chain
381   uint32_t tx_ipa_active_two_chain_time;
382   // The time duration of external TX active in one chain
383   uint32_t tx_epa_active_one_chain_time;
384   // The time duration of external TX active in two chain
385   uint32_t tx_epa_active_two_chain_time;
386 } __attribute__((__packed__)) BqrEnergyMonitorEvent;
387 
388 static constexpr uint8_t kEnergyMonitorParamTotalLen = sizeof(BqrEnergyMonitorEvent);
389 
390 // RF Stats BQR event
391 typedef struct {
392   // Quality report ID.
393   uint8_t quality_report_id;
394   // Extension for Further usage = 0x01 for BQRv6
395   uint8_t ext_info;
396   // time period (ms)
397   uint32_t tm_period;
398   // Packet counter of iPA BF
399   uint32_t tx_pw_ipa_bf;
400   // Packet counter of ePA BF
401   uint32_t tx_pw_epa_bf;
402   // Packet counter of iPA Div
403   uint32_t tx_pw_ipa_div;
404   // Packet counter of ePA Div
405   uint32_t tx_pw_epa_div;
406   // Packet counter of RSSI chain > -50 dBm
407   uint32_t rssi_ch_50;
408   // Packet counter of RSSI chain between  -50 dBm ~ >-55 dBm
409   uint32_t rssi_ch_50_55;
410   // Packet counter of RSSI chain between  -55 dBm ~ >-60 dBm
411   uint32_t rssi_ch_55_60;
412   // Packet counter of RSSI chain between  -60 dBm ~ >-65 dBm
413   uint32_t rssi_ch_60_65;
414   // Packet counter of RSSI chain between  -65 dBm ~ >-70 dBm
415   uint32_t rssi_ch_65_70;
416   // Packet counter of RSSI chain between  -70 dBm ~ >-75 dBm
417   uint32_t rssi_ch_70_75;
418   // Packet counter of RSSI chain between  -75 dBm ~ >-80 dBm
419   uint32_t rssi_ch_75_80;
420   // Packet counter of RSSI chain between  -80 dBm ~ >-85 dBm
421   uint32_t rssi_ch_80_85;
422   // Packet counter of RSSI chain between  -85 dBm ~ >-90 dBm
423   uint32_t rssi_ch_85_90;
424   // Packet counter of RSSI chain  < -90 dBm
425   uint32_t rssi_ch_90;
426   // Packet counter of RSSI delta < 2 dBm
427   uint32_t rssi_delta_2_down;
428   // Packet counter of  RSSI delta between 2 dBm ~ 5 dBm
429   uint32_t rssi_delta_2_5;
430   // Packet counter of  RSSI delta between 5 dBm ~ 8 dB
431   uint32_t rssi_delta_5_8;
432   // Packet counter of  RSSI delta between 8 dBm ~ 11 dBm
433   uint32_t rssi_delta_8_11;
434   // Packet counter of RSSI delta > 11 dBm
435   uint32_t rssi_delta_11_up;
436 } __attribute__((__packed__)) BqrRFStatsEvent;
437 
438 // Total length of all parameters of the RF Stats event
439 static constexpr uint8_t kRFStatsParamTotalLen = sizeof(BqrRFStatsEvent);
440 
441 // Log dump related BQR event
442 typedef struct {
443   // Quality report ID.
444   uint8_t quality_report_id;
445   // Connection handle of the connection.
446   uint16_t connection_handle;
447   // For the controller vendor to obtain more vendor specific parameters.
448   const uint8_t* vendor_specific_parameter;
449 } BqrLogDumpEvent;
450 
451 // BQR sub-event of Vendor Specific Event
452 class BqrVseSubEvt {
453 public:
454   // Parse the Link Quality related BQR event.
455   //
456   // @param length Total length of all parameters contained in the sub-event.
457   // @param p_param_buf A pointer to the parameters contained in the sub-event.
458   void ParseBqrLinkQualityEvt(uint8_t length, const uint8_t* p_param_buf);
459   // Parse the Energy Monitor BQR event.
460   //
461   // @param length Total length of all parameters contained in the sub-event.
462   // @param p_param_buf A pointer to the parameters contained in the sub-event.
463   //
464   // @return true if the event was parsed successfully, false otherwise.
465   bool ParseBqrEnergyMonitorEvt(uint8_t length, const uint8_t* p_param_buf);
466   // Parse the RF Stats BQR event.
467   //
468   // @param length Total length of all parameters contained in the sub-event.
469   // @param p_param_buf A pointer to the parameters contained in the sub-event.
470   //
471   // @return true if the event was parsed successfully, false otherwise.
472   bool ParseBqrRFStatsEvt(uint8_t length, const uint8_t* p_param_buf);
473   // Write the LMP/LL message trace to the log file.
474   //
475   // @param fd The File Descriptor of the log file.
476   // @param length Total length of all parameters contained in the sub-event.
477   // @param p_param_buf A pointer to the parameters contained in the sub-event.
478   void WriteLmpLlTraceLogFile(int fd, uint8_t length, const uint8_t* p_param_buf);
479   // Write the Bluetooth Multi-profile/Coex scheduling trace to the log file.
480   //
481   // @param fd The File Descriptor of the log file.
482   // @param length Total length of all parameters contained in the sub-event.
483   // @param p_param_buf A pointer to the parameters contained in the sub-event.
484   void WriteBtSchedulingTraceLogFile(int fd, uint8_t length, const uint8_t* p_param_buf);
485   // Get a string representation of the Bluetooth Quality event.
486   //
487   // @return a string representation of the Bluetooth Quality event.
488   std::string ToString() const;
489 
490   friend std::ostream& operator<<(std::ostream& os, const BqrVseSubEvt& a) {
491     return os << a.ToString();
492   }
493 
494   virtual ~BqrVseSubEvt() = default;
495   // Link Quality related BQR event
496   BqrLinkQualityEvent bqr_link_quality_event_ = {};
497   // Energy Monitor BQR event
498   BqrEnergyMonitorEvent bqr_energy_monitor_event_ = {};
499   // RF Stats BQR event
500   BqrRFStatsEvent bqr_rf_stats_event_ = {};
501   // Log Dump related BQR event
502   BqrLogDumpEvent bqr_log_dump_event_ = {};
503   // Local wall clock timestamp of receiving BQR VSE sub-event
504   std::tm tm_timestamp_ = {};
505 };
506 
507 BluetoothQualityReportInterface* getBluetoothQualityReportInterface();
508 
509 // Enable Bluetooth Quality Report mechanism.
510 //
511 // Which Quality event will be enabled is according to the setting of the
512 // property "persist.bluetooth.bqr.event_mask".
513 // And the minimum time interval of quality event reporting depends on the
514 // setting of property "persist.bluetooth.bqr.min_interval_ms".
515 //
516 // @param to_bind gives the postable for the callback.
517 void EnableBtQualityReport(common::PostableContext* to_bind);
518 
519 // Disable Bluetooth Quality Report mechanism.
520 void DisableBtQualityReport();
521 
522 // Dump Bluetooth Quality Report information.
523 //
524 // @param fd The file descriptor to use for dumping information.
525 void DebugDump(int fd);
526 
527 // Configure the file descriptor for the LMP/LL message trace log.
528 void SetLmpLlMessageTraceLogFd(int fd);
529 
530 }  // namespace bqr
531 }  // namespace bluetooth
532 
533 namespace std {
534 template <>
535 struct formatter<bluetooth::bqr::BqrReportAction>
536     : enum_formatter<bluetooth::bqr::BqrReportAction> {};
537 template <>
538 struct formatter<bluetooth::bqr::BqrVseSubEvt> : ostream_formatter {};
539 }  // namespace std
540