xref: /btstack/src/classic/avdtp_source.c (revision c37cd8f3d1350b92a2f66c31b2a5fcd75f8c91a4)
1 
2 /*
3  * Copyright (C) 2016 BlueKitchen GmbH
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific prior written permission.
17  * 4. Any redistribution, use, or modification is done solely for
18  *    personal benefit and not for any commercial purpose or for
19  *    monetary gain.
20  *
21  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
25  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
31  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * Please inquire about commercial licensing options at
35  * [email protected]
36  *
37  */
38 
39 #define __BTSTACK_FILE__ "avdtp_source.c"
40 
41 
42 #include <stdint.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 
47 #include "btstack.h"
48 #include "classic/avdtp.h"
49 #include "classic/avdtp_util.h"
50 #include "classic/avdtp_source.h"
51 
52 static avdtp_context_t * avdtp_source_context;
53 
54 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
55 
56 void avdtp_source_register_media_transport_category(uint8_t seid){
57     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
58     avdtp_register_media_transport_category(stream_endpoint);
59 }
60 
61 void avdtp_source_register_reporting_category(uint8_t seid){
62     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
63     avdtp_register_reporting_category(stream_endpoint);
64 }
65 
66 void avdtp_source_register_delay_reporting_category(uint8_t seid){
67     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
68     avdtp_register_delay_reporting_category(stream_endpoint);
69 }
70 
71 void avdtp_source_register_recovery_category(uint8_t seid, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets){
72     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
73     avdtp_register_recovery_category(stream_endpoint, maximum_recovery_window_size, maximum_number_media_packets);
74 }
75 
76 void avdtp_source_register_content_protection_category(uint8_t seid, uint16_t cp_type, const uint8_t * cp_type_value, uint8_t cp_type_value_len){
77     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
78     avdtp_register_content_protection_category(stream_endpoint, cp_type, cp_type_value, cp_type_value_len);
79 }
80 
81 void avdtp_source_register_header_compression_category(uint8_t seid, uint8_t back_ch, uint8_t media, uint8_t recovery){
82     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
83     avdtp_register_header_compression_category(stream_endpoint, back_ch, media, recovery);
84 }
85 
86 void avdtp_source_register_media_codec_category(uint8_t seid, avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, uint8_t * media_codec_info, uint16_t media_codec_info_len){
87     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
88     avdtp_register_media_codec_category(stream_endpoint, media_type, media_codec_type, media_codec_info, media_codec_info_len);
89 }
90 
91 void avdtp_source_register_multiplexing_category(uint8_t seid, uint8_t fragmentation){
92     avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
93     avdtp_register_multiplexing_category(stream_endpoint, fragmentation);
94 }
95 
96 avdtp_stream_endpoint_t * avdtp_source_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type){
97     return avdtp_create_stream_endpoint(sep_type, media_type, avdtp_source_context);
98 }
99 
100 void avdtp_source_register_packet_handler(btstack_packet_handler_t callback){
101     if (callback == NULL){
102         log_error("avdtp_source_register_packet_handler called with NULL callback");
103         return;
104     }
105     avdtp_source_context->avdtp_callback = callback;
106 }
107 
108 uint8_t avdtp_source_connect(bd_addr_t remote, uint16_t * avdtp_cid){
109     return avdtp_connect(remote, AVDTP_SINK, avdtp_source_context, avdtp_cid);
110 }
111 
112 uint8_t avdtp_source_disconnect(uint16_t avdtp_cid){
113     return avdtp_disconnect(avdtp_cid, avdtp_source_context);
114 }
115 
116 uint8_t avdtp_source_open_stream(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid){
117     return avdtp_open_stream(avdtp_cid, local_seid, remote_seid, avdtp_source_context);
118 }
119 
120 uint8_t avdtp_source_start_stream(uint16_t avdtp_cid, uint8_t local_seid){
121     return avdtp_start_stream(avdtp_cid, local_seid, avdtp_source_context);
122 }
123 
124 uint8_t avdtp_source_stop_stream(uint16_t avdtp_cid, uint8_t local_seid){
125     return avdtp_stop_stream(avdtp_cid, local_seid, avdtp_source_context);
126 }
127 
128 uint8_t avdtp_source_abort_stream(uint16_t avdtp_cid, uint8_t local_seid){
129     return avdtp_abort_stream(avdtp_cid, local_seid, avdtp_source_context);
130 }
131 
132 uint8_t avdtp_source_suspend(uint16_t avdtp_cid, uint8_t local_seid){
133     return avdtp_suspend_stream(avdtp_cid, local_seid, avdtp_source_context);
134 }
135 
136 void avdtp_source_discover_stream_endpoints(uint16_t avdtp_cid){
137     avdtp_discover_stream_endpoints(avdtp_cid, avdtp_source_context);
138 }
139 
140 void avdtp_source_get_capabilities(uint16_t avdtp_cid, uint8_t remote_seid){
141     avdtp_get_capabilities(avdtp_cid, remote_seid, avdtp_source_context);
142 }
143 
144 void avdtp_source_get_all_capabilities(uint16_t avdtp_cid, uint8_t remote_seid){
145     avdtp_get_all_capabilities(avdtp_cid, remote_seid, avdtp_source_context);
146 }
147 
148 void avdtp_source_get_configuration(uint16_t avdtp_cid, uint8_t remote_seid){
149     avdtp_get_configuration(avdtp_cid, remote_seid, avdtp_source_context);
150 }
151 
152 void avdtp_source_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration){
153     avdtp_set_configuration(avdtp_cid, local_seid, remote_seid, configured_services_bitmap, configuration, avdtp_source_context);
154 }
155 
156 void avdtp_source_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration){
157     avdtp_reconfigure(avdtp_cid, local_seid, remote_seid, configured_services_bitmap, configuration, avdtp_source_context);
158 }
159 
160 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
161     avdtp_packet_handler(packet_type, channel, packet, size, avdtp_source_context);
162 }
163 
164 void avdtp_source_init(avdtp_context_t * avdtp_context){
165     if (!avdtp_context){
166         log_error("avdtp_source_context is NULL");
167         return;
168     }
169     avdtp_source_context = avdtp_context;
170     avdtp_source_context->stream_endpoints = NULL;
171     avdtp_source_context->connections = NULL;
172     avdtp_source_context->stream_endpoints_id_counter = 0;
173     avdtp_source_context->packet_handler = packet_handler;
174 
175     l2cap_register_service(&packet_handler, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, LEVEL_0);
176 }
177 
178 uint8_t avdtp_source_remote_seps_num(uint16_t avdtp_cid){
179     return avdtp_remote_seps_num(avdtp_cid, avdtp_source_context);
180 }
181 
182 avdtp_sep_t * avdtp_source_remote_sep(uint16_t avdtp_cid, uint8_t index){
183     return avdtp_remote_sep(avdtp_cid, index, avdtp_source_context);
184 }
185