int hsp_hs_send_result(const char * result){ if (!hs_support_custom_indications) return 1; return hsp_hs_send_str_over_rfcomm(rfcomm_cid, result); }
static void hsp_run(void){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) return; if (wait_ok) return; if (hsp_release_audio_connection){ hsp_release_audio_connection = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } if (hsp_disconnect_rfcomm){ hsp_disconnect_rfcomm = 0; hsp_establish_audio_connection = 0; rfcomm_disconnect_internal(rfcomm_cid); return; } if (hsp_establish_audio_connection){ hsp_establish_audio_connection = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } if (hs_send_button_press){ hs_send_button_press = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } switch (hsp_state){ case HSP_SDP_QUERY_RFCOMM_CHANNEL: hsp_state = HSP_W4_SDP_QUERY_COMPLETE; sdp_query_rfcomm_channel_and_name_for_uuid(remote, SDP_Headset_AG); break; case HSP_AUDIO_CONNECTION_ESTABLISHED: case HSP_RFCOMM_CONNECTION_ESTABLISHED: if (hs_microphone_gain >= 0){ char buffer[20]; sprintf(buffer, "%s=%d\r\n", HSP_HS_MICROPHONE_GAIN, hs_microphone_gain); hsp_hs_send_str_over_rfcomm(rfcomm_cid, buffer); hs_microphone_gain = -1; break; } if (hs_speaker_gain >= 0){ char buffer[20]; sprintf(buffer, "%s=%d\r\n", HSP_HS_SPEAKER_GAIN, hs_speaker_gain); hsp_hs_send_str_over_rfcomm(rfcomm_cid, buffer); hs_speaker_gain = -1; break; } break; case HSP_W4_RFCOMM_DISCONNECTED: rfcomm_disconnect_internal(rfcomm_cid); break; default: break; } }
static void hsp_run(void){ if (wait_ok) return; if (hs_accept_sco_connection && hci_can_send_command_packet_now()){ hs_accept_sco_connection = 0; log_info("HSP: sending hci_accept_connection_request."); // 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; } if (hsp_release_audio_connection){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) { rfcomm_request_can_send_now_event(rfcomm_cid); return; } hsp_release_audio_connection = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } if (hsp_disconnect_rfcomm){ hsp_disconnect_rfcomm = 0; hsp_establish_audio_connection = 0; rfcomm_disconnect(rfcomm_cid); return; } if (hsp_establish_audio_connection){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) { rfcomm_request_can_send_now_event(rfcomm_cid); return; } hsp_establish_audio_connection = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } if (hs_send_button_press){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) { rfcomm_request_can_send_now_event(rfcomm_cid); return; } hs_send_button_press = 0; wait_ok = 1; hsp_hs_send_str_over_rfcomm(rfcomm_cid, HSP_HS_AT_CKPD); return; } switch (hsp_state){ case HSP_SDP_QUERY_RFCOMM_CHANNEL: hsp_state = HSP_W4_SDP_QUERY_COMPLETE; sdp_client_query_rfcomm_channel_and_name_for_uuid(&handle_query_rfcomm_event, remote, BLUETOOTH_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY_AG); break; case HSP_AUDIO_CONNECTION_ESTABLISHED: case HSP_RFCOMM_CONNECTION_ESTABLISHED: if (hs_microphone_gain >= 0){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) { rfcomm_request_can_send_now_event(rfcomm_cid); return; } char buffer[20]; sprintf(buffer, "%s=%d\r\n", HSP_HS_MICROPHONE_GAIN, hs_microphone_gain); hsp_hs_send_str_over_rfcomm(rfcomm_cid, buffer); hs_microphone_gain = -1; break; } if (hs_speaker_gain >= 0){ if (!rfcomm_can_send_packet_now(rfcomm_cid)) { rfcomm_request_can_send_now_event(rfcomm_cid); return; } char buffer[20]; sprintf(buffer, "%s=%d\r\n", HSP_HS_SPEAKER_GAIN, hs_speaker_gain); hsp_hs_send_str_over_rfcomm(rfcomm_cid, buffer); hs_speaker_gain = -1; break; } break; case HSP_W4_RFCOMM_DISCONNECTED: rfcomm_disconnect(rfcomm_cid); break; default: break; } }