xref: /btstack/src/classic/avdtp_initiator.c (revision 630ffdd469bbec3276322f46b93e6cfdfcb21c27)
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                     break;
133                 case AVDTP_SI_GET_CONFIGURATION:
134                     // sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, packet+offset, size-offset);
135                     // if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){
136                     //     switch (sep.configuration.media_codec.media_codec_type){
137                     //         case AVDTP_CODEC_SBC:
138                     //             avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid,
139                     //                 sep.configuration.media_codec.media_type, sep.configuration.media_codec.media_codec_information);
140                     //             break;
141                     //         default:
142                     //             avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid,  connection->remote_seid, sep.configuration.media_codec);
143                     //             break;
144                     //     }
145                     // }
146                     break;
147 
148                 case AVDTP_SI_RECONFIGURE:
149                     if (!stream_endpoint){
150                         log_error("AVDTP_SI_RECONFIGURE: stream endpoint is null");
151                         break;
152                     }
153                     // copy sbc media codec info
154                     stream_endpoint->remote_sep.configured_service_categories |= stream_endpoint->remote_configuration_bitmap;
155                     stream_endpoint->remote_sep.configuration = stream_endpoint->remote_configuration;
156                     memcpy(stream_endpoint->media_codec_sbc_info, stream_endpoint->remote_configuration.media_codec.media_codec_information, 4);
157                     stream_endpoint->remote_sep.configuration.media_codec.media_codec_information = stream_endpoint->media_codec_sbc_info;
158 
159 #if 0
160                     sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+4, connection->signaling_packet.size-4);
161                     // TODO check if configuration is supported
162 
163                     if (!is_avdtp_remote_seid_registered(stream_endpoint)){
164                         stream_endpoint->remote_sep = sep;
165                         log_info("INT: update seid %d, to %p", stream_endpoint->remote_sep.seid, stream_endpoint);
166                     }
167 #endif
168                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
169                     break;
170 
171                 case AVDTP_SI_SET_CONFIGURATION:{
172                     avdtp_configuration_timer_stop(connection);
173                     if (!stream_endpoint){
174                         log_error("AVDTP_SI_SET_CONFIGURATION: stream endpoint is null");
175                         break;
176                     }
177                     sep.configured_service_categories = stream_endpoint->remote_configuration_bitmap;
178                     sep.configuration = stream_endpoint->remote_configuration;
179                     sep.in_use = 1;
180 
181                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED;
182                     stream_endpoint->remote_sep = sep;
183                     stream_endpoint->connection = connection;
184 
185                     log_info("INT: configured remote seid %d, to %p", stream_endpoint->remote_sep.seid, stream_endpoint);
186 
187                     switch (stream_endpoint->media_codec_type){
188                         case AVDTP_CODEC_SBC:
189                             avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid,
190                                 stream_endpoint->media_type, stream_endpoint->media_codec_sbc_info);
191                             break;
192                         default:
193                             // TODO: we don\t have codec info to emit config
194                             avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid,  connection->remote_seid, sep.configuration.media_codec);
195                             break;
196                     }
197                     break;
198                 }
199 
200                 case AVDTP_SI_OPEN:
201                     if (!stream_endpoint){
202                         log_error("AVDTP_SI_OPEN: stream endpoint is null");
203                         break;
204                     }
205                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM) {
206                         log_error("AVDTP_SI_OPEN in wrong stream endpoint state");
207                         return;
208                     }
209                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
210                     connection->local_seid = stream_endpoint->sep.seid;
211                     l2cap_create_channel(context->packet_handler, connection->remote_addr, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, NULL);
212                     return;
213                 case AVDTP_SI_START:
214                     if (!stream_endpoint){
215                         log_error("AVDTP_SI_START: stream endpoint is null");
216                         break;
217                     }
218                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED) {
219                         log_error("AVDTP_SI_START in wrong stream endpoint state");
220                         return;
221                     }
222                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
223                     break;
224                 case AVDTP_SI_SUSPEND:
225                     if (!stream_endpoint){
226                         log_error("AVDTP_SI_SUSPEND: stream endpoint is null");
227                         break;
228                     }
229                     if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_STREAMING) {
230                         log_error("AVDTP_SI_SUSPEND in wrong stream endpoint state");
231                         return;
232                     }
233                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
234                     break;
235                 case AVDTP_SI_CLOSE:
236                     if (!stream_endpoint){
237                         log_error("AVDTP_SI_CLOSE: stream endpoint is null");
238                         break;
239                     }
240                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CLOSING;
241                     break;
242                 case AVDTP_SI_ABORT:
243                     if (!stream_endpoint){
244                         log_error("AVDTP_SI_ABORT: stream endpoint is null");
245                         break;
246                     }
247                     stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING;
248                     break;
249 
250                 default:
251                     log_info("    AVDTP_RESPONSE_ACCEPT_MSG, signal %d not implemented", connection->signaling_packet.signal_identifier);
252                     break;
253             }
254             avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, 0, connection->signaling_packet.signal_identifier);
255             connection->initiator_transaction_label++;
256             break;
257         case AVDTP_RESPONSE_REJECT_MSG:
258             switch (connection->signaling_packet.signal_identifier){
259                 case AVDTP_SI_SET_CONFIGURATION:
260                     connection->is_initiator = 0;
261                     log_info("Received reject for set configuration, role changed from initiator to acceptor. Start timer.");
262                     avdtp_configuration_timer_start(connection);
263                     break;
264                 default:
265                     break;
266             }
267             log_info("    AVDTP_RESPONSE_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier);
268             avdtp_signaling_emit_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier);
269             return;
270         case AVDTP_GENERAL_REJECT_MSG:
271             log_info("    AVDTP_GENERAL_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier);
272             avdtp_signaling_emit_general_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier);
273             return;
274         default:
275             break;
276     }
277 }
278 
279 void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, avdtp_context_t * context){
280     int sent = 1;
281     switch (connection->initiator_connection_state){
282         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_DISCOVER_SEPS:
283             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_DISCOVER_SEPS");
284             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
285             avdtp_initiator_send_signaling_cmd(connection->l2cap_signaling_cid, AVDTP_SI_DISCOVER, connection->initiator_transaction_label);
286             break;
287         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES:
288             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CAPABILITIES");
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_CAPABILITIES, connection->initiator_transaction_label, connection->remote_seid);
291             break;
292         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES:
293             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_ALL_CAPABILITIES");
294             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
295             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_GET_ALL_CAPABILITIES, connection->initiator_transaction_label, connection->remote_seid);
296             break;
297         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_GET_CONFIGURATION:
298             log_info("INT: AVDTP_INITIATOR_W4_GET_CONFIGURATION");
299             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
300             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_GET_CONFIGURATION, connection->initiator_transaction_label, connection->remote_seid);
301             break;
302         case AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_SEND_DELAY_REPORT:
303             log_info("INT: AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_DELAY_REPORT");
304             connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER;
305             avdtp_initiator_send_signaling_cmd_delay_report(connection->l2cap_signaling_cid, connection->initiator_transaction_label,
306                 connection->remote_seid, connection->delay_ms);
307             break;
308         default:
309             sent = 0;
310             break;
311     }
312 
313     if (sent) return;
314     sent = 1;
315 
316     avdtp_stream_endpoint_t * stream_endpoint = NULL;
317 
318     stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->remote_seid, context);
319     if (!stream_endpoint){
320         stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
321     }
322     if (!stream_endpoint) return;
323 
324     avdtp_initiator_stream_endpoint_state_t stream_endpoint_state = stream_endpoint->initiator_config_state;
325     stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W4_ANSWER;
326 
327     if (stream_endpoint->start_stream){
328         stream_endpoint->start_stream = 0;
329         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_OPENED){
330             connection->local_seid = stream_endpoint->sep.seid;
331             connection->remote_seid = stream_endpoint->remote_sep.seid;
332             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_START, connection->initiator_transaction_label++, connection->remote_seid);
333             return;
334         }
335         return;
336     }
337 
338     if (stream_endpoint->stop_stream){
339         stream_endpoint->stop_stream = 0;
340         if (stream_endpoint->state >= AVDTP_STREAM_ENDPOINT_OPENED){
341             connection->local_seid = stream_endpoint->sep.seid;
342             connection->remote_seid = stream_endpoint->remote_sep.seid;
343             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_CLOSE, connection->initiator_transaction_label++, connection->remote_seid);
344             return;
345         }
346     }
347 
348     if (stream_endpoint->abort_stream){
349         stream_endpoint->abort_stream = 0;
350         switch (stream_endpoint->state){
351             case AVDTP_STREAM_ENDPOINT_CONFIGURED:
352             case AVDTP_STREAM_ENDPOINT_CLOSING:
353             case AVDTP_STREAM_ENDPOINT_OPENED:
354             case AVDTP_STREAM_ENDPOINT_STREAMING:
355                 connection->local_seid = stream_endpoint->sep.seid;
356                 connection->remote_seid = stream_endpoint->remote_sep.seid;
357                 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING;
358                 avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_ABORT, connection->initiator_transaction_label++, connection->remote_seid);
359                 return;
360             default:
361                 break;
362         }
363     }
364 
365     if (stream_endpoint->suspend_stream){
366         stream_endpoint->suspend_stream = 0;
367         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_STREAMING){
368             connection->local_seid = stream_endpoint->sep.seid;
369             connection->remote_seid = stream_endpoint->remote_sep.seid;
370             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
371             avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_SUSPEND, connection->initiator_transaction_label, connection->remote_seid);
372             return;
373         }
374     }
375 
376     if (stream_endpoint->send_stream){
377         stream_endpoint->send_stream = 0;
378         if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_STREAMING){
379             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
380             avdtp_streaming_emit_can_send_media_packet_now(context->avdtp_callback, stream_endpoint->l2cap_media_cid, stream_endpoint->sep.seid, stream_endpoint->sequence_number);
381             return;
382         }
383     }
384 
385     switch (stream_endpoint_state){
386         case AVDTP_INITIATOR_W2_SET_CONFIGURATION:
387         case AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID:{
388             if (stream_endpoint_state == AVDTP_INITIATOR_W2_SET_CONFIGURATION && !connection->is_initiator){
389                 log_info("initiator SM stop sending SET_CONFIGURATION cmd: current role is acceptor");
390                 connection->is_configuration_initiated_locally = 0;
391                 break;
392             }
393             log_info("initiator SM prepare SET_CONFIGURATION cmd");
394             connection->is_configuration_initiated_locally = 1;
395             log_info("INT: AVDTP_INITIATOR_W2_(RE)CONFIGURATION bitmap, int seid %d, acp seid %d", connection->local_seid, connection->remote_seid);
396             // log_info_hexdump(  connection->remote_capabilities.media_codec.media_codec_information,  connection->remote_capabilities.media_codec.media_codec_information_len);
397             connection->signaling_packet.acp_seid = connection->remote_seid;
398             connection->signaling_packet.int_seid = connection->local_seid;
399 
400             connection->signaling_packet.signal_identifier = AVDTP_SI_SET_CONFIGURATION;
401             stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE;
402             if (stream_endpoint_state == AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID){
403                 connection->signaling_packet.signal_identifier = AVDTP_SI_RECONFIGURE;
404             }
405 
406             avdtp_prepare_capabilities(&connection->signaling_packet, connection->initiator_transaction_label, stream_endpoint->remote_configuration_bitmap, stream_endpoint->remote_configuration, connection->signaling_packet.signal_identifier);
407             l2cap_reserve_packet_buffer();
408             uint8_t * out_buffer = l2cap_get_outgoing_buffer();
409             uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
410             if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
411                 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
412                 log_info("INT: fragmented");
413             }
414             l2cap_send_prepared(connection->l2cap_signaling_cid, pos);
415             break;
416         }
417         case AVDTP_INITIATOR_FRAGMENTATED_COMMAND:{
418             l2cap_reserve_packet_buffer();
419             uint8_t * out_buffer = l2cap_get_outgoing_buffer();
420             uint16_t pos = avdtp_signaling_create_fragment(connection->l2cap_signaling_cid, &connection->signaling_packet, out_buffer);
421             if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
422                 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_FRAGMENTATED_COMMAND;
423                 log_info("INT: fragmented");
424             }
425             l2cap_send_prepared(connection->l2cap_signaling_cid, pos);
426             break;
427         }
428         case AVDTP_INITIATOR_W2_OPEN_STREAM:
429             switch (stream_endpoint->state){
430                 case AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM:
431                     log_info("INT: AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM");
432                     avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_OPEN, connection->initiator_transaction_label, connection->remote_seid);
433                     break;
434                 default:
435                     sent = 0;
436                     break;
437             }
438             break;
439         default:
440             sent = 0;
441             break;
442     }
443 
444     // check fragmentation
445     if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
446         avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
447     }
448 }
449