From abffc8194860aa979de23f5ebdb8af1d1c842818 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 28 Jul 2016 13:57:44 +0200 Subject: [PATCH] move sco accept connection to the upper layers (hfp, hsp) --- src/classic/hfp.c | 4 ++-- src/classic/hfp.h | 2 +- src/classic/hfp_ag.c | 21 ++++++++++++++++----- src/classic/hsp_ag.c | 30 +++++++++++++++++++++++++----- src/hci.c | 10 +--------- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/classic/hfp.c b/src/classic/hfp.c index 0b99cfa4f..c056f3940 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -525,7 +525,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet hfp_connection = provide_hfp_connection_context_for_bd_addr(event_addr); if (!hfp_connection) break; - hfp_connection->ag_establish_eSCO = 1; + hfp_connection->ag_establish_SCO = 1; break; case RFCOMM_EVENT_INCOMING_CONNECTION: @@ -590,7 +590,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet log_error("HFP: connection does not exist for remote with addr %s.", bd_addr_to_str(event_addr)); return; } - hfp_connection->ag_establish_eSCO = 0; + hfp_connection->ag_establish_SCO = 0; status = hci_event_synchronous_connection_complete_get_status(packet); if (status != 0){ diff --git a/src/classic/hfp.h b/src/classic/hfp.h index 83b67259d..ae331983d 100644 --- a/src/classic/hfp.h +++ b/src/classic/hfp.h @@ -561,7 +561,7 @@ typedef struct hfp_connection { uint8_t send_response_and_hold_status; // 0 - don't send. BRTH:0 == 1, .. // AG only - uint8_t ag_establish_eSCO; + uint8_t ag_establish_SCO; uint8_t change_in_band_ring_tone_setting; uint8_t ag_ring; uint8_t ag_send_clip; diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index e28f146b7..92d1ec70c 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -1626,17 +1626,28 @@ static void hfp_run_for_context(hfp_connection_t *hfp_connection){ if (!hfp_connection->rfcomm_cid) return; - if (hfp_connection->ag_establish_eSCO && hci_can_send_command_packet_now()){ + if (hfp_connection->ag_establish_SCO && hci_can_send_command_packet_now()){ // remote supported feature eSCO is set if link type is eSCO // eSCO: S4 - max latency == transmission interval = 0x000c == 12 ms, - uint16_t max_latency = 0x000c; - uint8_t retransmission_effort = 0x02; - uint16_t packet_types = 0x388; + uint16_t max_latency; + uint8_t retransmission_effort; + uint16_t packet_types; + + if (hci_remote_esco_supported(hfp_connection->acl_handle)){ + max_latency = 0x000c; + retransmission_effort = 0x02; + packet_types = 0x388; + } else { + max_latency = 0xffff; + retransmission_effort = 0xff; + packet_types = 0x003f; + } + uint16_t sco_voice_setting = hci_get_sco_voice_setting(); - if (hfp_connection->negotiated_codec == HFP_CODEC_MSBC){ sco_voice_setting = 0x0003; // Transparent data } + log_info("HFP: sending hci_accept_connection_request, sco_voice_setting %02x", sco_voice_setting); hci_send_cmd(&hci_accept_synchronous_connection, hfp_connection->remote_addr, 8000, 8000, max_latency, sco_voice_setting, retransmission_effort, packet_types); diff --git a/src/classic/hsp_ag.c b/src/classic/hsp_ag.c index 0f89810ad..7d5557a11 100644 --- a/src/classic/hsp_ag.c +++ b/src/classic/hsp_ag.c @@ -92,7 +92,7 @@ static uint8_t ag_send_ok = 0; static uint8_t ag_send_error = 0; static uint8_t ag_num_button_press_received = 0; static uint8_t ag_support_custom_commands = 0; -static uint8_t ag_establish_eSCO = 0; +static uint8_t ag_establish_SCO = 0; static uint8_t hsp_disconnect_rfcomm = 0; static uint8_t hsp_establish_audio_connection = 0; static uint8_t hsp_release_audio_connection = 0; @@ -381,9 +381,29 @@ void hsp_ag_stop_ringing(void){ } static void hsp_run(void){ - if (ag_establish_eSCO && hci_can_send_command_packet_now()){ + if (ag_establish_SCO && hci_can_send_command_packet_now()){ log_info("HSP: sending hci_accept_connection_request."); - hci_send_cmd(&hci_accept_synchronous_connection, sco_event_addr, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F); + // remote supported feature eSCO is set if link type is eSCO + // eSCO: S4 - max latency == transmission interval = 0x000c == 12 ms, + uint16_t max_latency; + uint8_t retransmission_effort; + uint16_t packet_types; + + if (hci_remote_esco_supported(rfcomm_handle)){ + max_latency = 0x000c; + retransmission_effort = 0x02; + packet_types = 0x388; + } else { + max_latency = 0xffff; + retransmission_effort = 0xff; + packet_types = 0x003f; + } + + uint16_t sco_voice_setting = hci_get_sco_voice_setting(); + + log_info("HFP: sending hci_accept_connection_request, sco_voice_setting %02x", sco_voice_setting); + hci_send_cmd(&hci_accept_synchronous_connection, remote, 8000, 8000, max_latency, + sco_voice_setting, retransmission_effort, packet_types); return; } @@ -566,10 +586,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack case HCI_EVENT_CONNECTION_REQUEST: printf("hsp HCI_EVENT_CONNECTION_REQUEST\n"); hci_event_connection_request_get_bd_addr(packet, sco_event_addr); - ag_establish_eSCO = 1; + ag_establish_SCO = 1; break; case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{ - ag_establish_eSCO = 0; + ag_establish_SCO = 0; uint8_t status = hci_event_synchronous_connection_complete_get_status(packet); if (status != 0){ log_error("(e)SCO Connection failed, status %u", status); diff --git a/src/hci.c b/src/hci.c index 2ba86637a..2b1e821e6 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2542,15 +2542,7 @@ static void hci_run(void){ connection->role = HCI_ROLE_SLAVE; if (connection->address_type == BD_ADDR_TYPE_CLASSIC){ hci_send_cmd(&hci_accept_connection_request, connection->address, 1); - } else { - // remote supported feature eSCO is set if link type is eSCO - if (connection->remote_supported_feature_eSCO) return; - // SCO: max latency, retransmission interval: N/A. any packet type - uint16_t max_latency = 0xffff; - uint8_t retransmission_effort = 0xff; - uint16_t packet_types = 0x003f; - hci_send_cmd(&hci_accept_synchronous_connection, connection->address, 8000, 8000, max_latency, hci_stack->sco_voice_setting, retransmission_effort, packet_types); - } + } return; #ifdef ENABLE_BLE