avdtp.c (9413b167eca30861711396cfa611dbc66aa27249) avdtp.c (34b22aac0913b061ca6c0da686fd034f9e188df1)
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

--- 270 unchanged lines hidden (view full) ---

279 }
280 break;
281 }
282 case HCI_EVENT_PACKET:
283 switch (event){
284 case L2CAP_EVENT_CHANNEL_OPENED:
285 if (stream_endpoint->l2cap_media_cid == 0){
286 if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED){
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

--- 270 unchanged lines hidden (view full) ---

279 }
280 break;
281 }
282 case HCI_EVENT_PACKET:
283 switch (event){
284 case L2CAP_EVENT_CHANNEL_OPENED:
285 if (stream_endpoint->l2cap_media_cid == 0){
286 if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED){
287 // log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed - stream endpoint in wrong state %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", stream_endpoint->state, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
287 log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed - stream endpoint in wrong state %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", stream_endpoint->state, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
288 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), AVDTP_STREAM_ENDPOINT_IN_WRONG_STATE);
289 break;
290 }
291 status = l2cap_event_channel_opened_get_status(packet);
292 if (status){
288 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), AVDTP_STREAM_ENDPOINT_IN_WRONG_STATE);
289 break;
290 }
291 status = l2cap_event_channel_opened_get_status(packet);
292 if (status){
293 // log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed with status %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", status, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
293 log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED failed with status %d, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", status, connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
294 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), status);
295 break;
296 }
297 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
298 stream_endpoint->connection = connection;
299 stream_endpoint->l2cap_media_cid = l2cap_event_channel_opened_get_local_cid(packet);
300 stream_endpoint->media_con_handle = l2cap_event_channel_opened_get_handle(packet);
301
302 // log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
303 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), 0);
304 break;
305 }
306 break;
307 case L2CAP_EVENT_CHANNEL_CLOSED:
308 local_cid = l2cap_event_channel_closed_get_local_cid(packet);
309 if (stream_endpoint->l2cap_media_cid == local_cid){
310 stream_endpoint->l2cap_media_cid = 0;
294 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), status);
295 break;
296 }
297 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
298 stream_endpoint->connection = connection;
299 stream_endpoint->l2cap_media_cid = l2cap_event_channel_opened_get_local_cid(packet);
300 stream_endpoint->media_con_handle = l2cap_event_channel_opened_get_handle(packet);
301
302 // log_info(" -> AVDTP_STREAM_ENDPOINT_OPENED, avdtp cid 0x%02x, l2cap_media_cid 0x%02x, local seid %d, remote seid %d", connection->avdtp_cid, stream_endpoint->l2cap_media_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint));
303 avdtp_streaming_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), 0);
304 break;
305 }
306 break;
307 case L2CAP_EVENT_CHANNEL_CLOSED:
308 local_cid = l2cap_event_channel_closed_get_local_cid(packet);
309 if (stream_endpoint->l2cap_media_cid == local_cid){
310 stream_endpoint->l2cap_media_cid = 0;
311 log_info(" -> L2CAP_EVENT_CHANNEL_CLOSED: AVDTP_STREAM_ENDPOINT_IDLE");
312 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_IDLE;
313 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
314 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE;
315 stream_endpoint->remote_sep_index = 0;
311 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_IDLE;
312 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
313 stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE;
314 stream_endpoint->remote_sep_index = 0;
315 avdtp_streaming_emit_connection_released(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint));
316 break;
317 }
318 if (stream_endpoint->l2cap_recovery_cid == local_cid){
319 log_info(" -> L2CAP_EVENT_CHANNEL_CLOSED recovery cid 0x%0x", local_cid);
320 stream_endpoint->l2cap_recovery_cid = 0;
321 break;
322 }
323

--- 245 unchanged lines hidden (view full) ---

569 if (!stream_endpoint){
570 log_info("L2CAP_EVENT_CHANNEL_OPENED: stream_endpoint not found");
571 return;
572 }
573 stream_endpoint_state_machine(connection, stream_endpoint, HCI_EVENT_PACKET, L2CAP_EVENT_CHANNEL_OPENED, packet, size, context);
574 break;
575
576 case L2CAP_EVENT_CHANNEL_CLOSED:
316 break;
317 }
318 if (stream_endpoint->l2cap_recovery_cid == local_cid){
319 log_info(" -> L2CAP_EVENT_CHANNEL_CLOSED recovery cid 0x%0x", local_cid);
320 stream_endpoint->l2cap_recovery_cid = 0;
321 break;
322 }
323

--- 245 unchanged lines hidden (view full) ---

569 if (!stream_endpoint){
570 log_info("L2CAP_EVENT_CHANNEL_OPENED: stream_endpoint not found");
571 return;
572 }
573 stream_endpoint_state_machine(connection, stream_endpoint, HCI_EVENT_PACKET, L2CAP_EVENT_CHANNEL_OPENED, packet, size, context);
574 break;
575
576 case L2CAP_EVENT_CHANNEL_CLOSED:
577 // data: event (8), len(8), channel (16)
578 local_cid = l2cap_event_channel_closed_get_local_cid(packet);
579 connection = avdtp_connection_for_l2cap_signaling_cid(local_cid, context);
577 local_cid = l2cap_event_channel_closed_get_local_cid(packet);
578 connection = avdtp_connection_for_l2cap_signaling_cid(local_cid, context);
580 log_info(" -> L2CAP_EVENT_CHANNEL_CLOSED signaling cid 0x%0x", local_cid);
581
582 stream_endpoint = avdtp_stream_endpoint_for_l2cap_cid(local_cid, context);
579 stream_endpoint = avdtp_stream_endpoint_for_l2cap_cid(local_cid, context);
580
583 if (stream_endpoint){
584 stream_endpoint_state_machine(connection, stream_endpoint, HCI_EVENT_PACKET, L2CAP_EVENT_CHANNEL_CLOSED, packet, size, context);
585 break;
586 }
587
588 if (connection){
581 if (stream_endpoint){
582 stream_endpoint_state_machine(connection, stream_endpoint, HCI_EVENT_PACKET, L2CAP_EVENT_CHANNEL_CLOSED, packet, size, context);
583 break;
584 }
585
586 if (connection){
589 log_info(" -> AVDTP_STREAM_ENDPOINT_IDLE, connection closed");
587 avdtp_signaling_emit_connection_released(context->avdtp_callback, connection->avdtp_cid);
590 btstack_linked_list_remove(avdtp_connections, (btstack_linked_item_t*) connection);
588 btstack_linked_list_remove(avdtp_connections, (btstack_linked_item_t*) connection);
591
592 btstack_linked_list_iterator_t it;
593 btstack_linked_list_iterator_init(&it, stream_endpoints);
594 while (btstack_linked_list_iterator_has_next(&it)){
595 avdtp_stream_endpoint_t * _stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
596
597 if (_stream_endpoint->connection == connection){
598 avdtp_initialize_stream_endpoint(_stream_endpoint);
599 }

--- 431 unchanged lines hidden ---
589 btstack_linked_list_iterator_t it;
590 btstack_linked_list_iterator_init(&it, stream_endpoints);
591 while (btstack_linked_list_iterator_has_next(&it)){
592 avdtp_stream_endpoint_t * _stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
593
594 if (_stream_endpoint->connection == connection){
595 avdtp_initialize_stream_endpoint(_stream_endpoint);
596 }

--- 431 unchanged lines hidden ---