1 /******************************************************************************
2  *
3  *  Copyright 2015 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #include <hardware/bluetooth.h>
22 #include <stdbool.h>
23 
24 #include "include/hardware/bluetooth.h"
25 #include "osi/include/list.h"
26 #include "types/raw_address.h"
27 
28 static const char INTEROP_MODULE[] = "interop_module";
29 
30 // NOTE:
31 // Only add values at the end of this enum and before END_OF_INTEROP_LIST
32 // do NOT delete values as they may be used in dynamic device configuration.
33 typedef enum {
34   BEGINNING_OF_INTEROP_LIST = 0,
35   // Disable secure connections
36   // This is for pre BT 4.1/2 devices that do not handle secure mode
37   // very well.
38   INTEROP_DISABLE_LE_SECURE_CONNECTIONS = BEGINNING_OF_INTEROP_LIST,
39 
40   // Some devices have proven problematic during the pairing process, often
41   // requiring multiple retries to complete pairing. To avoid degrading the user
42   // experience for those devices, automatically re-try pairing if page
43   // timeouts are received during pairing.
44   INTEROP_AUTO_RETRY_PAIRING,
45 
46   // Devices requiring this workaround do not handle Bluetooth Absolute Volume
47   // control correctly, leading to undesirable (potentially harmful) volume
48   // levels or general lack of controlability.
49   INTEROP_DISABLE_ABSOLUTE_VOLUME,
50 
51   // Disable automatic pairing with headsets/car-kits
52   // Some car kits do not react kindly to a failed pairing attempt and
53   // do not allow immediate re-pairing. Rejectlist these so that the initial
54   // pairing attempt makes it to the user instead.
55   INTEROP_DISABLE_AUTO_PAIRING,
56 
57   // Use a fixed pin for specific keyboards
58   // Keyboards should use a variable pin at all times. However, some keyboards
59   // require a fixed pin of all 0000. This workaround enables auto pairing for
60   // those keyboards.
61   INTEROP_KEYBOARD_REQUIRES_FIXED_PIN,
62 
63   // Some headsets have audio jitter issues because of increased
64   // re-transmissions as the 3 Mbps packets have a lower link margin, and are
65   // more prone to interference. We can disable 3DH packets (use only 2DH
66   // packets) for the ACL link to improve sensitivity when streaming A2DP audio
67   // to the headset. Air sniffer logs show reduced re-transmissions after
68   // switching to 2DH packets.
69 
70   // Disable 3Mbps packets and use only 2Mbps packets for ACL links when
71   // streaming audio.
72   INTEROP_2MBPS_LINK_ONLY,
73 
74   // Some HID devices have proven problematic behaviour if SDP is initiated
75   // again while HID connection is in progress or if more than 1 SDP connection
76   // is  created with those HID devices rsulting in issues of connection
77   // failure with such devices. To avoid degrading the user experience with
78   // those devices, SDP is not attempted as part of pairing process.
79   INTEROP_DISABLE_SDP_AFTER_PAIRING,
80 
81   // HID Keyboards that claim support for multitouch functionality have issue
82   // with  normal functioning of keyboard because of issues in USB HID kernel
83   // driver. To avoid degrading the user experience with those devices,
84   // digitizer record is removed from the report descriptor.
85   INTEROP_REMOVE_HID_DIG_DESCRIPTOR,
86 
87   // Some HID devices have problematic behaviour where when hid link is in Sniff
88   // and DUT is in peripheral role for SCO link (not eSCO) any solution cannot
89   // maintain the link as SCO scheduling over a short period will overlap with
90   // Sniff link due to peripheral drift. To avoid degrading the user experience
91   // with those devices, sniff is disabled from link policy when sco is active,
92   // and enabled when sco is disabled.
93   INTEROP_DISABLE_SNIFF_DURING_SCO,
94 
95   // Do not use supervision timeout value received from preferred connection
96   // parameters, use 3s instead. Use with HID only.
97   INTEROP_HID_PREF_CONN_SUP_TIMEOUT_3S,
98 
99   // Do not send service changed indications (GATT client).
100   // This should be removed after the characteristic is implmeented b/62088395.
101   INTEROP_GATTC_NO_SERVICE_CHANGED_IND,
102 
103   // Few carkits take long time to start sending AT commands
104   // Increase AG_CONN TIMEOUT so that AG connection go through
105   INTEROP_INCREASE_AG_CONN_TIMEOUT,
106 
107   // Some HOGP devices do not respond well when we switch from default LE conn
108   // parameters to preferred conn params immediately post connection. Disable
109   // automatic switching to preferred conn params for such devices and allow
110   // them to explicitly ask for it.
111   INTEROP_DISABLE_LE_CONN_PREFERRED_PARAMS,
112 
113   // certain remote A2DP sinks have issue playing back Music in AAC format.
114   // disable AAC for those headsets so that it switch to SBC
115   INTEROP_DISABLE_AAC_CODEC,
116 
117   // certain remote A2DP sinks have issue playing back Music in AAC VBR format.
118   // disable AAC for those headsets so that it switch to AAC CBR
119   INTEROP_DISABLE_AAC_VBR_CODEC,
120 
121   // Enable AAC only for allowlist of devices
122   INTEROP_ENABLE_AAC_CODEC,
123 
124   // Disable role switch for headsets/car-kits
125   // Some car kits initiate a role switch but won't initiate encryption
126   // after role switch complete
127   INTEROP_DISABLE_ROLE_SWITCH_POLICY,
128 
129   INTEROP_HFP_1_7_DENYLIST,
130 
131   INTEROP_HFP_1_8_DENYLIST,
132 
133   // Devices requiring this workaround do not handle Bluetooth PBAP 1.2 version
134   // correctly, leading them to go in bad state. So for better interoperability
135   // respond with PBAP 1.1 as supported version.
136   INTEROP_ADV_PBAP_VER_1_1,
137 
138   // Devices requiring this workaround do not handle SSR max latency values as
139   // mentioned, in their SDP HID Record properly and lead to connection timeout
140   // or lags. To prevent such scenarios, device requiring this workaorund need
141   // to use specific ssr max latency values.
142   INTEROP_UPDATE_HID_SSR_MAX_LAT,
143 
144   // Some HID pointing devices have proven problematic behaviour if pairing is
145   // initiated with them, resulting in no response for authentication request
146   // and ultimately resulting in connection failure. To avoid degrading the user
147   // experience with those devices, authentication request is not requested
148   // explicitly.
149   INTEROP_DISABLE_AUTH_FOR_HID_POINTING,
150 
151   // Do not use AVDTP RECONFIGURE when reconfiguring A2DP streams.
152   // Some A2DP Sink devices report SUCCESS to the AVDTP RECONFIGURE command,
153   // but fail to play the reconfigured audio stream.
154   INTEROP_DISABLE_AVDTP_RECONFIGURE,
155 
156   // Create dynamic rejectlist to disable role switch.
157   // Some car kits indicate that role switch is supported, but then reject
158   // role switch attempts. After rejecting several role switch attempts,
159   // such car kits will go into bad state.
160   INTEROP_DYNAMIC_ROLE_SWITCH,
161 
162   // Few carkit hfp version is hfp1.5 but it support hfp indicator, violate spec
163   // remove hfp indicator for such device
164   INTEROP_DISABLE_HF_INDICATOR,
165 
166   // Disable role switch for headsets/car-kits.
167   // Some car kits allow role switch but when the Phone initiates role switch,
168   // the Remote device will go into bad state that will lead to LMP time out.
169   INTEROP_DISABLE_ROLE_SWITCH,
170 
171   // Some remotes are very strict in receiving the call active
172   // indicator and SCO connection request order for MT call.
173   // If CIEV1,1 and SCO connection request are sent back to back
174   // to SOC, it may send SCO connection request first then CIEV1,1
175   // which may lead to remotes not rendering SCO audio.
176   INTEROP_DELAY_SCO_FOR_MT_CALL,
177 
178   // Some remotes are taking too long to respond for codec negotiation.
179   // Disable codec negotiation for such remotes and directly initiate
180   // SCO Connection.
181   INTEROP_DISABLE_CODEC_NEGOTIATION,
182 
183   // Some Carkits being AVRCP v1.3 upon receiving Play Application Setting
184   // Command Response and notification, doesn't send Passthrough commands back
185   // to DUT in Streaming State
186   INTEROP_DISABLE_PLAYER_APPLICATION_SETTING_CMDS,
187 
188   // Disable profile connection for headsets/car-kits
189   // Some car kits going bad state when DUT initiate profile connection in
190   // collision scenario Hence don't initaite profile level connections and wait
191   // for incoming connetcion
192   INTEROP_DISABLE_CONNECTION_AFTER_COLLISION,
193 
194   // Some LE devices have proven problematic behaviour if LE connection update
195   // is initiated with them, resulting in no response after initiating LE
196   // connection update and ultimately resulting in connection timeout. To avoid
197   // degrading the user experience with those devices, LE connection update is
198   // not requested explicitly for those devices.
199   INTEROP_DISABLE_LE_CONN_UPDATES,
200 
201   // Devices requiring this workaround do not handle Bluetooth PBAP 1.1 version
202   // correctly, leading them to go in bad state. So for better interoperability
203   // respond with PBAP 1.2 as supported version.
204   INTEROP_ADV_PBAP_VER_1_2,
205 
206   // Disable profile PCE SDP request for headsets/car-kits
207   // Some car kits going bad state when DUT initiate PCE SDP request during
208   // BONDING time Hence don't send PCE SDP request for to prevent this abnormal
209   // behaviour.
210   INTEROP_DISABLE_PCE_SDP_AFTER_PAIRING,
211 
212   // Few remote sends avrcp browsing request just after host sends avrcp
213   // browsing request leading collision which results in browsing channel open
214   // failure. For such devices, collision timer is used avoid collision.
215   INTEROP_AVRCP_BROWSE_OPEN_CHANNEL_COLLISION,
216 
217   // Some remote devices don't support sniff mode when the SCO is connected.
218   // For such devices, disable sniff mode after SCO is connected and make
219   // the link as active.
220   INTEROP_DISABLE_SNIFF_LINK_DURING_SCO,
221 
222   // For some remote devicea, disable sniff mode during the call
223   INTEROP_DISABLE_SNIFF_DURING_CALL,
224 
225   // Set a very low initial sniff subrating for HID devices that do not
226   // set their own sniff interval.
227   INTEROP_HID_HOST_LIMIT_SNIFF_INTERVAL,
228 
229   // Disable refresh_accept_signalling_timer
230   INTEROP_DISABLE_REFRESH_ACCEPT_SIG_TIMER,
231 
232   // skip sending incoming state to denylisted devices
233   INTEROP_SKIP_INCOMING_STATE,
234 
235   // Don't update avrcp paused status to some certain remote devices when a2dp
236   // is still playing.
237   INTEROP_NOT_UPDATE_AVRCP_PAUSED_TO_REMOTE,
238 
239   // Some certain devices reject DUT initiated connection
240   // when DUT tries to connect other auto-connectable profiles 6s after
241   // peer connects the first one. To avoid such race condition, raised
242   // connect other profiles timeout to 10s to make sure there is no
243   // connection rejection from remote because of connection collision.
244   INTEROP_PHONE_POLICY_INCREASED_DELAY_CONNECT_OTHER_PROFILES,
245 
246   // Disable remote name request for some devices.
247   // The public address of these devices are same as the Random address in ADV.
248   // Then will get name by LE_Create_connection, actually fails,
249   // but will block pairing.
250   INTEROP_DISABLE_NAME_REQUEST,
251 
252   // Respond AVRCP profile version only 1.4 for some device.
253   INTEROP_AVRCP_1_4_ONLY,
254 
255   // Disable sniff mode for headsets/car-kits
256   // Some car kits supports sniff mode but when DUT initiates sniff req
257   // Remote will go to bad state and its leads to LMP time out.
258   INTEROP_DISABLE_SNIFF,
259 
260   // Do not send AVDTP SUSPEND while the playback is paused.
261   // Some older A2DP Sink devices might not support to pause the streaming.
262   INTEROP_DISABLE_AVDTP_SUSPEND,
263 
264   // Some car kits do not send the AT+BIND command while establishing the SLC
265   // which causes an HFP profile connection failure
266   INTEROP_SLC_SKIP_BIND_COMMAND,
267 
268   // Few remote devices do not understand AVRCP version greater than 1.3. For
269   // these devices, we would like to denylist them and advertise AVRCP version
270   // as 1.3
271   INTEROP_AVRCP_1_3_ONLY,
272 
273   // As per the implementation for the incoming connection scenario if one
274   // profile got connected and other profile didn't get connected, DUT starts
275   // connect other profiles after 6sec timeout. For some certain device,
276   // this timeout has been reduced to 2sec for triggering auto connect to
277   // otherprofiles from DUT. So that Audio will get routed to BT device with
278   // reduced delay.
279   INTEROP_PHONE_POLICY_REDUCED_DELAY_CONNECT_OTHER_PROFILES,
280 
281   // Some remote devices are misbehaving when there is an active
282   // call and MT call is in progress. We send call indicators for
283   // active call and MT Call in progess. When active call is
284   // terminated, we send call end indicator only to remote. This
285   // is confusing remote and remotes are going into bad state.
286   // Denylist remote devices to disconnect SCO when active call is
287   // ended, fake MT call indicator again with some delay.
288   INTEROP_HFP_FAKE_INCOMING_CALL_INDICATOR,
289 
290   // Some certain devices not rendering VOIP call audio if call indicators
291   // are sent with a delay. Denylist the devices to send call
292   // indicators back to back.
293   INTEROP_HFP_SEND_CALL_INDICATORS_BACK_TO_BACK,
294 
295   // Some remotes need SCO immediately after SLC if there is an ongoing
296   // call on the phone
297   INTEROP_SETUP_SCO_WITH_NO_DELAY_AFTER_SLC_DURING_CALL,
298 
299   // Some LE mouses want to use preferred connection parameters
300   INTEROP_ENABLE_PREFERRED_CONN_PARAMETER,
301 
302   // Some remotes drop SCO connection immediately after accept it,
303   // Retry setup SCO once for those remote devices.
304   INTEROP_RETRY_SCO_AFTER_REMOTE_REJECT_SCO,
305 
306   // some remoted need a delay after outgoing call indicators
307   // are sent before sco is opened
308   INTEROP_DELAY_SCO_FOR_MO_CALL,
309 
310   // Some remote hid devices cannot work properly as they load special hid usb
311   // driver in kernel, so modify their vid/pid so that generic hid driver are
312   // loaded.
313   INTEROP_CHANGE_HID_VID_PID,
314 
315   // Some remote always set DUT in peripheral role during connection which
316   // restricts setting supervision timeout to required value. This interop will
317   // allow local device to be only central as role switch would be restricted
318   // during connection.
319   INTEROP_DISABLE_ROLE_SWITCH_DURING_CONNECTION,
320 
321   // Some remote devices have LMP version in[5.0, 5.2] but do not support robust
322   // caching or correctly response with an error. We disable the database hash
323   // lookup for such devices.
324   INTEROP_DISABLE_ROBUST_CACHING,
325 
326   INTEROP_HFP_1_7_ALLOWLIST,
327 
328   INTEROP_HFP_1_9_ALLOWLIST,
329 
330   // Some device may have problem in reconnect flow,
331   // need we initiate connection after signalling timeout
332   INTEROP_IGNORE_DISC_BEFORE_SIGNALLING_TIMEOUT,
333 
334   // Certain devices have issue where they cannot handle ATT traffic during SMP
335   // key exchange. For those devices, queued ATT writes are delayed until after
336   // both encryption complete and SMP key exchange completed.
337   INTEROP_SUSPEND_ATT_TRAFFIC_DURING_PAIRING,
338 
339   // This triggers a +CIEV command to set the call status for HFP devices.
340   // It is required for some devices to provide sound.
341   INTEROP_INSERT_CALL_WHEN_SCO_START,
342 
343   // Some device need the host to delay authentication process to avoid
344   // collision.
345   INTEROP_DELAY_AUTH,
346 
347   // Some LE HID devices contain more than one HOGP service.
348   INTEROP_MULTIPLE_HOGP_SERVICE_CHOOSE_THIRD,
349 
350   // Som A2DP sink devices don't respond SDP request during A2DP reconnection
351   INTEROP_A2DP_SKIP_SDP_DURING_RECONNECTION,
352 
353   // Some devices response slowly after setting non zero latency.
354   // To avoid slowing down profile connection set latency to 0.
355   // Peer can request proper latency based on its power state later.
356   INTEROP_HID_PREF_CONN_ZERO_LATENCY,
357 
358   // Some HOGP devices have the report map longer than the maximum GATT attribute value length (512
359   // bytes).
360   INTEROP_HOGP_LONG_REPORT,
361 
362   // Some HOGP devices requires MTU exchange be part of the initial setup to function.
363   INTEROP_HOGP_FORCE_MTU_EXCHANGE,
364 
365   END_OF_INTEROP_LIST
366 } interop_feature_t;
367 
368 // Check if a given |addr| matches a known interoperability workaround as
369 // identified by the |interop_feature_t| enum. This API is used for simple
370 // address based lookups where more information is not available. No
371 // look-ups or random address resolution are performed on |addr|.
372 bool interop_match_addr(const interop_feature_t feature, const RawAddress* addr);
373 
374 // Check if a given remote device |name| matches a known workaround.
375 // Name comparisons are case sensitive and do not allow for partial matches.
376 // If |name| is "TEST" and a workaround exists for "TESTING", then this function
377 // will return false. But, if |name| is "TESTING" and a workaround exists for
378 // "TEST", this function will return true.
379 // |name| cannot be null and must be null terminated.
380 bool interop_match_name(const interop_feature_t feature, const char* name);
381 
382 // This api will lookup remote name with |addr| by btif_storage api internally.
383 // Then if either interop_match_addr or interop_match_name is matched, this
384 // function will return true.
385 bool interop_match_addr_or_name(const interop_feature_t feature, const RawAddress* addr,
386                                 bt_status_t (*get_remote_device_property)(const RawAddress*,
387                                                                           bt_property_t*));
388 
389 // Check if a given |manufacturer| matches a known interoperability workaround
390 // as identified by the |interop_feature_t| enum. This API is used for
391 // manufacturer based lookups where more information is not available.
392 bool interop_match_manufacturer(const interop_feature_t feature, uint16_t manufacturer);
393 
394 // Check if a given |vendor_id, |product_id| matches a known
395 // interoperability workaround as identified by the |interop_feature_t|
396 // enum. This API is used for simple name based lookups where more information
397 // is not available.
398 bool interop_match_vendor_product_ids(const interop_feature_t feature, uint16_t vendor_id,
399                                       uint16_t product_id);
400 
401 // Add a dynamic interop database entry for a device matching the first |length|
402 // bytes of |addr|, implementing the workaround identified by |feature|.
403 // |addr| may not be null.
404 // |length| must be greater than 0 and less than RawAddress::kLength.
405 // As |interop_feature_t| is not exposed in the public API, feature must be a
406 // valid integer representing an option in the enum.
407 void interop_database_add(const uint16_t feature, const RawAddress* addr, size_t length);
408 
409 // Clear the dynamic portion of the interoperability workaround database.
410 void interop_database_clear(void);
411 
412 // check if device version is matching with the interop database
413 bool interop_database_match_version(const interop_feature_t feature, uint16_t version);
414 // Check if a given |addr| matches a known interoperability workaround as
415 // identified by the |interop_feature_t| enum. This API is used for simple
416 // address based lookups where more information is not available. No look-ups or
417 // random address resolution are performed on |addr|. If address is matched, max
418 // latency for SSR stored for particular remote device is returned.
419 bool interop_match_addr_get_max_lat(const interop_feature_t feature, const RawAddress* addr,
420                                     uint16_t* max_lat);
421 
422 // Return feature's enum value according to feature'name.
423 int interop_feature_name_to_feature_id(const char* feature_name);
424