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