xref: /btstack/src/classic/hsp_hs.h (revision eda0480f018f79db7599dc8db1ce251f24acf9dd)
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_query_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_AUDIO_CONNECTION_COMPLETE
62  * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
63  * - HSP_SUBEVENT_RING
64  * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED
65  * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED
66  * - HSP_SUBEVENT_AG_INDICATION
67  *
68  * @param event See include/btstack/hci_cmds.h
69  * @param event_size
70  */
71 typedef void (*hsp_hs_callback_t)(uint8_t * event, uint16_t event_size);
72 
73 /**
74  * @brief Set up HSP HS.
75  * @param rfcomm_channel_nr
76  */
77 void hsp_hs_init(uint8_t rfcomm_channel_nr);
78 
79 /**
80  * @brief Create HSP Headset (HS) SDP service record.
81  * @param service Empty buffer in which a new service record will be stored.
82  * @param rfcomm_channel_nr
83  * @param name
84  * @param have_remote_audio_control
85  */
86 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);
87 
88 /**
89  * @brief Register packet handler to receive HSP HS events.
90  * @param callback
91  */
92 void hsp_hs_register_packet_handler(hsp_hs_callback_t callback);
93 
94 /**
95  * @brief Connect to HSP Audio Gateway.
96  *
97  * Perform SDP query for an RFCOMM service on a remote device,
98  * and establish an RFCOMM connection if such service is found. The reception of the
99  * HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE or
100  * HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE event
101  * indicate if the connection is successfully established or not.
102  *
103  * @param bd_addr
104  */
105 void hsp_hs_connect(bd_addr_t bd_addr);
106 
107 /**
108  * @brief Disconnect from HSP Audio Gateway
109  *
110  * Releases the RFCOMM channel.
111  * @param bd_addr
112  */
113 void hsp_hs_disconnect(bd_addr_t bd_addr);
114 
115 /**
116  * @brief Set microphone gain.
117  *
118  * The new gain value will be confirmed by the HSP Audio Gateway.
119  * A HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED event will be received.
120  * @param gain Valid range: [0,15]
121  */
122 void hsp_hs_set_microphone_gain(uint8_t gain);
123 
124 /**
125  * @brief Set speaker gain.
126  *
127  * The new gain value will be confirmed by the HSP Audio Gateway.
128  * A HSP_SUBEVENT_SPEAKER_GAIN_CHANGED event will be received.
129  * @param gain - valid range: [0,15]
130  */
131 void hsp_hs_set_speaker_gain(uint8_t gain);
132 
133 /**
134  * @brief Send button press action.
135  * @param gain Valid range: [0,15]
136  */
137 void hsp_hs_send_button_press(void);
138 
139 /**
140  * @brief Enable custom indications.
141  *
142  * Custom indications are disabled by default.
143  * When enabled, custom indications are received via the HSP_SUBEVENT_AG_INDICATION.
144  * @param enable
145  */
146 void hsp_hs_enable_custom_indications(int enable);
147 
148 /**
149  * @brief Send answer to custom indication.
150  *
151  * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
152  * with this function with the result to the custom indication
153  * @param result
154  */
155 int hsp_hs_send_result(const char * result);
156 
157 /* API_END */
158 
159 #if defined __cplusplus
160 }
161 #endif
162 
163 #endif