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