xref: /btstack/src/classic/hsp_ag.h (revision efda0b48f920fa795cb4c2d0cf0c4acf184fb858)
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 Packet handler for HSP Audio Gateway (AG) events.
59  *
60  * The HSP AG 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_MICROPHONE_GAIN_CHANGED
64  * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED
65  * - HSP_SUBEVENT_HS_COMMAND
66  *
67  * @param event See include/btstack/hci_cmds.h
68  * @param event_size
69  */
70 typedef void (*hsp_ag_callback_t)(uint8_t * event, uint16_t event_size);
71 
72 /**
73  * @brief Set up HSP AG.
74  * @param rfcomm_channel_nr
75  */
76 void hsp_ag_init(uint8_t rfcomm_channel_nr);
77 
78 /**
79  * @brief Create HSP Audio Gateway (AG) SDP service record.
80  * @param service Empty buffer in which a new service record will be stored.
81  * @param service_record_handle
82  * @param rfcomm_channel_nr
83  * @param name
84  */
85 void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name);
86 
87 /**
88  * @brief Register packet handler to receive HSP AG events.
89  * @param callback
90  */
91 void hsp_ag_register_packet_handler(hsp_ag_callback_t callback);
92 
93 /**
94  * @brief Connect to HSP Headset
95  *
96  * Perform SDP query for an RFCOMM service on a remote device,
97  * and establish an RFCOMM connection if such service is found. The reception of the
98  * HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE or
99  * HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE event
100  * indicate if the connection is successfully established or not.
101  *
102  * @param bd_addr
103  */
104 void hsp_ag_connect(bd_addr_t bd_addr);
105 
106 /**
107  * @brief Disconnect from HSP Headset.
108  *
109  * Releases the RFCOMM channel.
110  * @param bd_addr
111  */
112 void hsp_ag_disconnect(void);
113 
114 /**
115  * @brief Set microphone gain.
116  * @param gain Valid range: [0,15]
117  */
118 void hsp_ag_set_microphone_gain(uint8_t gain);
119 
120 /**
121  * @brief Set speaker gain.
122  * @param gain Valid range: [0,15]
123  */
124 void hsp_ag_set_speaker_gain(uint8_t gain);
125 
126 /**
127  * @brief Start ringing because of incoming call.
128  */
129 void hsp_ag_start_ringing(void);
130 
131 /**
132  * @brief Stop ringing (e.g. call was terminated).
133  */
134 void hsp_ag_stop_ringing(void);
135 
136 /**
137  * @brief Enable custom AT commands.
138  *
139  * Custom commands are disabled by default.
140  * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND.
141  * @param enable
142  */
143 void hsp_ag_enable_custom_commands(int enable);
144 
145 /**
146  * @brief Send a custom AT command to HSP Headset.
147  *
148  * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
149  * with this function with the result to the custom command.
150  * @param result
151  */
152 int hsp_ag_send_result(char * result);
153 
154 /* API_END */
155 
156 #if defined __cplusplus
157 }
158 #endif
159 
160 #endif