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