xref: /btstack/src/classic/avdtp_initiator.c (revision 3c4cc6427fe05577c00b7d2593f58c7abcf9eab7)
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 #define BTSTACK_FILE__ "avdtp_initiator.c"
39 
40 #include <stdint.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 
45 #include "btstack.h"
46 #include "classic/avdtp.h"
47 #include "classic/avdtp_util.h"
48 #include "classic/avdtp_initiator.h"
49 
50 static int avdtp_initiator_send_signaling_cmd(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t transaction_label){
51     uint8_t command[2];
52     command[0] = avdtp_header(transaction_label, AVDTP_SINGLE_PACKET, AVDTP_CMD_MSG);
53     command[1] = (uint8_t)identifier;
54     return l2cap_send(cid, command, sizeof(command));
55 }
56 
57 static int avdtp_initiator_send_signaling_cmd_with_seid(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t transaction_label, uint8_t sep_id){
58     uint8_t command[3];
59     command[0] = avdtp_header(transaction_label, AVDTP_SINGLE_PACKET, AVDTP_CMD_MSG);
60     command[1] = (uint8_t)identifier;
61     command[2] = sep_id << 2;
62     return l2cap_send(cid, command, sizeof(command));
63 }
64 
65 static int avdtp_initiator_send_signaling_cmd_delay_report(uint16_t cid, uint8_t transaction_label, uint8_t sep_id, uint16_t delay_ms){
66     uint8_t command[5];
67     command[0] = avdtp_header(transaction_label, AVDTP_SINGLE_PACKET, AVDTP_CMD_MSG);
68     command[1] = AVDTP_SI_DELAYREPORT;
69     command[2] = sep_id << 2;
70     big_endian_store_16(command, 3, delay_ms);
71     return l2cap_send(cid, command, sizeof(command));
72 }
73 
74 void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context){
75     // int status = 0;
76     avdtp_stream_endpoint_t * stream_endpoint = NULL;
77 
78     avdtp_sep_t sep;
79     if (connection->initiator_connection_state == AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER) {
80         connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
81     } else {
82         stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->remote_seid, context);
83         if (!stream_endpoint){
84             stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
85         }
86         if (!stream_endpoint) return;
87         sep.seid = connection->remote_seid;
88 
89         if (stream_endpoint->initiator_config_state != AVDTP_INITIATOR_W4_ANSWER) return;
90         stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE;
91     }
92 
93     switch (connection->signaling_packet.message_type){
94         case AVDTP_RESPONSE_ACCEPT_MSG:
95             switch (connection->signaling_packet.signal_identifier){
96                 case AVDTP_SI_DISCOVER:{
97                     if (connection->signaling_packet.transaction_label != connection->initiator_transaction_label){
98                         log_info("    unexpected transaction label, got %d, expected %d", connection->signaling_packet.transaction_label, connection->initiator_transaction_label);
99                         // status = BAD_HEADER_FORMAT;
100                         break;
101                     }
102 
103                     if (size == 3){
104                         log_info("    ERROR code %02x", packet[offset]);
105                         break;
106                     }
107 
108                     int i;
109                     for (i = offset; i < size; i += 2){
110                         sep.seid = packet[i] >> 2;
111                         offset++;
112                         if (sep.seid < 0x01 || sep.seid > 0x3E){
113                             log_info("    invalid sep id");
114                             // status = BAD_ACP_SEID;
115                             break;
116                         }
117                         sep.in_use = (packet[i] >> 1) & 0x01;
118                         sep.media_type = (avdtp_media_type_t)(packet[i+1] >> 4);
119                         sep.type = (avdtp_sep_type_t)((packet[i+1] >> 3) & 0x01);
120                         avdtp_signaling_emit_sep(context->avdtp_callback, connection->avdtp_cid, sep);
121                     }
122                     avdtp_signaling_emit_sep_done(context->avdtp_callback, connection->avdtp_cid);
123                     break;
124                 }
125 
126                 case AVDTP_SI_GET_CAPABILITIES:
127                 case AVDTP_SI_GET_ALL_CAPABILITIES:
128                     sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, packet+offset, size-offset);
129                     avdtp_emit_capabilities(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid, &sep.capabilities, sep.registered_service_categories);
130                     break;
131                 case AVDTP_SI_DELAYREPORT:
132                     avdtp_signaling_emit_delay(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, little_endian_read_16(packet, offset));
133                     break;
134                 case AVDTP_SI_GET_CONFIGURATION:
135                     // sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, packet+offset, size-offset);
136                     // if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){
137                     //     switch (sep.configuration.media_codec.media_codec_type){
138                     //         case AVDTP_CODEC_SBC:
139                     //             avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid,
140                     //                 sep.configuration.media_codec.media_type, sep.configuration.media_codec.media_codec_information);
141                     //             break;
142                     //         default:
143                     //             avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid,  connection->remote_seid, sep.configuration.media_codec);
144                     //             break;
145                     //     }
146                     // }
147                     break;
148 
149                 case AVDTP_SI_RECONFIGURE:
150                     if (!stream_endpoint){
151                         log_error("AVDTP_SI_RECONFIGURE: stream endpoint is null");
152                         break;
153                     }
154                     // copy sbc media codec info
155                     stream_endpoint->remote_sep.configured_service_categories |= stream_endpoint->remote_configuration_bitmap;
156                     stream_endpoint->remote_sep.configuration = stream_endpoint->remote_configuration;
157                     memcpy(stream_endpoint->media_codec_sbc_info, stream_endpoint->remote_configuration.media_codec.media_codec_information, 4);
158                     stream_endpoint->remote_sep.configuration.media_codec.media_codec_information = stream_endpoint->media_codec_sbc_info;
159                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
160                     break;
161 
162                 case AVDTP_SI_SET_CONFIGURATION:{
163                     avdtp_configuration_timer_stop(connection);
164                     if (!stream_endpoint){
165                         log_error("AVDTP_SI_SET_CONFIGURATION: stream endpoint is null");
166                         break;
167                     }
168                     sep.configured_service_categories = stream_endpoint->remote_configuration_bitmap;
169                     sep.configuration = stream_endpoint->remote_configuration;
170                     sep.in_use = 1;
171 
172                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED;
173                     stream_endpoint->remote_sep = sep;
174                     stream_endpoint->connection = connection;
175 
176                     log_info("INT: configured remote seid %d, to %p", stream_endpoint->remote_sep.seid, stream_endpoint);
177 
178                     switch (stream_endpoint->media_codec_type){
179                         case AVDTP_CODEC_SBC:
180                             avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid,
181                                 stream_endpoint->media_type, stream_endpoint->media_codec_sbc_info);
182                             break;
183                         default:
184                             // TODO: we don\t have codec info to emit config
185                             avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid,  connection->remote_seid, sep.configuration.media_codec);
186                             break;
187                     }
188                     break;
189                 }
190 
191                 case AVDTP_SI_OPEN:
192                     if (!stream_endpoint){
193                         log_error("AVDTP_SI_OPEN: stream endpoint is null");
194                         break;
195                     }
196                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM) {
197                         log_error("AVDTP_SI_OPEN in wrong stream endpoint state");
198                         return;
199                     }
200                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
201                     connection->local_seid = stream_endpoint->sep.seid;
202                     l2cap_create_channel(context->packet_handler, connection->remote_addr, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, NULL);
203                     return;
204                 case AVDTP_SI_START:
205                     if (!stream_endpoint){
206                         log_error("AVDTP_SI_START: stream endpoint is null");
207                         break;
208                     }
209                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED) {
210                         log_error("AVDTP_SI_START in wrong stream endpoint state");
211                         return;
212                     }
213                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
214                     break;
215                 case AVDTP_SI_SUSPEND:
216                     if (!stream_endpoint){
217                         log_error("AVDTP_SI_SUSPEND: stream endpoint is null");
218                         break;
219                     }
220                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_STREAMING) {
221                         log_error("AVDTP_SI_SUSPEND in wrong stream endpoint state");
222                         return;
223                     }
224                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
225                     break;
226                 case AVDTP_SI_CLOSE:
227                     if (!stream_endpoint){
228                         log_error("AVDTP_SI_CLOSE: stream endpoint is null");
229                         break;
230                     }
231                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CLOSING;
232                     break;
233                 case AVDTP_SI_ABORT:
234                     if (!stream_endpoint){
235                         log_error("AVDTP_SI_ABORT: stream endpoint is null");
236                         break;
237                     }
238                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING;
239                     break;
240                 default:
241                     log_info("    AVDTP_RESPONSE_ACCEPT_MSG, signal %d not implemented", connection->signaling_packet.signal_identifier);
242                     break;
243             }
244             avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, 0, connection->signaling_packet.signal_identifier);
245             connection->initiator_transaction_label++;
246             break;
247         case AVDTP_RESPONSE_REJECT_MSG:
248             switch (connection->signaling_packet.signal_identifier){
249                 case AVDTP_SI_SET_CONFIGURATION:
250                     connection->is_initiator = 0;
251                     log_info("Received reject for set configuration, role changed from initiator to acceptor. Start timer.");
252                     avdtp_configuration_timer_start(connection);
253                     break;
254                 default:
255                     break;
256             }
257             log_info("    AVDTP_RESPONSE_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier);
258             avdtp_signaling_emit_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier);
259             return;
260         case AVDTP_GENERAL_REJECT_MSG:
261             log_info("    AVDTP_GENERAL_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier);
262             avdtp_signaling_emit_general_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier);
263             return;
264         default:
265             break;
266     }
267 }
268 
269 void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context){
270     int sent = 1;
271     switch (connection->initiator_connection_state){
272         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_DISCOVER_SEPS:
273             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_DISCOVER_SEPS");
274             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
275             avdtp_initiator_send_signaling_cmd(connection->l2cap_signaling_cid, AVDTP_SI_DISCOVER, connection->initiator_transaction_label);
276             break;
277         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES:
278             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES");
279             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
280             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_GET_CAPABILITIES, connection->initiator_transaction_label, connection->remote_seid);
281             break;
282         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES:
283             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES");
284             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
285             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_GET_ALL_CAPABILITIES, connection->initiator_transaction_label, connection->remote_seid);
286             break;
287         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CONFIGURATION:
288             log_info("INT: AVDTP_INITIATOR_W4_GET_CONFIGURATION");
289             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
290             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_GET_CONFIGURATION, connection->initiator_transaction_label, connection->remote_seid);
291             break;
292         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_SEND_DELAY_REPORT:
293             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_DELAY_REPORT");
294             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
295             avdtp_initiator_send_signaling_cmd_delay_report(connection->l2cap_signaling_cid, connection->initiator_transaction_label,
296                 connection->remote_seid, connection->delay_ms);
297             break;
298         default:
299             sent = 0;
300             break;
301     }
302 
303     if (sent) return;
304     sent = 1;
305 
306     avdtp_stream_endpoint_t * stream_endpoint = NULL;
307 
308     stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->remote_seid, context);
309     if (!stream_endpoint){
310         stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
311     }
312     if (!stream_endpoint) return;
313 
314     avdtp_initiator_stream_endpoint_state_t stream_endpoint_state = stream_endpoint->initiator_config_state;
315     stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W4_ANSWER;
316 
317     if (stream_endpoint->start_stream){
318         stream_endpoint->start_stream = 0;
319         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_OPENED){
320             connection->local_seid = stream_endpoint->sep.seid;
321             connection->remote_seid = stream_endpoint->remote_sep.seid;
322             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_START, connection->initiator_transaction_label++, connection->remote_seid);
323             return;
324         }
325         return;
326     }
327 
328     if (stream_endpoint->stop_stream){
329         stream_endpoint->stop_stream = 0;
330         if (stream_endpoint->state >= AVDTP_STREAM_ENDPOINT_OPENED){
331             connection->local_seid = stream_endpoint->sep.seid;
332             connection->remote_seid = stream_endpoint->remote_sep.seid;
333             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_CLOSE, connection->initiator_transaction_label++, connection->remote_seid);
334             return;
335         }
336     }
337 
338     if (stream_endpoint->abort_stream){
339         stream_endpoint->abort_stream = 0;
340         switch (stream_endpoint->state){
341             case AVDTP_STREAM_ENDPOINT_CONFIGURED:
342             case AVDTP_STREAM_ENDPOINT_CLOSING:
343             case AVDTP_STREAM_ENDPOINT_OPENED:
344             case AVDTP_STREAM_ENDPOINT_STREAMING:
345                 connection->local_seid = stream_endpoint->sep.seid;
346                 connection->remote_seid = stream_endpoint->remote_sep.seid;
347                 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING;
348                 avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_ABORT, connection->initiator_transaction_label++, connection->remote_seid);
349                 return;
350             default:
351                 break;
352         }
353     }
354 
355     if (stream_endpoint->suspend_stream){
356         stream_endpoint->suspend_stream = 0;
357         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_STREAMING){
358             connection->local_seid = stream_endpoint->sep.seid;
359             connection->remote_seid = stream_endpoint->remote_sep.seid;
360             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
361             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_SUSPEND, connection->initiator_transaction_label, connection->remote_seid);
362             return;
363         }
364     }
365 
366     if (stream_endpoint->send_stream){
367         stream_endpoint->send_stream = 0;
368         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_STREAMING){
369             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
370             avdtp_streaming_emit_can_send_media_packet_now(context->avdtp_callback, stream_endpoint->l2cap_media_cid, stream_endpoint->sep.seid, stream_endpoint->sequence_number);
371             return;
372         }
373     }
374 
375     switch (stream_endpoint_state){
376         case AVDTP_INITIATOR_W2_SET_CONFIGURATION:
377         case AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID:{
378             if (stream_endpoint_state == AVDTP_INITIATOR_W2_SET_CONFIGURATION && !connection->is_initiator){
379                 log_info("initiator SM stop sending SET_CONFIGURATION cmd: current role is acceptor");
380                 connection->is_configuration_initiated_locally = 0;
381                 break;
382             }
383             log_info("initiator SM prepare SET_CONFIGURATION cmd");
384             connection->is_configuration_initiated_locally = 1;
385             log_info("INT: AVDTP_INITIATOR_W2_(RE)CONFIGURATION bitmap, int seid %d, acp seid %d", connection->local_seid, connection->remote_seid);
386             // log_info_hexdump(  connection->remote_capabilities.media_codec.media_codec_information,  connection->remote_capabilities.media_codec.media_codec_information_len);
387             connection->signaling_packet.acp_seid = connection->remote_seid;
388             connection->signaling_packet.int_seid = connection->local_seid;
389 
390             connection->signaling_packet.signal_identifier = AVDTP_SI_SET_CONFIGURATION;
391             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE;
392             if (stream_endpoint_state == AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID){
393                 connection->signaling_packet.signal_identifier = AVDTP_SI_RECONFIGURE;
394             }
395 
396             avdtp_prepare_capabilities(&connection->signaling_packet, connection->initiator_transaction_label, stream_endpoint->remote_configuration_bitmap, stream_endpoint->remote_configuration, connection->signaling_packet.signal_identifier);
397             l2cap_reserve_packet_buffer();
398             uint8_t * out_buffer = l2cap_get_outgoing_buffer();
399             uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
400             if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
401                 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
402                 log_info("INT: fragmented");
403             }
404             l2cap_send_prepared(connection->l2cap_signaling_cid, pos);
405             break;
406         }
407         case AVDTP_INITIATOR_FRAGMENTATED_COMMAND:{
408             l2cap_reserve_packet_buffer();
409             uint8_t * out_buffer = l2cap_get_outgoing_buffer();
410             uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
411             if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
412                 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
413                 log_info("INT: fragmented");
414             }
415             l2cap_send_prepared(connection->l2cap_signaling_cid, pos);
416             break;
417         }
418         case AVDTP_INITIATOR_W2_OPEN_STREAM:
419             switch (stream_endpoint->state){
420                 case AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM:
421                     log_info("INT: AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM");
422                     avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_OPEN, connection->initiator_transaction_label, connection->remote_seid);
423                     break;
424                 default:
425                     sent = 0;
426                     break;
427             }
428             break;
429         default:
430             sent = 0;
431             break;
432     }
433 
434     // check fragmentation
435     if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
436         avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
437     }
438 }
439