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 Set up HSP HS. 59 * @param rfcomm_channel_nr 60 */ 61 void hsp_hs_init(uint8_t rfcomm_channel_nr); 62 63 /** 64 * @brief Create HSP Headset (HS) SDP service record. 65 * @param service Empty buffer in which a new service record will be stored. 66 * @param rfcomm_channel_nr 67 * @param name 68 * @param have_remote_audio_control 69 */ 70 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); 71 72 /** 73 * @brief Register packet handler to receive HSP HS events. 74 * 75 * The HSP HS 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_RING 81 * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED 82 * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED 83 * - HSP_SUBEVENT_AG_INDICATION 84 * 85 * @param callback 86 */ 87 void hsp_hs_register_packet_handler(btstack_packet_handler_t callback); 88 89 /** 90 * @brief Connect to HSP Audio Gateway. 91 * 92 * Perform SDP query for an RFCOMM service on a remote device, 93 * and establish an RFCOMM connection if such service is found. Reception of the 94 * HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE with status 0 95 * indicates if the connection is successfully established. 96 * 97 * @param bd_addr 98 */ 99 void hsp_hs_connect(bd_addr_t bd_addr); 100 101 /** 102 * @brief Disconnect from HSP Audio Gateway 103 * 104 * Releases the RFCOMM channel. Reception of the 105 * HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE with status 0 106 * indicates if the connection is successfully released. 107 * @param bd_addr 108 */ 109 void hsp_hs_disconnect(void); 110 111 112 /** 113 * @brief Send button press action. Toggle establish/release of audio connection. 114 */ 115 void hsp_hs_send_button_press(void); 116 117 /** 118 * @brief Triger establishing audio connection. 119 * 120 * Reception of the HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE with status 0 121 * indicates if the audio connection is successfully established. 122 * @param bd_addr 123 */ 124 void hsp_hs_establish_audio_connection(void); 125 126 /** 127 * @brief Trigger releasing audio connection. 128 * 129 * Reception of the HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE with status 0 130 * indicates if the connection is successfully released. 131 * @param bd_addr 132 */ 133 void hsp_hs_release_audio_connection(void); 134 135 /** 136 * @brief Set microphone gain. 137 * 138 * The new gain value will be confirmed by the HSP Audio Gateway. 139 * A HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED event will be received. 140 * @param gain Valid range: [0,15] 141 */ 142 void hsp_hs_set_microphone_gain(uint8_t gain); 143 144 /** 145 * @brief Set speaker gain. 146 * 147 * The new gain value will be confirmed by the HSP Audio Gateway. 148 * A HSP_SUBEVENT_SPEAKER_GAIN_CHANGED event will be received. 149 * @param gain - valid range: [0,15] 150 */ 151 void hsp_hs_set_speaker_gain(uint8_t gain); 152 153 154 155 /** 156 * @brief Enable custom indications. 157 * 158 * Custom indications are disabled by default. 159 * When enabled, custom indications are received via the HSP_SUBEVENT_AG_INDICATION. 160 * @param enable 161 */ 162 void hsp_hs_enable_custom_indications(int enable); 163 164 /** 165 * @brief Send answer to custom indication. 166 * 167 * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond 168 * with this function with the result to the custom indication 169 * @param result 170 */ 171 int hsp_hs_send_result(const char * result); 172 173 /** 174 * @brief Set packet types used for incoming SCO connection requests 175 * @param common single packet_types: SCO_PACKET_TYPES_* 176 */ 177 void hsp_hs_set_sco_packet_types(uint16_t packet_types); 178 179 /** 180 * @brief De-Init HSP AG 181 */ 182 void hsp_hs_deinit(void); 183 184 /* API_END */ 185 186 #if defined __cplusplus 187 } 188 #endif 189 190 #endif 191