xref: /btstack/src/classic/hsp_ag.h (revision efda0b48f920fa795cb4c2d0cf0c4acf184fb858)
13deb3ec6SMatthias Ringwald /*
23deb3ec6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
33deb3ec6SMatthias Ringwald  *
43deb3ec6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53deb3ec6SMatthias Ringwald  * modification, are permitted provided that the following conditions
63deb3ec6SMatthias Ringwald  * are met:
73deb3ec6SMatthias Ringwald  *
83deb3ec6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103deb3ec6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123deb3ec6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133deb3ec6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143deb3ec6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153deb3ec6SMatthias Ringwald  *    from this software without specific prior written permission.
163deb3ec6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173deb3ec6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183deb3ec6SMatthias Ringwald  *    monetary gain.
193deb3ec6SMatthias Ringwald  *
203deb3ec6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213deb3ec6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223deb3ec6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
233deb3ec6SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
243deb3ec6SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253deb3ec6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263deb3ec6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273deb3ec6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283deb3ec6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293deb3ec6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303deb3ec6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313deb3ec6SMatthias Ringwald  * SUCH DAMAGE.
323deb3ec6SMatthias Ringwald  *
333deb3ec6SMatthias Ringwald  * Please inquire about commercial licensing options at
343deb3ec6SMatthias Ringwald  * [email protected]
353deb3ec6SMatthias Ringwald  *
363deb3ec6SMatthias Ringwald  */
373deb3ec6SMatthias Ringwald 
383deb3ec6SMatthias Ringwald // *****************************************************************************
393deb3ec6SMatthias Ringwald //
4066a048abSMatthias Ringwald // HSP Audio Gateway
413deb3ec6SMatthias Ringwald //
423deb3ec6SMatthias Ringwald // *****************************************************************************
433deb3ec6SMatthias Ringwald 
443deb3ec6SMatthias Ringwald 
453deb3ec6SMatthias Ringwald #ifndef btstack_hsp_ag_h
463deb3ec6SMatthias Ringwald #define btstack_hsp_ag_h
473deb3ec6SMatthias Ringwald 
483deb3ec6SMatthias Ringwald #include "hci.h"
49*efda0b48SMatthias Ringwald #include "classic/sdp_client_rfcomm.h"
503deb3ec6SMatthias Ringwald 
513deb3ec6SMatthias Ringwald #if defined __cplusplus
523deb3ec6SMatthias Ringwald extern "C" {
533deb3ec6SMatthias Ringwald #endif
543deb3ec6SMatthias Ringwald 
55eda0480fSMatthias Ringwald /* API_START */
56eda0480fSMatthias Ringwald 
57eda0480fSMatthias Ringwald /**
58eda0480fSMatthias Ringwald  * @brief Packet handler for HSP Audio Gateway (AG) events.
59eda0480fSMatthias Ringwald  *
60eda0480fSMatthias Ringwald  * The HSP AG event has type HCI_EVENT_HSP_META with following subtypes:
61eda0480fSMatthias Ringwald  * - HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE
62eda0480fSMatthias Ringwald  * - HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE
63eda0480fSMatthias Ringwald  * - HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED
64eda0480fSMatthias Ringwald  * - HSP_SUBEVENT_SPEAKER_GAIN_CHANGED
65eda0480fSMatthias Ringwald  * - HSP_SUBEVENT_HS_COMMAND
66eda0480fSMatthias Ringwald  *
67eda0480fSMatthias Ringwald  * @param event See include/btstack/hci_cmds.h
68eda0480fSMatthias Ringwald  * @param event_size
69eda0480fSMatthias Ringwald  */
703deb3ec6SMatthias Ringwald typedef void (*hsp_ag_callback_t)(uint8_t * event, uint16_t event_size);
7166a048abSMatthias Ringwald 
72eda0480fSMatthias Ringwald /**
73eda0480fSMatthias Ringwald  * @brief Set up HSP AG.
74eda0480fSMatthias Ringwald  * @param rfcomm_channel_nr
75eda0480fSMatthias Ringwald  */
763deb3ec6SMatthias Ringwald void hsp_ag_init(uint8_t rfcomm_channel_nr);
7766a048abSMatthias Ringwald 
78eda0480fSMatthias Ringwald /**
79eda0480fSMatthias Ringwald  * @brief Create HSP Audio Gateway (AG) SDP service record.
80eda0480fSMatthias Ringwald  * @param service Empty buffer in which a new service record will be stored.
81eda0480fSMatthias Ringwald  * @param service_record_handle
82eda0480fSMatthias Ringwald  * @param rfcomm_channel_nr
83eda0480fSMatthias Ringwald  * @param name
84eda0480fSMatthias Ringwald  */
85eda0480fSMatthias Ringwald void hsp_ag_create_sdp_record(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name);
86eda0480fSMatthias Ringwald 
87eda0480fSMatthias Ringwald /**
88eda0480fSMatthias Ringwald  * @brief Register packet handler to receive HSP AG events.
89eda0480fSMatthias Ringwald  * @param callback
90eda0480fSMatthias Ringwald  */
9166a048abSMatthias Ringwald void hsp_ag_register_packet_handler(hsp_ag_callback_t callback);
9266a048abSMatthias Ringwald 
93eda0480fSMatthias Ringwald /**
94eda0480fSMatthias Ringwald  * @brief Connect to HSP Headset
95eda0480fSMatthias Ringwald  *
96eda0480fSMatthias Ringwald  * Perform SDP query for an RFCOMM service on a remote device,
97eda0480fSMatthias Ringwald  * and establish an RFCOMM connection if such service is found. The reception of the
98eda0480fSMatthias Ringwald  * HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE or
99eda0480fSMatthias Ringwald  * HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE event
100eda0480fSMatthias Ringwald  * indicate if the connection is successfully established or not.
101eda0480fSMatthias Ringwald  *
102eda0480fSMatthias Ringwald  * @param bd_addr
103eda0480fSMatthias Ringwald  */
1043deb3ec6SMatthias Ringwald void hsp_ag_connect(bd_addr_t bd_addr);
10566a048abSMatthias Ringwald 
106eda0480fSMatthias Ringwald /**
107eda0480fSMatthias Ringwald  * @brief Disconnect from HSP Headset.
108eda0480fSMatthias Ringwald  *
109eda0480fSMatthias Ringwald  * Releases the RFCOMM channel.
110eda0480fSMatthias Ringwald  * @param bd_addr
111eda0480fSMatthias Ringwald  */
1123deb3ec6SMatthias Ringwald void hsp_ag_disconnect(void);
1133deb3ec6SMatthias Ringwald 
114eda0480fSMatthias Ringwald /**
115eda0480fSMatthias Ringwald  * @brief Set microphone gain.
116eda0480fSMatthias Ringwald  * @param gain Valid range: [0,15]
117eda0480fSMatthias Ringwald  */
1183deb3ec6SMatthias Ringwald void hsp_ag_set_microphone_gain(uint8_t gain);
11966a048abSMatthias Ringwald 
120eda0480fSMatthias Ringwald /**
121eda0480fSMatthias Ringwald  * @brief Set speaker gain.
122eda0480fSMatthias Ringwald  * @param gain Valid range: [0,15]
123eda0480fSMatthias Ringwald  */
1243deb3ec6SMatthias Ringwald void hsp_ag_set_speaker_gain(uint8_t gain);
1253deb3ec6SMatthias Ringwald 
126eda0480fSMatthias Ringwald /**
127eda0480fSMatthias Ringwald  * @brief Start ringing because of incoming call.
128eda0480fSMatthias Ringwald  */
1293deb3ec6SMatthias Ringwald void hsp_ag_start_ringing(void);
13066a048abSMatthias Ringwald 
131eda0480fSMatthias Ringwald /**
132eda0480fSMatthias Ringwald  * @brief Stop ringing (e.g. call was terminated).
133eda0480fSMatthias Ringwald  */
1343deb3ec6SMatthias Ringwald void hsp_ag_stop_ringing(void);
1353deb3ec6SMatthias Ringwald 
136eda0480fSMatthias Ringwald /**
137eda0480fSMatthias Ringwald  * @brief Enable custom AT commands.
138eda0480fSMatthias Ringwald  *
139eda0480fSMatthias Ringwald  * Custom commands are disabled by default.
140eda0480fSMatthias Ringwald  * When enabled, custom AT commands are received via the HSP_SUBEVENT_HS_COMMAND.
141eda0480fSMatthias Ringwald  * @param enable
142eda0480fSMatthias Ringwald  */
14366a048abSMatthias Ringwald void hsp_ag_enable_custom_commands(int enable);
14466a048abSMatthias Ringwald 
145eda0480fSMatthias Ringwald /**
146eda0480fSMatthias Ringwald  * @brief Send a custom AT command to HSP Headset.
147eda0480fSMatthias Ringwald  *
148eda0480fSMatthias Ringwald  * On HSP_SUBEVENT_AG_INDICATION, the client needs to respond
149eda0480fSMatthias Ringwald  * with this function with the result to the custom command.
150eda0480fSMatthias Ringwald  * @param result
151eda0480fSMatthias Ringwald  */
1523deb3ec6SMatthias Ringwald int hsp_ag_send_result(char * result);
1533deb3ec6SMatthias Ringwald 
154eda0480fSMatthias Ringwald /* API_END */
155eda0480fSMatthias Ringwald 
1563deb3ec6SMatthias Ringwald #if defined __cplusplus
1573deb3ec6SMatthias Ringwald }
1583deb3ec6SMatthias Ringwald #endif
1593deb3ec6SMatthias Ringwald 
1603deb3ec6SMatthias Ringwald #endif