hfp_ag.c (ac6f828ea67656d19dc26c69b555123740cccce2) | hfp_ag.c (d84719b14b724e9967aeab5d871d19d77c4c56ef) |
---|---|
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 --- 732 unchanged lines hidden (view full) --- 741 return 1; 742 } 743 default: 744 break; 745 } 746 return 0; 747} 748 | 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 --- 732 unchanged lines hidden (view full) --- 741 return 1; 742 } 743 default: 744 break; 745 } 746 return 0; 747} 748 |
749static bool hfp_ag_voice_recognition_supported(hfp_connection_t * hfp_connection){ 750 int ag = get_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION); 751 int hf = get_bit(hfp_connection->remote_supported_features, HFP_HFSF_VOICE_RECOGNITION_FUNCTION); 752 return hf && ag; 753} 754 755static uint8_t hfp_ag_activate_voice_recognition_for_connection(hfp_connection_t * hfp_connection){ 756 if (!hfp_ag_voice_recognition_supported(hfp_connection)){ 757 return ERROR_CODE_COMMAND_DISALLOWED; 758 } 759 if (hfp_connection->vra_status != HFP_VRA_VOICE_RECOGNITION_OFF){ 760 return ERROR_CODE_COMMAND_DISALLOWED; 761 } 762 763 hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION; 764 hfp_connection->vra_status = HFP_VRA_W4_VOICE_RECOGNITION_ACTIVATED; 765 return ERROR_CODE_SUCCESS; 766} 767 768static uint8_t hfp_ag_deactivate_voice_recognition_for_connection(hfp_connection_t * hfp_connection){ 769 if (!hfp_ag_voice_recognition_supported(hfp_connection)){ 770 return ERROR_CODE_COMMAND_DISALLOWED; 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} |
|
749static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * hfp_connection){ 750 int sent = codecs_exchange_state_machine(hfp_connection); 751 if (sent) return 1; 752 753 switch(hfp_connection->command){ | 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){ |
754 case HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION: 755 hfp_ag_send_activate_voice_recognition_cmd(hfp_connection->rfcomm_cid, hfp_connection->ag_activate_voice_recognition); 756 if (hfp_connection->ag_activate_voice_recognition > 0){ 757 hfp_ag_setup_audio_connection(hfp_connection); 758 } else { 759 hfp_trigger_release_audio_connection(hfp_connection); 760 } 761 return 1; | |
762 763 case HFP_CMD_AG_ACTIVATE_ENHANCED_VOICE_RECOGNITION: 764 switch (hfp_connection->ag_vra_status){ 765 case HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_ACTIVATED: 766 hfp_connection->ag_vra_status = HFP_VRA_ENHANCED_VOICE_RECOGNITION_ACTIVATED; 767 hfp_ag_send_enhanced_voice_recognition_cmd(hfp_connection->rfcomm_cid, 1, hfp_connection->ag_vra_state); 768 hfp_ag_setup_audio_connection(hfp_connection); 769 break; --- 1165 unchanged lines hidden (view full) --- 1935 cmd_sent = hfp_ag_run_for_context_service_level_connection(hfp_connection); 1936 } 1937 1938 if (!cmd_sent){ 1939 cmd_sent = hfp_ag_run_for_context_service_level_connection_queries(hfp_connection); 1940 } 1941 1942 if (!cmd_sent){ | 784 785 case HFP_CMD_AG_ACTIVATE_ENHANCED_VOICE_RECOGNITION: 786 switch (hfp_connection->ag_vra_status){ 787 case HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_ACTIVATED: 788 hfp_connection->ag_vra_status = HFP_VRA_ENHANCED_VOICE_RECOGNITION_ACTIVATED; 789 hfp_ag_send_enhanced_voice_recognition_cmd(hfp_connection->rfcomm_cid, 1, hfp_connection->ag_vra_state); 790 hfp_ag_setup_audio_connection(hfp_connection); 791 break; --- 1165 unchanged lines hidden (view full) --- 1957 cmd_sent = hfp_ag_run_for_context_service_level_connection(hfp_connection); 1958 } 1959 1960 if (!cmd_sent){ 1961 cmd_sent = hfp_ag_run_for_context_service_level_connection_queries(hfp_connection); 1962 } 1963 1964 if (!cmd_sent){ |
1965 cmd_sent = hfp_ag_voice_recognition_state_machine(hfp_connection); 1966 } 1967 1968 if (!cmd_sent){ |
|
1943 cmd_sent = call_setup_state_machine(hfp_connection); 1944 } 1945 1946 // trigger codec exchange (must be before hfp_ag_run_for_audio_connection) 1947 if (!cmd_sent && (hfp_connection->command == HFP_CMD_NONE) && hfp_connection->trigger_codec_exchange){ 1948 switch (hfp_connection->codecs_state){ 1949 case HFP_CODECS_IDLE: 1950 case HFP_CODECS_RECEIVED_LIST: --- 579 unchanged lines hidden (view full) --- 2530uint8_t hfp_ag_set_battery_level(int battery_level){ 2531 if ((battery_level < 0) || (battery_level > 5)){ 2532 return ERROR_CODE_COMMAND_DISALLOWED; 2533 } 2534 hfp_ag_set_ag_indicator("battchg", battery_level); 2535 return ERROR_CODE_SUCCESS; 2536} 2537 | 1969 cmd_sent = call_setup_state_machine(hfp_connection); 1970 } 1971 1972 // trigger codec exchange (must be before hfp_ag_run_for_audio_connection) 1973 if (!cmd_sent && (hfp_connection->command == HFP_CMD_NONE) && hfp_connection->trigger_codec_exchange){ 1974 switch (hfp_connection->codecs_state){ 1975 case HFP_CODECS_IDLE: 1976 case HFP_CODECS_RECEIVED_LIST: --- 579 unchanged lines hidden (view full) --- 2556uint8_t hfp_ag_set_battery_level(int battery_level){ 2557 if ((battery_level < 0) || (battery_level > 5)){ 2558 return ERROR_CODE_COMMAND_DISALLOWED; 2559 } 2560 hfp_ag_set_ag_indicator("battchg", battery_level); 2561 return ERROR_CODE_SUCCESS; 2562} 2563 |
2538uint8_t hfp_ag_activate_voice_recognition(hci_con_handle_t acl_handle, int activate){ 2539 if (!get_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION)){ 2540 return ERROR_CODE_COMMAND_DISALLOWED; | 2564uint8_t hfp_ag_activate_voice_recognition(hci_con_handle_t acl_handle){ 2565 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle); 2566 if (!hfp_connection){ 2567 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; |
2541 } | 2568 } |
2569 uint8_t status = hfp_ag_activate_voice_recognition_for_connection(hfp_connection); 2570 if (status == ERROR_CODE_SUCCESS){ 2571 hfp_ag_run_for_context(hfp_connection); 2572 } 2573 return status; 2574} |
|
2542 | 2575 |
2576uint8_t hfp_ag_deactivate_voice_recognition(hci_con_handle_t acl_handle){ |
|
2543 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle); 2544 if (!hfp_connection){ 2545 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; 2546 } | 2577 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle); 2578 if (!hfp_connection){ 2579 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; 2580 } |
2547 2548 if (!get_bit(hfp_connection->remote_supported_features, HFP_HFSF_VOICE_RECOGNITION_FUNCTION)) { 2549 return ERROR_CODE_COMMAND_DISALLOWED; | 2581 uint8_t status = hfp_ag_deactivate_voice_recognition_for_connection(hfp_connection); 2582 if (status == ERROR_CODE_SUCCESS){ 2583 hfp_ag_run_for_context(hfp_connection); |
2550 } | 2584 } |
2551 2552 hfp_connection->ag_activate_voice_recognition = activate; 2553 hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION; 2554 hfp_ag_run_for_context(hfp_connection); 2555 return ERROR_CODE_SUCCESS; | 2585 return status; |
2556} 2557 | 2586} 2587 |
2588 |
|
2558uint8_t hfp_ag_enhanced_voice_recognition_activate(hci_con_handle_t acl_handle){ 2559 if (!get_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION)){ 2560 return ERROR_CODE_COMMAND_DISALLOWED; 2561 } 2562 2563 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle); 2564 if (!hfp_connection){ 2565 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; --- 228 unchanged lines hidden --- | 2589uint8_t hfp_ag_enhanced_voice_recognition_activate(hci_con_handle_t acl_handle){ 2590 if (!get_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION)){ 2591 return ERROR_CODE_COMMAND_DISALLOWED; 2592 } 2593 2594 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle); 2595 if (!hfp_connection){ 2596 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; --- 228 unchanged lines hidden --- |