avdtp.c (dbdb76a871f66859413f58c56dd81714c8ce2685) avdtp.c (95fdf9791c47e6796491183c8badffc8457528ea)
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

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

1079 break;
1080
1081 default:
1082 // other packet type
1083 break;
1084 }
1085}
1086
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

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

1079 break;
1080
1081 default:
1082 // other packet type
1083 break;
1084 }
1085}
1086
1087uint8_t avdtp_disconnect(uint16_t avdtp_cid){
1088 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_cid);
1089 if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1090
1091 if (connection->state == AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED) return ERROR_CODE_SUCCESS;
1092
1093 btstack_linked_list_iterator_t it;
1087void avdtp_disconenct_streamendpoints(const avdtp_connection_t *connection) {
1088 btstack_linked_list_iterator_t it;
1094 btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints());
1089 btstack_linked_list_iterator_init(&it, avdtp_get_stream_endpoints());
1095
1096 while (btstack_linked_list_iterator_has_next(&it)){
1097 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
1098 if (stream_endpoint->connection != connection) continue;
1090 while (btstack_linked_list_iterator_has_next(&it)){
1091 avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it);
1092 if (stream_endpoint->connection != connection) continue;
1099
1093
1100 switch (stream_endpoint->state){
1101 case AVDTP_STREAM_ENDPOINT_OPENED:
1102 case AVDTP_STREAM_ENDPOINT_STREAMING:
1103 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_DISCONNECTED;
1104 l2cap_disconnect(stream_endpoint->l2cap_media_cid);
1105 break;
1106 default:
1107 break;
1094 switch (stream_endpoint->state){
1095 case AVDTP_STREAM_ENDPOINT_OPENED:
1096 case AVDTP_STREAM_ENDPOINT_STREAMING:
1097 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_DISCONNECTED;
1098 l2cap_disconnect(stream_endpoint->l2cap_media_cid);
1099 break;
1100 default:
1101 break;
1108 }
1102 }
1109 }
1103 }
1104}
1110
1105
1111 connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED;
1112 l2cap_disconnect(connection->l2cap_signaling_cid);
1106uint8_t avdtp_disconnect(uint16_t avdtp_cid){
1107 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_cid);
1108 if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1109
1110 switch (connection->state){
1111 case AVDTP_SIGNALING_CONNECTION_OPENED:
1112 avdtp_disconenct_streamendpoints(connection);
1113 connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED;
1114 l2cap_disconnect(connection->l2cap_signaling_cid);
1115 break;
1116 case AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED:
1117 // stream endpoints closed, wait for disconnected
1118 break;
1119 default:
1120 // connection has not been reported as established yet, report open failed
1121 avdtp_signaling_emit_connection_established(connection->avdtp_cid, connection->remote_addr,
1122 connection->con_handle, ERROR_CODE_UNSPECIFIED_ERROR);
1123 avdtp_finalize_connection(connection);
1124 break;
1125 }
1113 return ERROR_CODE_SUCCESS;
1114}
1115
1116
1117#ifdef ENABLE_AVDTP_ACCEPTOR_EXPLICIT_START_STREAM_CONFIRMATION
1118static uint8_t avdtp_handle_explicit_start_stream_confirmation(uint16_t avdtp_cid, uint8_t local_seid, bool accept_stream_requested){
1119 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_cid);
1120 if (!connection){

--- 560 unchanged lines hidden ---
1126 return ERROR_CODE_SUCCESS;
1127}
1128
1129
1130#ifdef ENABLE_AVDTP_ACCEPTOR_EXPLICIT_START_STREAM_CONFIRMATION
1131static uint8_t avdtp_handle_explicit_start_stream_confirmation(uint16_t avdtp_cid, uint8_t local_seid, bool accept_stream_requested){
1132 avdtp_connection_t * connection = avdtp_get_connection_for_avdtp_cid(avdtp_cid);
1133 if (!connection){

--- 560 unchanged lines hidden ---