hfp_ag.c (5be6b47a7f686392b26eff93e7600ba14ec6b01b) hfp_ag.c (471dea41ab395d4c7fcbf32edf8a18b239742ccb)
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

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

870 uint8_t event[5];
871 event[0] = HCI_EVENT_HFP_META;
872 event[1] = sizeof(event) - 2;
873 event[2] = event_subtype;
874 little_endian_store_16(event, 3, HCI_CON_HANDLE_INVALID);
875 (*hfp_ag_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
876}
877
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

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

870 uint8_t event[5];
871 event[0] = HCI_EVENT_HFP_META;
872 event[1] = sizeof(event) - 2;
873 event[2] = event_subtype;
874 little_endian_store_16(event, 3, HCI_CON_HANDLE_INVALID);
875 (*hfp_ag_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
876}
877
878static void hfp_ag_emit_custom_command_event(hfp_connection_t * hfp_connection){
879 btstack_assert(sizeof(hfp_connection->line_buffer) < (255-5));
880
881 uint16_t line_len = strlen((const char*)hfp_connection->line_buffer) + 1;
882 uint8_t event[7 + sizeof(hfp_connection->line_buffer)];
883 event[0] = HCI_EVENT_HFP_META;
884 event[1] = 5 + line_len;
885 event[2] = HFP_SUBEVENT_CUSTOM_AT_COMMAND;
886 little_endian_store_16(event, 3, hfp_connection->acl_handle);
887 little_endian_store_16(event, 5, hfp_connection->ag_custom_at_command_id);
888 memcpy(&event[7], hfp_connection->line_buffer, line_len);
889 (*hfp_ag_callback)(HCI_EVENT_PACKET, 0, event, 7 + line_len);
890}
891
878// @return status
879static uint8_t hfp_ag_vra_state_machine_two(hfp_connection_t * hfp_connection){
880 uint8_t status = ERROR_CODE_SUCCESS;
881 switch (hfp_connection->vra_state_requested){
882 case HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO:
883 if (!hfp_ag_is_audio_connection_active(hfp_connection)){
884 status = hfp_ag_setup_audio_connection(hfp_connection);
885 if (status != ERROR_CODE_SUCCESS){

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

2498 hfp_emit_event(hfp_connection, HFP_SUBEVENT_SPEAKER_VOLUME, hfp_connection->speaker_gain);
2499 break;
2500 case HFP_CMD_SET_MICROPHONE_GAIN:
2501 hfp_connection->command = HFP_CMD_NONE;
2502 hfp_connection->ok_pending = 1;
2503 log_info("HF microphone gain = %u", hfp_connection->microphone_gain);
2504 hfp_emit_event(hfp_connection, HFP_SUBEVENT_MICROPHONE_VOLUME, hfp_connection->microphone_gain);
2505 break;
892// @return status
893static uint8_t hfp_ag_vra_state_machine_two(hfp_connection_t * hfp_connection){
894 uint8_t status = ERROR_CODE_SUCCESS;
895 switch (hfp_connection->vra_state_requested){
896 case HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO:
897 if (!hfp_ag_is_audio_connection_active(hfp_connection)){
898 status = hfp_ag_setup_audio_connection(hfp_connection);
899 if (status != ERROR_CODE_SUCCESS){

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

2512 hfp_emit_event(hfp_connection, HFP_SUBEVENT_SPEAKER_VOLUME, hfp_connection->speaker_gain);
2513 break;
2514 case HFP_CMD_SET_MICROPHONE_GAIN:
2515 hfp_connection->command = HFP_CMD_NONE;
2516 hfp_connection->ok_pending = 1;
2517 log_info("HF microphone gain = %u", hfp_connection->microphone_gain);
2518 hfp_emit_event(hfp_connection, HFP_SUBEVENT_MICROPHONE_VOLUME, hfp_connection->microphone_gain);
2519 break;
2520 case HFP_CMD_CUSTOM_MESSAGE:
2521 hfp_connection->command = HFP_CMD_NONE;
2522 hfp_parser_reset_line_buffer(hfp_connection);
2523 log_info("Custom AT Command ID 0x%04x", hfp_connection->ag_custom_at_command_id);
2524 hfp_ag_emit_custom_command_event(hfp_connection);
2525 break;
2506 case HFP_CMD_UNKNOWN:
2507 hfp_connection->command = HFP_CMD_NONE;
2508 hfp_connection->send_error = 1;
2509 break;
2510 default:
2511 break;
2512 }
2513 }

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

3112 if (hfp_connection->send_custom_message != NULL){
3113 return ERROR_CODE_COMMAND_DISALLOWED;
3114 }
3115 hfp_connection->send_custom_message = unsolicited_result_code;
3116 hfp_ag_run_for_context(hfp_connection);
3117 return ERROR_CODE_SUCCESS;
3118}
3119
2526 case HFP_CMD_UNKNOWN:
2527 hfp_connection->command = HFP_CMD_NONE;
2528 hfp_connection->send_error = 1;
2529 break;
2530 default:
2531 break;
2532 }
2533 }

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

3132 if (hfp_connection->send_custom_message != NULL){
3133 return ERROR_CODE_COMMAND_DISALLOWED;
3134 }
3135 hfp_connection->send_custom_message = unsolicited_result_code;
3136 hfp_ag_run_for_context(hfp_connection);
3137 return ERROR_CODE_SUCCESS;
3138}
3139
3140uint8_t hfp_ag_send_command_result_code(hci_con_handle_t acl_handle, bool ok){
3141 hfp_connection_t * hfp_connection = get_hfp_ag_connection_context_for_acl_handle(acl_handle);
3142 if (!hfp_connection){
3143 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
3144 }
3145 if (ok){
3146 hfp_connection->ok_pending = 1;
3147 } else {
3148 hfp_connection->send_error = 1;
3149 }
3150 hfp_ag_run_for_context(hfp_connection);
3151 return ERROR_CODE_SUCCESS;
3152}
3153
3120void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count){
3121 hfp_ag_subscriber_numbers = numbers;
3122 hfp_ag_subscriber_numbers_count = numbers_count;
3123}
3124
3125void hfp_ag_clear_last_dialed_number(void){
3126 hfp_gsm_clear_last_dialed_number();
3127}

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

3187
3188 hfp_ag_callback = callback;
3189 hfp_set_ag_callback(callback);
3190}
3191
3192void hfp_ag_register_custom_call_sm_handler(bool (*handler)(hfp_ag_call_event_t event)){
3193 hfp_ag_custom_call_sm_handler = handler;
3194}
3154void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count){
3155 hfp_ag_subscriber_numbers = numbers;
3156 hfp_ag_subscriber_numbers_count = numbers_count;
3157}
3158
3159void hfp_ag_clear_last_dialed_number(void){
3160 hfp_gsm_clear_last_dialed_number();
3161}

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

3221
3222 hfp_ag_callback = callback;
3223 hfp_set_ag_callback(callback);
3224}
3225
3226void hfp_ag_register_custom_call_sm_handler(bool (*handler)(hfp_ag_call_event_t event)){
3227 hfp_ag_custom_call_sm_handler = handler;
3228}
3229
3230void hfp_ag_register_custom_at_command(hfp_custom_at_command_t * custom_at_command){
3231 hfp_register_custom_ag_command(custom_at_command);
3232}