xref: /btstack/src/classic/avdtp_util.h (revision dbe92de6a93924b91532f8d818af55adf6b370d8)
1 /*
2  * Copyright (C) 2016 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  * avdtp_util.h
40  *
41  * Audio/Video Distribution Transport Protocol - Utils
42  *
43  */
44 
45 #ifndef AVDTP_UITL_H
46 #define AVDTP_UITL_H
47 
48 #include <stdint.h>
49 #include "classic/avdtp.h"
50 
51 #if defined __cplusplus
52 extern "C" {
53 #endif
54 
55 static inline uint8_t avdtp_header(uint8_t tr_label, avdtp_packet_type_t packet_type, avdtp_message_type_t msg_type){
56     return (tr_label<<4) | ((uint8_t)packet_type<<2) | (uint8_t)msg_type;
57 }
58 
59 avdtp_message_type_t avdtp_get_signaling_packet_type(uint8_t * packet);
60 
61 int     avdtp_read_signaling_header(avdtp_signaling_packet_t * signaling_header, uint8_t * packet, uint16_t size);
62 
63 uint16_t store_bit16(uint16_t bitmap, int position, uint8_t value);
64 int     get_bit16(uint16_t bitmap, int position);
65 
66 int avdtp_pack_service_capabilities(uint8_t * buffer, int size, avdtp_capabilities_t caps, avdtp_service_category_t category, uint8_t pack_all_capabilities);
67 uint16_t avdtp_unpack_service_capabilities(avdtp_connection_t * connection, avdtp_signal_identifier_t signal_identifier, avdtp_capabilities_t * caps, uint8_t * packet, uint16_t size);
68 
69 void avdtp_prepare_capabilities(avdtp_signaling_packet_t * signaling_packet, uint8_t transaction_label, uint16_t registered_service_categories, avdtp_capabilities_t configuration, uint8_t identifier);
70 int avdtp_signaling_create_fragment(uint16_t cid, avdtp_signaling_packet_t * signaling_packet, uint8_t * out_buffer);
71 
72 void avdtp_signaling_emit_connection_established(uint16_t avdtp_cid, bd_addr_t addr, uint8_t status);
73 
74 void avdtp_signaling_emit_connection_released(uint16_t avdtp_cid);
75 
76 void avdtp_signaling_emit_sep(uint16_t avdtp_cid, avdtp_sep_t sep);
77 void avdtp_signaling_emit_sep_done(uint16_t avdtp_cid);
78 
79 void avdtp_signaling_emit_accept(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier,
80                                  bool is_initiator);
81 void avdtp_signaling_emit_general_reject(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier,
82                                          bool is_initiator);
83 void avdtp_signaling_emit_reject(uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier,
84                                  bool is_initiator);
85 
86 void
87 avdtp_emit_capabilities(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, avdtp_capabilities_t *capabilities,
88                         uint16_t registered_service_categories);
89 
90 void
91 avdtp_signaling_emit_media_codec_other_reconfiguration(avdtp_stream_endpoint_t *stream_endpoint, uint16_t avdtp_cid,
92                                                        uint8_t local_seid, uint8_t remote_seid,
93                                                        adtvp_media_codec_capabilities_t media_codec);
94 void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure);
95 
96 uint8_t avdtp_request_can_send_now_acceptor(avdtp_connection_t * connection, uint16_t l2cap_cid);
97 uint8_t avdtp_request_can_send_now_initiator(avdtp_connection_t * connection, uint16_t l2cap_cid);
98 
99 void avdtp_reset_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint);
100 
101 // uint16_t avdtp_cid(avdtp_stream_endpoint_t * stream_endpoint);
102 uint8_t  avdtp_local_seid(avdtp_stream_endpoint_t * stream_endpoint);
103 uint8_t  avdtp_remote_seid(avdtp_stream_endpoint_t * stream_endpoint);
104 const char * avdtp_si2str(uint16_t index);
105 
106 void a2dp_streaming_emit_connection_established(btstack_packet_handler_t callback, uint16_t cid, bd_addr_t addr, uint8_t local_seid, uint8_t remote_seid, uint8_t status);
107 
108 #if defined __cplusplus
109 }
110 #endif
111 
112 #endif // AVDTP_UITL_H
113