xref: /btstack/src/classic/hsp_hs.h (revision df25739fc3ea5a0a90f0f5925e6461d653697d2e)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 // *****************************************************************************
39 //
40 // HSP Headset
41 //
42 // *****************************************************************************
43 
44 
45 #ifndef btstack_hsp_hs_h
46 #define btstack_hsp_hs_h
47 
48 #include "hci.h"
49 #include "classic/sdp_client_rfcomm.h"
50 
51 #if defined __cplusplus
52 extern "C" {
53 #endif
54 
55 /* API_START */
56 
57 /**
58  * @brief Packet handler for HSP Headset (HS) events.
59  *
60  * The HSP HS event has type HCI_EVENT_HSP_META with following subtypes:
61  * - HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE
62  * - HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE
63  * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE
64  * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
65  * - HSP_SUBEVENT_RING
66  * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED
67  * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED
68  * - HSP_SUBEVENT_AG_INDICATION
69  *
70  * @param event See include/btstack/hci_cmds.h
71  * @param event_size
72  */
73 typedef void (*hsp_hs_callback_t)(uint8_t * event, uint16_t event_size);
74 
75 /**
76  * @brief Set up HSP HS.
77  * @param rfcomm_channel_nr
78  */
79 void hsp_hs_init(uint8_t rfcomm_channel_nr);
80 
81 /**
82  * @brief Create HSP Headset (HS) SDP service record.
83  * @param service Empty buffer in which a new service record will be stored.
84  * @param rfcomm_channel_nr
85  * @param name
86  * @param have_remote_audio_control
87  */
88 void hsp_hs_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name, uint8_t have_remote_audio_control);
89 
90 /**
91  * @brief Register packet handler to receive HSP HS events.
92  * @param callback
93  */
94 void hsp_hs_register_packet_handler(hsp_hs_callback_t callback);
95 
96 /**
97  * @brief Connect to HSP Audio Gateway.
98  *
99  * Perform SDP query for an RFCOMM service on a remote device,
100  * and establish an RFCOMM connection if such service is found. Reception of the
101  * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0
102  * indicates if the connection is successfully established.
103  *
104  * @param bd_addr
105  */
106 void hsp_hs_connect(bd_addr_t bd_addr);
107 
108 /**
109  * @brief Disconnect from HSP Audio Gateway
110  *
111  * Releases the RFCOMM channel. Reception of the
112  * HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0
113  * indicates if the connection is successfully released.
114  * @param bd_addr
115  */
116 void hsp_hs_disconnect(void);
117 
118 
119 /**
120  * @brief Send button press action. Toggle establish/release of audio connection.
121  */
122 void hsp_hs_send_button_press(void);
123 
124 /**
125  * @brief Triger establishing audio connection.
126  *
127  * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0
128  * indicates if the audio connection is successfully established.
129  * @param bd_addr
130  */
131 void hsp_hs_establish_audio_connection(void);
132 
133 /**
134  * @brief Trigger releasing audio connection.
135  *
136  * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0
137  * indicates if the connection is successfully released.
138  * @param bd_addr
139  */
140 void hsp_hs_release_audio_connection(void);
141 
142 /**
143  * @brief Set microphone gain.
144  *
145  * The new gain value will be confirmed by the HSP Audio Gateway.
146  * A HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED event will be received.
147  * @param gain Valid range: [0,15]
148  */
149 void hsp_hs_set_microphone_gain(uint8_t gain);
150 
151 /**
152  * @brief Set speaker gain.
153  *
154  * The new gain value will be confirmed by the HSP Audio Gateway.
155  * A HSP_SUBEVENT_SPEAKER_GAIN_CHANGED event will be received.
156  * @param gain - valid range: [0,15]
157  */
158 void hsp_hs_set_speaker_gain(uint8_t gain);
159 
160 
161 
162 /**
163  * @brief Enable custom indications.
164  *
165  * Custom indications are disabled by default.
166  * When enabled, custom indications are received via the HSP_SUBEVENT_AG_INDICATION.
167  * @param enable
168  */
169 void hsp_hs_enable_custom_indications(int enable);
170 
171 /**
172  * @brief Send answer to custom indication.
173  *
174  * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
175  * with this function with the result to the custom indication
176  * @param result
177  */
178 int hsp_hs_send_result(const char * result);
179 
180 /* API_END */
181 
182 #if defined __cplusplus
183 }
184 #endif
185 
186 #endif