avrcp.c (b84b7ce1d289a76bed9cf7fb0cf025645d318c28) | avrcp.c (e39127d3f38bcf687ba523982b74f1bc66b69ba7) |
---|---|
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 --- 969 unchanged lines hidden (view full) --- 978 UNUSED(channel); 979 UNUSED(size); 980 bd_addr_t event_addr; 981 uint16_t local_cid; 982 uint16_t l2cap_mtu; 983 uint8_t status; 984 bool decline_connection; 985 bool outoing_active; | 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 --- 969 unchanged lines hidden (view full) --- 978 UNUSED(channel); 979 UNUSED(size); 980 bd_addr_t event_addr; 981 uint16_t local_cid; 982 uint16_t l2cap_mtu; 983 uint8_t status; 984 bool decline_connection; 985 bool outoing_active; |
986 bool connection_already_established; |
|
986 hci_con_handle_t con_handle; 987 988 avrcp_connection_t * connection_controller; 989 avrcp_connection_t * connection_target; 990 bool can_send; 991 992 switch (packet_type) { 993 case HCI_EVENT_PACKET: 994 switch (hci_event_packet_get_type(packet)) { 995 996 case L2CAP_EVENT_INCOMING_CONNECTION: 997 btstack_assert(avrcp_controller_packet_handler != NULL); 998 btstack_assert(avrcp_target_packet_handler != NULL); 999 1000 l2cap_event_incoming_connection_get_address(packet, event_addr); 1001 local_cid = l2cap_event_incoming_connection_get_local_cid(packet); 1002 con_handle = l2cap_event_incoming_connection_get_handle(packet); 1003 1004 outoing_active = false; | 987 hci_con_handle_t con_handle; 988 989 avrcp_connection_t * connection_controller; 990 avrcp_connection_t * connection_target; 991 bool can_send; 992 993 switch (packet_type) { 994 case HCI_EVENT_PACKET: 995 switch (hci_event_packet_get_type(packet)) { 996 997 case L2CAP_EVENT_INCOMING_CONNECTION: 998 btstack_assert(avrcp_controller_packet_handler != NULL); 999 btstack_assert(avrcp_target_packet_handler != NULL); 1000 1001 l2cap_event_incoming_connection_get_address(packet, event_addr); 1002 local_cid = l2cap_event_incoming_connection_get_local_cid(packet); 1003 con_handle = l2cap_event_incoming_connection_get_handle(packet); 1004 1005 outoing_active = false; |
1006 connection_already_established = false; 1007 |
|
1005 connection_target = avrcp_get_connection_for_bd_addr_for_role(AVRCP_TARGET, event_addr); 1006 if (connection_target != NULL){ 1007 if (connection_target->state == AVCTP_CONNECTION_W4_L2CAP_CONNECTED){ 1008 outoing_active = true; 1009 connection_target->incoming_declined = true; 1010 } | 1008 connection_target = avrcp_get_connection_for_bd_addr_for_role(AVRCP_TARGET, event_addr); 1009 if (connection_target != NULL){ 1010 if (connection_target->state == AVCTP_CONNECTION_W4_L2CAP_CONNECTED){ 1011 outoing_active = true; 1012 connection_target->incoming_declined = true; 1013 } |
1014 if (connection_target->state >= AVCTP_CONNECTION_OPENED){ 1015 connection_already_established = true; 1016 } |
|
1011 } 1012 1013 connection_controller = avrcp_get_connection_for_bd_addr_for_role(AVRCP_CONTROLLER, event_addr); 1014 if (connection_controller != NULL){ 1015 if (connection_controller->state == AVCTP_CONNECTION_W4_L2CAP_CONNECTED) { 1016 outoing_active = true; 1017 connection_controller->incoming_declined = true; 1018 } | 1017 } 1018 1019 connection_controller = avrcp_get_connection_for_bd_addr_for_role(AVRCP_CONTROLLER, event_addr); 1020 if (connection_controller != NULL){ 1021 if (connection_controller->state == AVCTP_CONNECTION_W4_L2CAP_CONNECTED) { 1022 outoing_active = true; 1023 connection_controller->incoming_declined = true; 1024 } |
1025 if (connection_controller->state >= AVCTP_CONNECTION_OPENED){ 1026 connection_already_established = true; 1027 } |
|
1019 } 1020 | 1028 } 1029 |
1021 decline_connection = outoing_active; | 1030 decline_connection = outoing_active || connection_already_established; |
1022 if (decline_connection == false){ 1023 uint16_t avrcp_cid; 1024 if ((connection_controller == NULL) || (connection_target == NULL)){ 1025 avrcp_cid = avrcp_get_next_cid(AVRCP_CONTROLLER); 1026 } else { 1027 avrcp_cid = connection_controller->avrcp_cid; 1028 } 1029 // create two connection objects (both) --- 5 unchanged lines hidden (view full) --- 1035 avrcp_finalize_connection(connection_target); 1036 } 1037 if (connection_controller) { 1038 avrcp_finalize_connection(connection_controller); 1039 } 1040 } 1041 } 1042 if (decline_connection){ | 1031 if (decline_connection == false){ 1032 uint16_t avrcp_cid; 1033 if ((connection_controller == NULL) || (connection_target == NULL)){ 1034 avrcp_cid = avrcp_get_next_cid(AVRCP_CONTROLLER); 1035 } else { 1036 avrcp_cid = connection_controller->avrcp_cid; 1037 } 1038 // create two connection objects (both) --- 5 unchanged lines hidden (view full) --- 1044 avrcp_finalize_connection(connection_target); 1045 } 1046 if (connection_controller) { 1047 avrcp_finalize_connection(connection_controller); 1048 } 1049 } 1050 } 1051 if (decline_connection){ |
1052 log_info("Decline connection 0x%04x: outgoing active %u, connection already established: %u", local_cid, outoing_active, connection_already_established); |
|
1043 l2cap_decline_connection(local_cid); 1044 } else { | 1053 l2cap_decline_connection(local_cid); 1054 } else { |
1045 log_info("AVRCP: L2CAP_EVENT_INCOMING_CONNECTION local cid 0x%02x, state %d", local_cid, connection_controller->state); | 1055 log_info("AVRCP: L2CAP_EVENT_INCOMING_CONNECTION local cid 0x%04x, state %d", local_cid, connection_controller->state); |
1046 l2cap_accept_connection(local_cid); 1047 } 1048 break; 1049 1050 case L2CAP_EVENT_CHANNEL_OPENED: 1051 l2cap_event_channel_opened_get_address(packet, event_addr); 1052 status = l2cap_event_channel_opened_get_status(packet); 1053 local_cid = l2cap_event_channel_opened_get_local_cid(packet); --- 223 unchanged lines hidden --- | 1056 l2cap_accept_connection(local_cid); 1057 } 1058 break; 1059 1060 case L2CAP_EVENT_CHANNEL_OPENED: 1061 l2cap_event_channel_opened_get_address(packet, event_addr); 1062 status = l2cap_event_channel_opened_get_status(packet); 1063 local_cid = l2cap_event_channel_opened_get_local_cid(packet); --- 223 unchanged lines hidden --- |