xref: /btstack/src/classic/hsp_ag.h (revision cd5f23a3250874824c01a2b3326a9522fea3f99f)
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 Audio Gateway
41 //
42 // *****************************************************************************
43 
44 
45 #ifndef btstack_hsp_ag_h
46 #define btstack_hsp_ag_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 Set up HSP AG.
59  * @param rfcomm_channel_nr
60  */
61 void hsp_ag_init(uint8_t rfcomm_channel_nr);
62 
63 /**
64  * @brief Create HSP Audio Gateway (AG) SDP service record.
65  * @param service Empty buffer in which a new service record will be stored.
66  * @param service_record_handle
67  * @param rfcomm_channel_nr
68  * @param name
69  */
70 void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name);
71 
72 /**
73  * @brief Register packet handler to receive HSP AG events.
74 
75  * The HSP AG event has type HCI_EVENT_HSP_META with following subtypes:
76  * - HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE
77  * - HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE
78  * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE
79  * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
80  * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED
81  * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED
82  * - HSP_SUBEVENT_HS_COMMAND
83  *
84  * @param callback
85  */
86 void hsp_ag_register_packet_handler(btstack_packet_handler_t callback);
87 
88 /**
89  * @brief Connect to HSP Headset.
90  *
91  * Perform SDP query for an RFCOMM service on a remote device,
92  * and establish an RFCOMM connection if such service is found. Reception of the
93  * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0
94  * indicates if the connection is successfully established.
95  *
96  * @param bd_addr
97  */
98 void hsp_ag_connect(bd_addr_t bd_addr);
99 
100 /**
101  * @brief Disconnect from HSP Headset
102  *
103  * Reception of the HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0
104  * indicates if the connection is successfully released.
105  * @param bd_addr
106  */
107 void hsp_ag_disconnect(void);
108 
109 
110 /**
111  * @brief Establish audio connection.
112  *
113  * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0
114  * indicates if the audio connection is successfully established.
115  * @param bd_addr
116  */
117 void hsp_ag_establish_audio_connection(void);
118 
119 /**
120  * @brief Release audio connection.
121  *
122  * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0
123  * indicates if the connection is successfully released.
124  * @param bd_addr
125  */
126 void hsp_ag_release_audio_connection(void);
127 
128 /**
129  * @brief Set microphone gain.
130  * @param gain Valid range: [0,15]
131  */
132 void hsp_ag_set_microphone_gain(uint8_t gain);
133 
134 /**
135  * @brief Set speaker gain.
136  * @param gain Valid range: [0,15]
137  */
138 void hsp_ag_set_speaker_gain(uint8_t gain);
139 
140 /**
141  * @brief Start ringing because of incoming call.
142  */
143 void hsp_ag_start_ringing(void);
144 
145 /**
146  * @brief Stop ringing (e.g. call was terminated).
147  */
148 void hsp_ag_stop_ringing(void);
149 
150 /**
151  * @brief Enable custom AT commands.
152  *
153  * Custom commands are disabled by default.
154  * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND.
155  * @param enable
156  */
157 void hsp_ag_enable_custom_commands(int enable);
158 
159 /**
160  * @brief Send a custom AT command to HSP Headset.
161  *
162  * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
163  * with this function with the result to the custom command.
164  * @param result
165  */
166 int hsp_ag_send_result(char * result);
167 
168 /**
169  * @brief Set packet types used for outgoing SCO connection requests
170  * @param common single packet_types: SCO_PACKET_TYPES_*
171  */
172 void hsp_ag_set_sco_packet_types(uint16_t packet_types);
173 
174 /**
175  * @brief De-Init HSP AG
176  */
177 void hsp_ag_deinit(void);
178 
179 /* API_END */
180 
181 #if defined __cplusplus
182 }
183 #endif
184 
185 #endif
186