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 <stdbool.h>
22 
23 #include "raw_address.h"
24 
25 static const char INTEROP_MODULE[] = "interop_module";
26 
27 // NOTE:
28 // Only add values at the end of this enum and do NOT delete values
29 // as they may be used in dynamic device configuration.
30 typedef enum {
31   // Disable secure connections
32   // This is for pre BT 4.1/2 devices that do not handle secure mode
33   // very well.
34   INTEROP_DISABLE_LE_SECURE_CONNECTIONS = 0,
35 
36   // Some devices have proven problematic during the pairing process, often
37   // requiring multiple retries to complete pairing. To avoid degrading the user
38   // experience for those devices, automatically re-try pairing if page
39   // timeouts are received during pairing.
40   INTEROP_AUTO_RETRY_PAIRING,
41 
42   // Devices requiring this workaround do not handle Bluetooth Absolute Volume
43   // control correctly, leading to undesirable (potentially harmful) volume
44   // levels or general lack of controlability.
45   INTEROP_DISABLE_ABSOLUTE_VOLUME,
46 
47   // Disable automatic pairing with headsets/car-kits
48   // Some car kits do not react kindly to a failed pairing attempt and
49   // do not allow immediate re-pairing. Rejectlist these so that the initial
50   // pairing attempt makes it to the user instead.
51   INTEROP_DISABLE_AUTO_PAIRING,
52 
53   // Use a fixed pin for specific keyboards
54   // Keyboards should use a variable pin at all times. However, some keyboards
55   // require a fixed pin of all 0000. This workaround enables auto pairing for
56   // those keyboards.
57   INTEROP_KEYBOARD_REQUIRES_FIXED_PIN,
58 
59   // Some headsets have audio jitter issues because of increased
60   // re-transmissions as the 3 Mbps packets have a lower link margin, and are
61   // more prone to interference. We can disable 3DH packets (use only 2DH
62   // packets) for the ACL link to improve sensitivity when streaming A2DP audio
63   // to the headset. Air sniffer logs show reduced re-transmissions after
64   // switching to 2DH packets.
65 
66   // Disable 3Mbps packets and use only 2Mbps packets for ACL links when
67   // streaming audio.
68   INTEROP_2MBPS_LINK_ONLY,
69 
70   // Do not use supervision timeout value received from preferred connection
71   // parameters, use 3s instead. Use with HID only.
72   INTEROP_HID_PREF_CONN_SUP_TIMEOUT_3S,
73 
74   // Do not send service changed indications (GATT client).
75   // This should be removed after the characteristic is implmeented b/62088395.
76   INTEROP_GATTC_NO_SERVICE_CHANGED_IND,
77 
78   // Do not use AVDTP RECONFIGURE when reconfiguring A2DP streams.
79   // Some A2DP Sink devices report SUCCESS to the AVDTP RECONFIGURE command,
80   // but fail to play the reconfigured audio stream.
81   INTEROP_DISABLE_AVDTP_RECONFIGURE,
82 
83   // Create dynamic rejectlist to disable role switch.
84   // Some car kits indicate that role switch is supported, but then reject
85   // role switch attempts. After rejecting several role switch attempts,
86   // such car kits will go into bad state.
87   INTEROP_DYNAMIC_ROLE_SWITCH,
88 
89   // Disable role switch for headsets/car-kits.
90   // Some car kits allow role switch but when the Phone initiates role switch,
91   // the Remote device will go into bad state that will lead to LMP time out.
92   INTEROP_DISABLE_ROLE_SWITCH,
93 
94   // Set a very low initial sniff subrating for HID devices that do not
95   // set their own sniff interval.
96   INTEROP_HID_HOST_LIMIT_SNIFF_INTERVAL,
97 
98   // Disable remote name requst for some devices.
99   // The public address of these devices are same as the Random address in ADV.
100   // Then will get name by LE_Create_connection, actually fails,
101   // but will block pairing.
102   INTEROP_DISABLE_NAME_REQUEST,
103 
104   // Respond AVRCP profile version only 1.4 for some device.
105   INTEROP_AVRCP_1_4_ONLY,
106 
107   // Disable sniff mode for headsets/car-kits
108   // Some car kits supports sniff mode but when DUT initiates sniff req
109   // Remote will go to bad state and its leads to LMP time out.
110   INTEROP_DISABLE_SNIFF,
111 
112   // Do not send AVDTP SUSPEND while the playback is paused.
113   // Some older A2DP Sink devices might not support to pause the streaming.
114   INTEROP_DISABLE_AVDTP_SUSPEND,
115 
116   // Some car kits do not send the AT+BIND command while establishing the SLC
117   // which causes an HFP profile connection failure
118   INTEROP_SLC_SKIP_BIND_COMMAND
119 } interop_feature_t;
120 
121 // Check if a given |addr| matches a known interoperability workaround as
122 // identified by the |interop_feature_t| enum. This API is used for simple
123 // address based lookups where more information is not available. No
124 // look-ups or random address resolution are performed on |addr|.
125 bool interop_match_addr(const interop_feature_t feature,
126                         const RawAddress* addr);
127 
128 // Check if a given remote device |name| matches a known workaround.
129 // Name comparisons are case sensitive and do not allow for partial matches.
130 // If |name| is "TEST" and a workaround exists for "TESTING", then this function
131 // will return false. But, if |name| is "TESTING" and a workaround exists for
132 // "TEST", this function will return true.
133 // |name| cannot be null and must be null terminated.
134 bool interop_match_name(const interop_feature_t feature, const char* name);
135 
136 // Add a dynamic interop database entry for a device matching the first |length|
137 // bytes of |addr|, implementing the workaround identified by |feature|.
138 // |addr| may not be null.
139 // |length| must be greater than 0 and less than RawAddress::kLength.
140 // As |interop_feature_t| is not exposed in the public API, feature must be a
141 // valid integer representing an option in the enum.
142 void interop_database_add(uint16_t feature, const RawAddress* addr,
143                           size_t length);
144 
145 // Clear the dynamic portion of the interoperability workaround database.
146 void interop_database_clear(void);
147