hfp_ag.c (d84719b14b724e9967aeab5d871d19d77c4c56ef) hfp_ag.c (754910ca8c2e98c34d9eb8ef45245f28c915e225)
1/*
2 * Copyright (C) 2014 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

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

771 }
772 if (hfp_connection->vra_status != HFP_VRA_VOICE_RECOGNITION_ACTIVATED){
773 return ERROR_CODE_COMMAND_DISALLOWED;
774 }
775 hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
776 hfp_connection->vra_status = HFP_VRA_W4_VOICE_RECOGNITION_OFF;
777 return ERROR_CODE_SUCCESS;
778}
1/*
2 * Copyright (C) 2014 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

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

771 }
772 if (hfp_connection->vra_status != HFP_VRA_VOICE_RECOGNITION_ACTIVATED){
773 return ERROR_CODE_COMMAND_DISALLOWED;
774 }
775 hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
776 hfp_connection->vra_status = HFP_VRA_W4_VOICE_RECOGNITION_OFF;
777 return ERROR_CODE_SUCCESS;
778}
779
780static int hfp_ag_voice_recognition_send(hfp_connection_t * hfp_connection, int value){
781 int done = 0;
782 switch(hfp_connection->command){
783 case HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION:
784 done = hfp_ag_send_ok(hfp_connection->rfcomm_cid);
785 break;
786 case HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION:
787 done = hfp_ag_send_activate_voice_recognition_cmd(hfp_connection->rfcomm_cid, value);
788 break;
789 default:
790 btstack_unreachable();
791 break;
792 }
793 return done;
794}
795
796static int hfp_ag_voice_recognition_state_machine(hfp_connection_t * hfp_connection){
797 if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) {
798 return 0;
799 }
800 int done = 0;
801 uint8_t status;
802
803 switch (hfp_connection->vra_status){
804 case HFP_VRA_W4_VOICE_RECOGNITION_OFF:
805 done = hfp_ag_voice_recognition_send(hfp_connection, 0);
806 if (!done){
807 return 0;
808 }
809
810 hfp_connection->vra_status = HFP_VRA_VOICE_RECOGNITION_OFF;
811 hfp_trigger_release_audio_connection(hfp_connection);
812 hfp_emit_voice_recognition_state_event(hfp_connection, ERROR_CODE_SUCCESS, 0);
813 break;
814
815 case HFP_VRA_W4_VOICE_RECOGNITION_ACTIVATED:
816 done = hfp_ag_voice_recognition_send(hfp_connection, 1);
817
818 if (!done){
819 hfp_connection->vra_status = HFP_VRA_VOICE_RECOGNITION_ACTIVATED;
820 }
821
822 status = hfp_ag_setup_audio_connection(hfp_connection);
823 if (status != ERROR_CODE_SUCCESS){
824 hfp_connection->vra_status = HFP_VRA_VOICE_RECOGNITION_ACTIVATED;
825 }
826 hfp_emit_voice_recognition_state_event(hfp_connection, status, 1);
827 break;
828
829 default:
830 if (hfp_connection->command == HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION){
831 done = hfp_ag_send_error(hfp_connection->rfcomm_cid);
832 }
833 break;
834 }
835 return done;
836}
837
779static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * hfp_connection){
780 int sent = codecs_exchange_state_machine(hfp_connection);
781 if (sent) return 1;
782
783 switch(hfp_connection->command){
784
785 case HFP_CMD_AG_ACTIVATE_ENHANCED_VOICE_RECOGNITION:
786 switch (hfp_connection->ag_vra_status){

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

802 hfp_connection->ag_vra_status = HFP_VRA_ENHANCED_VOICE_RECOGNITION_ACTIVATED;
803 hfp_ag_send_enhanced_voice_recognition_msg_cmd(hfp_connection);
804 break;
805 default:
806 return 0;
807 }
808 return 1;
809
838static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * hfp_connection){
839 int sent = codecs_exchange_state_machine(hfp_connection);
840 if (sent) return 1;
841
842 switch(hfp_connection->command){
843
844 case HFP_CMD_AG_ACTIVATE_ENHANCED_VOICE_RECOGNITION:
845 switch (hfp_connection->ag_vra_status){

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

861 hfp_connection->ag_vra_status = HFP_VRA_ENHANCED_VOICE_RECOGNITION_ACTIVATED;
862 hfp_ag_send_enhanced_voice_recognition_msg_cmd(hfp_connection);
863 break;
864 default:
865 return 0;
866 }
867 return 1;
868
810 case HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION:
811
812 if (get_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION)){
813 hfp_ag_send_ok(hfp_connection->rfcomm_cid);
814 } else {
815 switch (hfp_connection->ag_vra_status){
816 case HFP_VRA_ENHANCED_VOICE_RECOGNITION_ACTIVATED:
817 hfp_ag_send_ok(hfp_connection->rfcomm_cid);
818 break;
819 default:
820 hfp_ag_send_error(hfp_connection->rfcomm_cid);
821 break;
822 }
823 }
824 return 1;
825 case HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING:
826 hfp_ag_send_change_in_band_ring_tone_setting_cmd(hfp_connection->rfcomm_cid);
827 return 1;
828 case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME:
829 hfp_ag_send_report_network_operator_name_cmd(hfp_connection->rfcomm_cid, hfp_connection->network_operator);
830 return 1;
831 case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT:
832 if (hfp_connection->network_operator.format != 0){

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

2026
2027 // parse until end of line
2028 if (!hfp_parser_is_end_of_line(packet[pos])) continue;
2029
2030 hfp_generic_status_indicator_t * indicator;
2031 switch(hfp_connection->command){
2032 case HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION:
2033 if (hfp_connection->ag_activate_voice_recognition == 0){
869 case HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING:
870 hfp_ag_send_change_in_band_ring_tone_setting_cmd(hfp_connection->rfcomm_cid);
871 return 1;
872 case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME:
873 hfp_ag_send_report_network_operator_name_cmd(hfp_connection->rfcomm_cid, hfp_connection->network_operator);
874 return 1;
875 case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT:
876 if (hfp_connection->network_operator.format != 0){

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

2070
2071 // parse until end of line
2072 if (!hfp_parser_is_end_of_line(packet[pos])) continue;
2073
2074 hfp_generic_status_indicator_t * indicator;
2075 switch(hfp_connection->command){
2076 case HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION:
2077 if (hfp_connection->ag_activate_voice_recognition == 0){
2034 hfp_trigger_release_audio_connection(hfp_connection);
2078 hfp_ag_deactivate_voice_recognition_for_connection(hfp_connection);
2079 } else {
2080 hfp_ag_activate_voice_recognition_for_connection(hfp_connection);
2035 }
2036 break;
2037 case HFP_CMD_RESPONSE_AND_HOLD_QUERY:
2038 if (hfp_ag_response_and_hold_active){
2039 hfp_connection->send_response_and_hold_status = HFP_RESPONSE_AND_HOLD_INCOMING_ON_HOLD + 1;
2040 }
2041 hfp_connection->ok_pending = 1;
2042 break;

--- 782 unchanged lines hidden ---
2081 }
2082 break;
2083 case HFP_CMD_RESPONSE_AND_HOLD_QUERY:
2084 if (hfp_ag_response_and_hold_active){
2085 hfp_connection->send_response_and_hold_status = HFP_RESPONSE_AND_HOLD_INCOMING_ON_HOLD + 1;
2086 }
2087 hfp_connection->ok_pending = 1;
2088 break;

--- 782 unchanged lines hidden ---