1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef CRAS_HFP_SLC_H_
7 #define CRAS_HFP_SLC_H_
8 
9 struct hfp_slc_handle;
10 struct cras_bt_device;
11 
12 /*
13  * Hands-free HFP and AG supported features bits definition.
14  * Per HFP 1.7.1 specification section 4.34.1, command
15  * AT+BRSF (Bluetooth Retrieve Supported Features)
16  */
17 #define HF_EC_ANDOR_NR 0x0001
18 #define HF_THREE_WAY_CALLING 0x0002
19 #define HF_CLI_PRESENTATION_CAP 0x0004
20 #define HF_VOICE_RECOGNITION 0x0008
21 #define HF_REMOTE_VOLUME_CONTROL 0x0010
22 #define HF_ENHANCED_CALL_STATUS 0x0020
23 #define HF_ENHANCED_CALL_CONTROL 0x0040
24 #define HF_CODEC_NEGOTIATION 0x0080
25 #define HF_HF_INDICATORS 0x0100
26 #define HF_ESCO_S4_T2_SETTINGS 0x0200
27 
28 #define AG_THREE_WAY_CALLING 0x0001
29 #define AG_EC_ANDOR_NR 0x0002
30 #define AG_VOICE_RECOGNITION 0x0004
31 #define AG_INBAND_RINGTONE 0x0008
32 #define AG_ATTACH_NUMBER_TO_VOICETAG 0x0010
33 #define AG_REJECT_A_CALL 0x0020
34 #define AG_ENHANCED_CALL_STATUS 0x0040
35 #define AG_ENHANCED_CALL_CONTROL 0x0080
36 #define AG_EXTENDED_ERROR_RESULT_CODES 0x0100
37 #define AG_CODEC_NEGOTIATION 0x0200
38 #define AG_HF_INDICATORS 0x0400
39 #define AG_ESCO_S4_T2_SETTINGS 0x0800
40 
41 /*
42  * Apple specific bluetooth commands that extend accessory capabilities.
43  * Per Accessory Design Guidelines for Apple devices, command AT+XAPL
44  */
45 
46 #define APL_RESERVED 0x01
47 #define APL_BATTERY 0x02
48 #define APL_DOCKED_OR_POWERED 0x04
49 #define APL_SIRI 0x08
50 #define APL_NOISE_REDUCTION 0x10
51 
52 #define CRAS_APL_SUPPORTED_FEATURES (APL_BATTERY)
53 
54 /* Codec ids for codec negotiation, per HFP 1.7.1 spec appendix B. */
55 #define HFP_CODEC_UNUSED 0
56 #define HFP_CODEC_ID_CVSD 1
57 #define HFP_CODEC_ID_MSBC 2
58 #define HFP_MAX_CODECS 3
59 
60 /* Hands-free HFP supported battery indicator bit definition.
61  * This is currently only used for logging purpose. */
62 #define CRAS_HFP_BATTERY_INDICATOR_NONE 0x0
63 #define CRAS_HFP_BATTERY_INDICATOR_HFP 0x1
64 #define CRAS_HFP_BATTERY_INDICATOR_APPLE 0x2
65 #define CRAS_HFP_BATTERY_INDICATOR_PLANTRONICS 0x4
66 
67 /* Callback to call when service level connection initialized. */
68 typedef int (*hfp_slc_init_cb)(struct hfp_slc_handle *handle);
69 
70 /* Callback to call when service level connection disconnected. */
71 typedef int (*hfp_slc_disconnect_cb)(struct hfp_slc_handle *handle);
72 
73 /* Creates an hfp_slc_handle to poll the RFCOMM file descriptor
74  * to read and handle received AT commands.
75  * Args:
76  *    fd - the rfcomm fd used to initialize service level connection
77  *    is_hsp - if the slc handle is created for headset profile
78  *    ag_supported_features - Supported AG features bitmap.
79  *    device - The bt device associated with the created slc object
80  *    init_cb - the callback function to be triggered when a service level
81  *        connection is initialized.
82  *    disconnect_cb - the callback function to be triggered when the service
83  *        level connection is disconnected.
84  */
85 struct hfp_slc_handle *hfp_slc_create(int fd, int is_hsp,
86 				      int ag_supported_features,
87 				      struct cras_bt_device *device,
88 				      hfp_slc_init_cb init_cb,
89 				      hfp_slc_disconnect_cb disconnect_cb);
90 
91 /* Destroys an hfp_slc_handle. */
92 void hfp_slc_destroy(struct hfp_slc_handle *handle);
93 
94 /* Returns true if this SLC is created for headset profile(HSP), false
95  * means it's created for hands-free profile(HFP).
96  */
97 int hfp_slc_is_hsp(struct hfp_slc_handle *handle);
98 
99 /* Sets the call status to notify handsfree device. */
100 int hfp_set_call_status(struct hfp_slc_handle *handle, int call);
101 
102 /* Fakes the incoming call event for qualification test. */
103 int hfp_event_incoming_call(struct hfp_slc_handle *handle, const char *number,
104 			    int type);
105 
106 /* Handles the call status changed event.
107  * AG will send notification to HF accordingly. */
108 int hfp_event_update_call(struct hfp_slc_handle *handle);
109 
110 /* Handles the call setup status changed event.
111  * AG will send notification to HF accordingly. */
112 int hfp_event_update_callsetup(struct hfp_slc_handle *handle);
113 
114 /* Handles the call held status changed event.
115  * AG will send notification to HF accordingly. */
116 int hfp_event_update_callheld(struct hfp_slc_handle *handle);
117 
118 /* Sets battery level which is required for qualification test. */
119 int hfp_event_set_battery(struct hfp_slc_handle *handle, int value);
120 
121 /* Sets signal strength which is required for qualification test. */
122 int hfp_event_set_signal(struct hfp_slc_handle *handle, int value);
123 
124 /* Sets service availability which is required for qualification test. */
125 int hfp_event_set_service(struct hfp_slc_handle *handle, int value);
126 
127 /* Sets speaker gain value to headsfree device. */
128 int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain);
129 
130 /* Gets the selected codec for HFP, mSBC or CVSD. */
131 int hfp_slc_get_selected_codec(struct hfp_slc_handle *handle);
132 
133 /* Gets if the remote HF supports codec negotiation. */
134 int hfp_slc_get_hf_codec_negotiation_supported(struct hfp_slc_handle *handle);
135 
136 /* Gets if the remote HF supports HF indicator. */
137 int hfp_slc_get_hf_hf_indicators_supported(struct hfp_slc_handle *handle);
138 
139 /* Gets if the HF side supports wideband speech. */
140 bool hfp_slc_get_wideband_speech_supported(struct hfp_slc_handle *handle);
141 
142 /* Gets if the AG side supports codec negotiation. */
143 int hfp_slc_get_ag_codec_negotiation_supported(struct hfp_slc_handle *handle);
144 
145 /* Gets an enum representing which spec the HF supports battery indicator.
146  * Apple, HFP, none, or both. */
147 int hfp_slc_get_hf_supports_battery_indicator(struct hfp_slc_handle *handle);
148 
149 /* Init the codec negotiation process if needed. */
150 int hfp_slc_codec_connection_setup(struct hfp_slc_handle *handle);
151 
152 // Expose internal AT command handling for fuzzing.
153 int handle_at_command_for_test(struct hfp_slc_handle *slc_handle,
154 			       const char *cmd);
155 
156 #endif /* CRAS_HFP_SLC_H_ */
157