avdtp.c (371c8f0ee5e532a1a235ad9b67fd1ac668f4e51b) avdtp.c (89f10e1d723a12f5563dd0e147dedf9b7f778e41)
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

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

729 UNUSED(channel);
730 UNUSED(size);
731
732 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_sdp_query_context_avdtp_cid);
733 if (!connection) {
734 log_error("SDP query, connection with 0x%02x cid not found", avdtp_sdp_query_context_avdtp_cid);
735 return;
736 }
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

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

729 UNUSED(channel);
730 UNUSED(size);
731
732 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_sdp_query_context_avdtp_cid);
733 if (!connection) {
734 log_error("SDP query, connection with 0x%02x cid not found", avdtp_sdp_query_context_avdtp_cid);
735 return;
736 }
737
737
738 uint8_t status = ERROR_CODE_SUCCESS;
738 uint8_t status = ERROR_CODE_SUCCESS;
739 switch (hci_event_packet_get_type(packet)){
740 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
741 avdtp_handle_sdp_client_query_attribute_value(connection, packet);
742 return;
743 case SDP_EVENT_QUERY_COMPLETE:
744 status = sdp_event_query_complete_get_status(packet);
745 break;
746 default:
747 btstack_assert(false);
748 return;
749 }
750
751 // query completed with status, validate received information
752 bool handle_query_complete = true;
739 switch (connection->state){
740 case AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SINK_COMPLETE:
753 switch (connection->state){
754 case AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SINK_COMPLETE:
741 switch (hci_event_packet_get_type(packet)){
742 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
743 avdtp_handle_sdp_client_query_attribute_value(connection, packet);
744 return;
745 case SDP_EVENT_QUERY_COMPLETE:
746 status = sdp_event_query_complete_get_status(packet);
747 if (status != ERROR_CODE_SUCCESS) break;
748 if (!connection->sink_supported || (connection->avdtp_l2cap_psm == 0)) {
749 status = SDP_SERVICE_NOT_FOUND;
750 break;
751 }
752 break;
753 default:
754 btstack_assert(false);
755 return;
755 if (status == ERROR_CODE_SUCCESS) {
756 if (!connection->sink_supported || (connection->avdtp_l2cap_psm == 0)) {
757 status = SDP_SERVICE_NOT_FOUND;
758 }
756 }
757 break;
758 case AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SOURCE_COMPLETE:
759 }
760 break;
761 case AVDTP_SIGNALING_W4_SDP_QUERY_FOR_REMOTE_SOURCE_COMPLETE:
759 switch (hci_event_packet_get_type(packet)){
760 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
761 avdtp_handle_sdp_client_query_attribute_value(connection, packet);
762 return;
763 case SDP_EVENT_QUERY_COMPLETE:
764 status = sdp_event_query_complete_get_status(packet);
765 if (status != ERROR_CODE_SUCCESS) break;
766 if (!connection->source_supported || (connection->avdtp_l2cap_psm == 0)) {
767 status = SDP_SERVICE_NOT_FOUND;
768 break;
769 }
770 break;
771 default:
772 btstack_assert(false);
773 return;
762 if (status == ERROR_CODE_SUCCESS) {
763 if (!connection->source_supported || (connection->avdtp_l2cap_psm == 0)) {
764 status = SDP_SERVICE_NOT_FOUND;
765 }
774 }
775 break;
766 }
767 break;
776
777 case AVDTP_SIGNALING_CONNECTION_OPENED:
768 case AVDTP_SIGNALING_CONNECTION_OPENED:
778 switch (hci_event_packet_get_type(packet)){
779 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
780 avdtp_handle_sdp_client_query_attribute_value(connection, packet);
781 return;
782 case SDP_EVENT_QUERY_COMPLETE:
783 // without suitable SDP Record, avdtp version v0.0 is assumed
784 status = sdp_event_query_complete_get_status(packet);
785 break;
786 default:
787 btstack_assert(false);
788 return;
789 }
769 // without suitable SDP Record, avdtp version v0.0 is assumed
790 break;
770 break;
791
792 default:
771 default:
793 // bail out, we must have had an incoming connection in the meantime; just trigger next sdp query on complete
794 if (hci_event_packet_get_type(packet) == SDP_EVENT_QUERY_COMPLETE){
795 (void) sdp_client_register_query_callback(&avdtp_handle_sdp_client_query_request);
796 }
797 return;
772 // we must have had an incoming connection in the meantime -> bail out
773 // just trigger next sdp query on complete
774 handle_query_complete = false;
775 break;
798 }
799
776 }
777
800 if (status == ERROR_CODE_SUCCESS){
801 avdtp_handle_sdp_query_succeeded(connection);
802 } else {
803 avdtp_handle_sdp_query_failed(connection, status);
778 if (handle_query_complete){
779 if (status == ERROR_CODE_SUCCESS){
780 avdtp_handle_sdp_query_succeeded(connection);
781 } else {
782 avdtp_handle_sdp_query_failed(connection, status);
783 }
804 }
805
806 // register the SDP Query request to check if there is another connection waiting for the query
784 }
785
786 // register the SDP Query request to check if there is another connection waiting for the query
807 // ignore ERROR_CODE_COMMAND_DISALLOWED because in that case, we already have requested an SDP callback
808 (void) sdp_client_register_query_callback(&avdtp_handle_sdp_client_query_request);
787 if (avdtp_get_next_connection_ready_for_sdp_query() != NULL){
788 // ignore ERROR_CODE_COMMAND_DISALLOWED because in that case, we already have requested an SDP callback
789 (void) sdp_client_register_query_callback(&avdtp_handle_sdp_client_query_request);
790 }
809}
810
811static avdtp_connection_t * avdtp_handle_incoming_connection(avdtp_connection_t * connection, bd_addr_t event_addr, hci_con_handle_t con_handle, uint16_t local_cid){
812 if (connection == NULL){
813 uint16_t cid = avdtp_get_next_cid();
814 connection = avdtp_create_connection(event_addr, cid);
815 }
816

--- 904 unchanged lines hidden ---
791}
792
793static avdtp_connection_t * avdtp_handle_incoming_connection(avdtp_connection_t * connection, bd_addr_t event_addr, hci_con_handle_t con_handle, uint16_t local_cid){
794 if (connection == NULL){
795 uint16_t cid = avdtp_get_next_cid();
796 connection = avdtp_create_connection(event_addr, cid);
797 }
798

--- 904 unchanged lines hidden ---