mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
hfp: use hfp_connection instead of connection/context
This commit is contained in:
parent
f1189ff18a
commit
206ba3fb6a
654
src/hfp_ag.c
654
src/hfp_ag.c
File diff suppressed because it is too large
Load Diff
588
src/hfp_hf.c
588
src/hfp_hf.c
@ -91,6 +91,20 @@ void hfp_hf_register_packet_handler(hfp_callback_t callback){
|
||||
hfp_callback = callback;
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_subscriber_number(hfp_connection_t * hfp_connection){
|
||||
printf("Subscriber Number: number %s, type %u\n", hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_response_and_hold_status(hfp_connection_t * hfp_connection){
|
||||
printf("Response and Hold status: %s\n", hfp_connection->line_buffer);
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_enhanced_call_status(hfp_connection_t * hfp_connection){
|
||||
printf("Enhanced Call Status: idx %u, dir %u, status %u, mpty %u, number %s, type %u\n",
|
||||
hfp_connection->clcc_idx, hfp_connection->clcc_dir, hfp_connection->clcc_status, hfp_connection->clcc_mpty,
|
||||
hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
}
|
||||
|
||||
static int hfp_hf_supports_codec(uint8_t codec){
|
||||
int i;
|
||||
for (i = 0; i < hfp_codecs_nr; i++){
|
||||
@ -351,47 +365,47 @@ static void hfp_emit_network_operator_event(hfp_callback_t callback, hfp_network
|
||||
(*callback)(event, sizeof(event));
|
||||
}
|
||||
|
||||
static int hfp_hf_run_for_context_service_level_connection(hfp_connection_t * context){
|
||||
if (context->state >= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
if (context->ok_pending) return 0;
|
||||
static int hfp_hf_run_for_context_service_level_connection(hfp_connection_t * hfp_connection){
|
||||
if (hfp_connection->state >= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
if (hfp_connection->ok_pending) return 0;
|
||||
int done = 1;
|
||||
|
||||
switch (context->state){
|
||||
switch (hfp_connection->state){
|
||||
case HFP_EXCHANGE_SUPPORTED_FEATURES:
|
||||
context->state = HFP_W4_EXCHANGE_SUPPORTED_FEATURES;
|
||||
hfp_hf_cmd_exchange_supported_features(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_EXCHANGE_SUPPORTED_FEATURES;
|
||||
hfp_hf_cmd_exchange_supported_features(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_NOTIFY_ON_CODECS:
|
||||
context->state = HFP_W4_NOTIFY_ON_CODECS;
|
||||
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_NOTIFY_ON_CODECS;
|
||||
hfp_hf_cmd_notify_on_codecs(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_RETRIEVE_INDICATORS:
|
||||
context->state = HFP_W4_RETRIEVE_INDICATORS;
|
||||
hfp_hf_cmd_retrieve_indicators(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RETRIEVE_INDICATORS;
|
||||
hfp_hf_cmd_retrieve_indicators(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_RETRIEVE_INDICATORS_STATUS:
|
||||
context->state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
|
||||
hfp_hf_cmd_retrieve_indicators_status(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
|
||||
hfp_hf_cmd_retrieve_indicators_status(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_ENABLE_INDICATORS_STATUS_UPDATE:
|
||||
context->state = HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE;
|
||||
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, 1);
|
||||
hfp_connection->state = HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE;
|
||||
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(hfp_connection->rfcomm_cid, 1);
|
||||
break;
|
||||
case HFP_RETRIEVE_CAN_HOLD_CALL:
|
||||
context->state = HFP_W4_RETRIEVE_CAN_HOLD_CALL;
|
||||
hfp_hf_cmd_retrieve_can_hold_call(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RETRIEVE_CAN_HOLD_CALL;
|
||||
hfp_hf_cmd_retrieve_can_hold_call(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_LIST_GENERIC_STATUS_INDICATORS:
|
||||
context->state = HFP_W4_LIST_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_list_supported_generic_status_indicators(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_LIST_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_list_supported_generic_status_indicators(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_RETRIEVE_GENERIC_STATUS_INDICATORS:
|
||||
context->state = HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_retrieve_supported_generic_status_indicators(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_retrieve_supported_generic_status_indicators(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
case HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS:
|
||||
context->state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_list_initital_supported_generic_status_indicators(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_hf_cmd_list_initital_supported_generic_status_indicators(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
default:
|
||||
done = 0;
|
||||
@ -401,52 +415,52 @@ static int hfp_hf_run_for_context_service_level_connection(hfp_connection_t * co
|
||||
}
|
||||
|
||||
|
||||
static int hfp_hf_run_for_context_service_level_connection_queries(hfp_connection_t * context){
|
||||
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
if (context->ok_pending) return 0;
|
||||
static int hfp_hf_run_for_context_service_level_connection_queries(hfp_connection_t * hfp_connection){
|
||||
if (hfp_connection->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
if (hfp_connection->ok_pending) return 0;
|
||||
|
||||
int done = 0;
|
||||
if (context->enable_status_update_for_ag_indicators != 0xFF){
|
||||
context->ok_pending = 1;
|
||||
if (hfp_connection->enable_status_update_for_ag_indicators != 0xFF){
|
||||
hfp_connection->ok_pending = 1;
|
||||
done = 1;
|
||||
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, context->enable_status_update_for_ag_indicators);
|
||||
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(hfp_connection->rfcomm_cid, hfp_connection->enable_status_update_for_ag_indicators);
|
||||
return done;
|
||||
};
|
||||
if (context->change_status_update_for_individual_ag_indicators){
|
||||
context->ok_pending = 1;
|
||||
if (hfp_connection->change_status_update_for_individual_ag_indicators){
|
||||
hfp_connection->ok_pending = 1;
|
||||
done = 1;
|
||||
hfp_hf_cmd_activate_status_update_for_ag_indicator(context->rfcomm_cid,
|
||||
context->ag_indicators_status_update_bitmap,
|
||||
context->ag_indicators_nr);
|
||||
hfp_hf_cmd_activate_status_update_for_ag_indicator(hfp_connection->rfcomm_cid,
|
||||
hfp_connection->ag_indicators_status_update_bitmap,
|
||||
hfp_connection->ag_indicators_nr);
|
||||
return done;
|
||||
}
|
||||
|
||||
switch (context->hf_query_operator_state){
|
||||
switch (hfp_connection->hf_query_operator_state){
|
||||
case HFP_HF_QUERY_OPERATOR_SET_FORMAT:
|
||||
context->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_cmd_query_operator_name_format(context->rfcomm_cid);
|
||||
hfp_connection->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_cmd_query_operator_name_format(hfp_connection->rfcomm_cid);
|
||||
return 1;
|
||||
case HFP_HF_QUERY_OPERATOR_SEND_QUERY:
|
||||
context->hf_query_operator_state = HPF_HF_QUERY_OPERATOR_W4_RESULT;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_cmd_query_operator_name(context->rfcomm_cid);
|
||||
hfp_connection->hf_query_operator_state = HPF_HF_QUERY_OPERATOR_W4_RESULT;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_cmd_query_operator_name(hfp_connection->rfcomm_cid);
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (context->enable_extended_audio_gateway_error_report){
|
||||
context->ok_pending = 1;
|
||||
if (hfp_connection->enable_extended_audio_gateway_error_report){
|
||||
hfp_connection->ok_pending = 1;
|
||||
done = 1;
|
||||
hfp_hf_cmd_enable_extended_audio_gateway_error_report(context->rfcomm_cid, context->enable_extended_audio_gateway_error_report);
|
||||
hfp_hf_cmd_enable_extended_audio_gateway_error_report(hfp_connection->rfcomm_cid, hfp_connection->enable_extended_audio_gateway_error_report);
|
||||
return done;
|
||||
}
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
static int codecs_exchange_state_machine(hfp_connection_t * context){
|
||||
static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
|
||||
/* events ( == commands):
|
||||
HFP_CMD_AVAILABLE_CODECS == received AT+BAC with list of codecs
|
||||
HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
|
||||
@ -455,39 +469,39 @@ static int codecs_exchange_state_machine(hfp_connection_t * context){
|
||||
HFP_CMD_HF_CONFIRMED_CODEC == received AT+BCS
|
||||
*/
|
||||
|
||||
if (context->ok_pending) return 0;
|
||||
if (hfp_connection->ok_pending) return 0;
|
||||
|
||||
switch (context->command){
|
||||
switch (hfp_connection->command){
|
||||
case HFP_CMD_AVAILABLE_CODECS:
|
||||
if (context->codecs_state == HFP_CODECS_W4_AG_COMMON_CODEC) return 0;
|
||||
if (hfp_connection->codecs_state == HFP_CODECS_W4_AG_COMMON_CODEC) return 0;
|
||||
|
||||
context->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
|
||||
hfp_connection->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_cmd_notify_on_codecs(hfp_connection->rfcomm_cid);
|
||||
return 1;
|
||||
case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
|
||||
context->codec_confirmed = 0;
|
||||
context->suggested_codec = 0;
|
||||
context->negotiated_codec = 0;
|
||||
hfp_connection->codec_confirmed = 0;
|
||||
hfp_connection->suggested_codec = 0;
|
||||
hfp_connection->negotiated_codec = 0;
|
||||
|
||||
context->codecs_state = HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_cmd_trigger_codec_connection_setup(context->rfcomm_cid);
|
||||
hfp_connection->codecs_state = HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_cmd_trigger_codec_connection_setup(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
|
||||
case HFP_CMD_AG_SUGGESTED_CODEC:
|
||||
if (hfp_hf_supports_codec(context->suggested_codec)){
|
||||
context->codec_confirmed = context->suggested_codec;
|
||||
context->ok_pending = 1;
|
||||
context->codecs_state = HFP_CODECS_HF_CONFIRMED_CODEC;
|
||||
hfp_hf_cmd_confirm_codec(context->rfcomm_cid, context->suggested_codec);
|
||||
if (hfp_hf_supports_codec(hfp_connection->suggested_codec)){
|
||||
hfp_connection->codec_confirmed = hfp_connection->suggested_codec;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_connection->codecs_state = HFP_CODECS_HF_CONFIRMED_CODEC;
|
||||
hfp_hf_cmd_confirm_codec(hfp_connection->rfcomm_cid, hfp_connection->suggested_codec);
|
||||
} else {
|
||||
context->codec_confirmed = 0;
|
||||
context->suggested_codec = 0;
|
||||
context->negotiated_codec = 0;
|
||||
context->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
|
||||
hfp_connection->codec_confirmed = 0;
|
||||
hfp_connection->suggested_codec = 0;
|
||||
hfp_connection->negotiated_codec = 0;
|
||||
hfp_connection->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_cmd_notify_on_codecs(hfp_connection->rfcomm_cid);
|
||||
|
||||
}
|
||||
break;
|
||||
@ -498,234 +512,234 @@ static int codecs_exchange_state_machine(hfp_connection_t * context){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hfp_hf_run_for_audio_connection(hfp_connection_t * context){
|
||||
if (context->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED ||
|
||||
context->state > HFP_W2_DISCONNECT_SCO) return 0;
|
||||
static int hfp_hf_run_for_audio_connection(hfp_connection_t * hfp_connection){
|
||||
if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED ||
|
||||
hfp_connection->state > HFP_W2_DISCONNECT_SCO) return 0;
|
||||
|
||||
|
||||
if (context->state == HFP_AUDIO_CONNECTION_ESTABLISHED && context->release_audio_connection){
|
||||
context->state = HFP_W4_SCO_DISCONNECTED;
|
||||
context->release_audio_connection = 0;
|
||||
gap_disconnect(context->sco_handle);
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED && hfp_connection->release_audio_connection){
|
||||
hfp_connection->state = HFP_W4_SCO_DISCONNECTED;
|
||||
hfp_connection->release_audio_connection = 0;
|
||||
gap_disconnect(hfp_connection->sco_handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (context->state == HFP_AUDIO_CONNECTION_ESTABLISHED) return 0;
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) return 0;
|
||||
|
||||
// run codecs exchange
|
||||
int done = codecs_exchange_state_machine(context);
|
||||
int done = codecs_exchange_state_machine(hfp_connection);
|
||||
if (done) return 1;
|
||||
|
||||
if (context->establish_audio_connection){
|
||||
context->state = HFP_W4_SCO_CONNECTED;
|
||||
context->establish_audio_connection = 0;
|
||||
hfp_setup_synchronous_connection(context->con_handle, context->link_setting);
|
||||
if (hfp_connection->establish_audio_connection){
|
||||
hfp_connection->state = HFP_W4_SCO_CONNECTED;
|
||||
hfp_connection->establish_audio_connection = 0;
|
||||
hfp_setup_synchronous_connection(hfp_connection->con_handle, hfp_connection->link_setting);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int call_setup_state_machine(hfp_connection_t * context){
|
||||
if (context->hf_answer_incoming_call){
|
||||
hfp_hf_cmd_ata(context->rfcomm_cid);
|
||||
context->hf_answer_incoming_call = 0;
|
||||
static int call_setup_state_machine(hfp_connection_t * hfp_connection){
|
||||
if (hfp_connection->hf_answer_incoming_call){
|
||||
hfp_hf_cmd_ata(hfp_connection->rfcomm_cid);
|
||||
hfp_connection->hf_answer_incoming_call = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hfp_run_for_context(hfp_connection_t * context){
|
||||
if (!context) return;
|
||||
if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
|
||||
static void hfp_run_for_context(hfp_connection_t * hfp_connection){
|
||||
if (!hfp_connection) return;
|
||||
if (!rfcomm_can_send_packet_now(hfp_connection->rfcomm_cid)) return;
|
||||
|
||||
int done = hfp_hf_run_for_context_service_level_connection(context);
|
||||
int done = hfp_hf_run_for_context_service_level_connection(hfp_connection);
|
||||
if (!done){
|
||||
done = hfp_hf_run_for_context_service_level_connection_queries(context);
|
||||
done = hfp_hf_run_for_context_service_level_connection_queries(hfp_connection);
|
||||
}
|
||||
if (!done){
|
||||
done = hfp_hf_run_for_audio_connection(context);
|
||||
done = hfp_hf_run_for_audio_connection(hfp_connection);
|
||||
}
|
||||
if (!done){
|
||||
done = call_setup_state_machine(context);
|
||||
done = call_setup_state_machine(hfp_connection);
|
||||
}
|
||||
|
||||
if (context->send_microphone_gain){
|
||||
context->send_microphone_gain = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_microphone_gain_cmd(context->rfcomm_cid, context->microphone_gain);
|
||||
if (hfp_connection->send_microphone_gain){
|
||||
hfp_connection->send_microphone_gain = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_microphone_gain_cmd(hfp_connection->rfcomm_cid, hfp_connection->microphone_gain);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->send_speaker_gain){
|
||||
context->send_speaker_gain = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_speaker_gain_cmd(context->rfcomm_cid, context->speaker_gain);
|
||||
if (hfp_connection->send_speaker_gain){
|
||||
hfp_connection->send_speaker_gain = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_speaker_gain_cmd(hfp_connection->rfcomm_cid, hfp_connection->speaker_gain);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_calling_line_notification){
|
||||
context->hf_deactivate_calling_line_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(context->rfcomm_cid, 0);
|
||||
if (hfp_connection->hf_deactivate_calling_line_notification){
|
||||
hfp_connection->hf_deactivate_calling_line_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(hfp_connection->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_calling_line_notification){
|
||||
context->hf_activate_calling_line_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(context->rfcomm_cid, 1);
|
||||
if (hfp_connection->hf_activate_calling_line_notification){
|
||||
hfp_connection->hf_activate_calling_line_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(hfp_connection->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_echo_canceling_and_noise_reduction){
|
||||
context->hf_deactivate_echo_canceling_and_noise_reduction = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(context->rfcomm_cid, 0);
|
||||
if (hfp_connection->hf_deactivate_echo_canceling_and_noise_reduction){
|
||||
hfp_connection->hf_deactivate_echo_canceling_and_noise_reduction = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(hfp_connection->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_echo_canceling_and_noise_reduction){
|
||||
context->hf_activate_echo_canceling_and_noise_reduction = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(context->rfcomm_cid, 1);
|
||||
if (hfp_connection->hf_activate_echo_canceling_and_noise_reduction){
|
||||
hfp_connection->hf_activate_echo_canceling_and_noise_reduction = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(hfp_connection->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_voice_recognition_notification){
|
||||
context->hf_deactivate_voice_recognition_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(context->rfcomm_cid, 0);
|
||||
if (hfp_connection->hf_deactivate_voice_recognition_notification){
|
||||
hfp_connection->hf_deactivate_voice_recognition_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_voice_recognition_notification){
|
||||
context->hf_activate_voice_recognition_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(context->rfcomm_cid, 1);
|
||||
if (hfp_connection->hf_activate_voice_recognition_notification){
|
||||
hfp_connection->hf_activate_voice_recognition_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (context->hf_deactivate_call_waiting_notification){
|
||||
context->hf_deactivate_call_waiting_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_call_waiting_notification_cmd(context->rfcomm_cid, 0);
|
||||
if (hfp_connection->hf_deactivate_call_waiting_notification){
|
||||
hfp_connection->hf_deactivate_call_waiting_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_call_waiting_notification_cmd(hfp_connection->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_call_waiting_notification){
|
||||
context->hf_activate_call_waiting_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_call_waiting_notification_cmd(context->rfcomm_cid, 1);
|
||||
if (hfp_connection->hf_activate_call_waiting_notification){
|
||||
hfp_connection->hf_activate_call_waiting_notification = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_set_call_waiting_notification_cmd(hfp_connection->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_initiate_outgoing_call){
|
||||
context->hf_initiate_outgoing_call = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_initiate_outgoing_call_cmd(context->rfcomm_cid);
|
||||
if (hfp_connection->hf_initiate_outgoing_call){
|
||||
hfp_connection->hf_initiate_outgoing_call = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_initiate_outgoing_call_cmd(hfp_connection->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_initiate_memory_dialing){
|
||||
context->hf_initiate_memory_dialing = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_memory_dial_cmd(context->rfcomm_cid, context->memory_id);
|
||||
if (hfp_connection->hf_initiate_memory_dialing){
|
||||
hfp_connection->hf_initiate_memory_dialing = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_memory_dial_cmd(hfp_connection->rfcomm_cid, hfp_connection->memory_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_initiate_redial_last_number){
|
||||
context->hf_initiate_redial_last_number = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_redial_last_number_cmd(context->rfcomm_cid);
|
||||
if (hfp_connection->hf_initiate_redial_last_number){
|
||||
hfp_connection->hf_initiate_redial_last_number = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_redial_last_number_cmd(hfp_connection->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chup){
|
||||
context->hf_send_chup = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chup(context->rfcomm_cid);
|
||||
if (hfp_connection->hf_send_chup){
|
||||
hfp_connection->hf_send_chup = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chup(hfp_connection->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_0){
|
||||
context->hf_send_chld_0 = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, 0);
|
||||
if (hfp_connection->hf_send_chld_0){
|
||||
hfp_connection->hf_send_chld_0 = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_1){
|
||||
context->hf_send_chld_1 = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, 1);
|
||||
if (hfp_connection->hf_send_chld_1){
|
||||
hfp_connection->hf_send_chld_1 = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_2){
|
||||
context->hf_send_chld_2 = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, 2);
|
||||
if (hfp_connection->hf_send_chld_2){
|
||||
hfp_connection->hf_send_chld_2 = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_3){
|
||||
context->hf_send_chld_3 = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, 3);
|
||||
if (hfp_connection->hf_send_chld_3){
|
||||
hfp_connection->hf_send_chld_3 = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, 3);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_4){
|
||||
context->hf_send_chld_4 = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, 4);
|
||||
if (hfp_connection->hf_send_chld_4){
|
||||
hfp_connection->hf_send_chld_4 = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chld_x){
|
||||
context->hf_send_chld_x = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_chld(context->rfcomm_cid, context->hf_send_chld_x_index);
|
||||
if (hfp_connection->hf_send_chld_x){
|
||||
hfp_connection->hf_send_chld_x = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_chld(hfp_connection->rfcomm_cid, hfp_connection->hf_send_chld_x_index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_dtmf_code){
|
||||
char code = context->hf_send_dtmf_code;
|
||||
context->hf_send_dtmf_code = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_dtmf(context->rfcomm_cid, code);
|
||||
if (hfp_connection->hf_send_dtmf_code){
|
||||
char code = hfp_connection->hf_send_dtmf_code;
|
||||
hfp_connection->hf_send_dtmf_code = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_dtmf(hfp_connection->rfcomm_cid, code);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_binp){
|
||||
context->hf_send_binp = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_binp(context->rfcomm_cid);
|
||||
if (hfp_connection->hf_send_binp){
|
||||
hfp_connection->hf_send_binp = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_binp(hfp_connection->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_clcc){
|
||||
context->hf_send_clcc = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_clcc(context->rfcomm_cid);
|
||||
if (hfp_connection->hf_send_clcc){
|
||||
hfp_connection->hf_send_clcc = 0;
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_hf_send_clcc(hfp_connection->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_rrh){
|
||||
context->hf_send_rrh = 0;
|
||||
if (hfp_connection->hf_send_rrh){
|
||||
hfp_connection->hf_send_rrh = 0;
|
||||
char buffer[20];
|
||||
switch (context->hf_send_rrh_command){
|
||||
switch (hfp_connection->hf_send_rrh_command){
|
||||
case '?':
|
||||
sprintf(buffer, "AT%s?\r\n", HFP_RESPONSE_AND_HOLD);
|
||||
send_str_over_rfcomm(context->rfcomm_cid, buffer);
|
||||
send_str_over_rfcomm(hfp_connection->rfcomm_cid, buffer);
|
||||
return;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
sprintf(buffer, "AT%s=%c\r\n", HFP_RESPONSE_AND_HOLD, context->hf_send_rrh_command);
|
||||
send_str_over_rfcomm(context->rfcomm_cid, buffer);
|
||||
sprintf(buffer, "AT%s=%c\r\n", HFP_RESPONSE_AND_HOLD, hfp_connection->hf_send_rrh_command);
|
||||
send_str_over_rfcomm(hfp_connection->rfcomm_cid, buffer);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
@ -733,25 +747,25 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_cnum){
|
||||
context->hf_send_cnum = 0;
|
||||
if (hfp_connection->hf_send_cnum){
|
||||
hfp_connection->hf_send_cnum = 0;
|
||||
char buffer[20];
|
||||
sprintf(buffer, "AT%s\r\n", HFP_SUBSCRIBER_NUMBER_INFORMATION);
|
||||
send_str_over_rfcomm(context->rfcomm_cid, buffer);
|
||||
send_str_over_rfcomm(hfp_connection->rfcomm_cid, buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// update HF indicators
|
||||
if (context->generic_status_update_bitmap){
|
||||
if (hfp_connection->generic_status_update_bitmap){
|
||||
int i;
|
||||
for (i=0;i<hfp_indicators_nr;i++){
|
||||
if (get_bit(context->generic_status_update_bitmap, i)){
|
||||
if (context->generic_status_indicators[i].state){
|
||||
context->ok_pending = 1;
|
||||
context->generic_status_update_bitmap = store_bit(context->generic_status_update_bitmap, i, 0);
|
||||
if (get_bit(hfp_connection->generic_status_update_bitmap, i)){
|
||||
if (hfp_connection->generic_status_indicators[i].state){
|
||||
hfp_connection->ok_pending = 1;
|
||||
hfp_connection->generic_status_update_bitmap = store_bit(hfp_connection->generic_status_update_bitmap, i, 0);
|
||||
char buffer[30];
|
||||
sprintf(buffer, "AT%s=%u,%u\r\n", HFP_TRANSFER_HF_INDICATOR_STATUS, hfp_indicators[i], hfp_indicators_value[i]);
|
||||
send_str_over_rfcomm(context->rfcomm_cid, buffer);
|
||||
send_str_over_rfcomm(hfp_connection->rfcomm_cid, buffer);
|
||||
} else {
|
||||
printf("Not sending HF indicator %u as it is disabled\n", hfp_indicators[i]);
|
||||
}
|
||||
@ -762,10 +776,10 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
|
||||
if (done) return;
|
||||
// deal with disconnect
|
||||
switch (context->state){
|
||||
switch (hfp_connection->state){
|
||||
case HFP_W2_DISCONNECT_RFCOMM:
|
||||
context->state = HFP_W4_RFCOMM_DISCONNECTED;
|
||||
rfcomm_disconnect_internal(context->rfcomm_cid);
|
||||
hfp_connection->state = HFP_W4_RFCOMM_DISCONNECTED;
|
||||
rfcomm_disconnect_internal(hfp_connection->rfcomm_cid);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -773,129 +787,129 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
}
|
||||
}
|
||||
|
||||
static void hfp_init_link_settings(hfp_connection_t * context){
|
||||
static void hfp_init_link_settings(hfp_connection_t * hfp_connection){
|
||||
// determine highest possible link setting
|
||||
context->link_setting = HFP_LINK_SETTINGS_D1;
|
||||
if (hci_remote_eSCO_supported(context->con_handle)){
|
||||
context->link_setting = HFP_LINK_SETTINGS_S3;
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_D1;
|
||||
if (hci_remote_eSCO_supported(hfp_connection->con_handle)){
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_S3;
|
||||
if ((hfp_supported_features & (1<<HFP_HFSF_ESCO_S4))
|
||||
&& (context->remote_supported_features & (1<<HFP_AGSF_ESCO_S4))){
|
||||
context->link_setting = HFP_LINK_SETTINGS_S4;
|
||||
&& (hfp_connection->remote_supported_features & (1<<HFP_AGSF_ESCO_S4))){
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_S4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void hfp_ag_slc_established(hfp_connection_t * context){
|
||||
context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
|
||||
static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
|
||||
hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0);
|
||||
hfp_init_link_settings(context);
|
||||
hfp_init_link_settings(hfp_connection);
|
||||
// restore volume settings
|
||||
context->speaker_gain = hfp_hf_speaker_gain;
|
||||
context->send_speaker_gain = 1;
|
||||
hfp_connection->speaker_gain = hfp_hf_speaker_gain;
|
||||
hfp_connection->send_speaker_gain = 1;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SPEAKER_VOLUME, hfp_hf_speaker_gain);
|
||||
context->microphone_gain = hfp_hf_microphone_gain;
|
||||
context->send_microphone_gain = 1;
|
||||
hfp_connection->microphone_gain = hfp_hf_microphone_gain;
|
||||
hfp_connection->send_microphone_gain = 1;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_MICROPHONE_VOLUME, hfp_hf_microphone_gain);
|
||||
// enable all indicators
|
||||
int i;
|
||||
for (i=0;i<hfp_indicators_nr;i++){
|
||||
context->generic_status_indicators[i].uuid = hfp_indicators[i];
|
||||
context->generic_status_indicators[i].state = 1;
|
||||
hfp_connection->generic_status_indicators[i].uuid = hfp_indicators[i];
|
||||
hfp_connection->generic_status_indicators[i].state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void hfp_hf_switch_on_ok(hfp_connection_t *context){
|
||||
context->ok_pending = 0;
|
||||
static void hfp_hf_switch_on_ok(hfp_connection_t *hfp_connection){
|
||||
hfp_connection->ok_pending = 0;
|
||||
int done = 1;
|
||||
switch (context->state){
|
||||
switch (hfp_connection->state){
|
||||
case HFP_W4_EXCHANGE_SUPPORTED_FEATURES:
|
||||
if (has_codec_negotiation_feature(context)){
|
||||
context->state = HFP_NOTIFY_ON_CODECS;
|
||||
if (has_codec_negotiation_feature(hfp_connection)){
|
||||
hfp_connection->state = HFP_NOTIFY_ON_CODECS;
|
||||
break;
|
||||
}
|
||||
context->state = HFP_RETRIEVE_INDICATORS;
|
||||
hfp_connection->state = HFP_RETRIEVE_INDICATORS;
|
||||
break;
|
||||
|
||||
case HFP_W4_NOTIFY_ON_CODECS:
|
||||
context->state = HFP_RETRIEVE_INDICATORS;
|
||||
hfp_connection->state = HFP_RETRIEVE_INDICATORS;
|
||||
break;
|
||||
|
||||
case HFP_W4_RETRIEVE_INDICATORS:
|
||||
context->state = HFP_RETRIEVE_INDICATORS_STATUS;
|
||||
hfp_connection->state = HFP_RETRIEVE_INDICATORS_STATUS;
|
||||
break;
|
||||
|
||||
case HFP_W4_RETRIEVE_INDICATORS_STATUS:
|
||||
context->state = HFP_ENABLE_INDICATORS_STATUS_UPDATE;
|
||||
hfp_connection->state = HFP_ENABLE_INDICATORS_STATUS_UPDATE;
|
||||
break;
|
||||
|
||||
case HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE:
|
||||
if (has_call_waiting_and_3way_calling_feature(context)){
|
||||
context->state = HFP_RETRIEVE_CAN_HOLD_CALL;
|
||||
if (has_call_waiting_and_3way_calling_feature(hfp_connection)){
|
||||
hfp_connection->state = HFP_RETRIEVE_CAN_HOLD_CALL;
|
||||
break;
|
||||
}
|
||||
if (has_hf_indicators_feature(context)){
|
||||
context->state = HFP_LIST_GENERIC_STATUS_INDICATORS;
|
||||
if (has_hf_indicators_feature(hfp_connection)){
|
||||
hfp_connection->state = HFP_LIST_GENERIC_STATUS_INDICATORS;
|
||||
break;
|
||||
}
|
||||
hfp_ag_slc_established(context);
|
||||
hfp_ag_slc_established(hfp_connection);
|
||||
break;
|
||||
|
||||
case HFP_W4_RETRIEVE_CAN_HOLD_CALL:
|
||||
if (has_hf_indicators_feature(context)){
|
||||
context->state = HFP_LIST_GENERIC_STATUS_INDICATORS;
|
||||
if (has_hf_indicators_feature(hfp_connection)){
|
||||
hfp_connection->state = HFP_LIST_GENERIC_STATUS_INDICATORS;
|
||||
break;
|
||||
}
|
||||
hfp_ag_slc_established(context);
|
||||
hfp_ag_slc_established(hfp_connection);
|
||||
break;
|
||||
|
||||
case HFP_W4_LIST_GENERIC_STATUS_INDICATORS:
|
||||
context->state = HFP_RETRIEVE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_connection->state = HFP_RETRIEVE_GENERIC_STATUS_INDICATORS;
|
||||
break;
|
||||
|
||||
case HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS:
|
||||
context->state = HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
|
||||
hfp_connection->state = HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
|
||||
break;
|
||||
|
||||
case HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS:
|
||||
hfp_ag_slc_established(context);
|
||||
hfp_ag_slc_established(hfp_connection);
|
||||
break;
|
||||
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
|
||||
if (context->enable_status_update_for_ag_indicators != 0xFF){
|
||||
context->enable_status_update_for_ag_indicators = 0xFF;
|
||||
if (hfp_connection->enable_status_update_for_ag_indicators != 0xFF){
|
||||
hfp_connection->enable_status_update_for_ag_indicators = 0xFF;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (context->change_status_update_for_individual_ag_indicators == 1){
|
||||
context->change_status_update_for_individual_ag_indicators = 0;
|
||||
if (hfp_connection->change_status_update_for_individual_ag_indicators == 1){
|
||||
hfp_connection->change_status_update_for_individual_ag_indicators = 0;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (context->hf_query_operator_state){
|
||||
switch (hfp_connection->hf_query_operator_state){
|
||||
case HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK:
|
||||
printf("Format set, querying name\n");
|
||||
context->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_SEND_QUERY;
|
||||
hfp_connection->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_SEND_QUERY;
|
||||
break;
|
||||
case HPF_HF_QUERY_OPERATOR_W4_RESULT:
|
||||
context->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_FORMAT_SET;
|
||||
hfp_emit_network_operator_event(hfp_callback, context->network_operator);
|
||||
hfp_connection->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_FORMAT_SET;
|
||||
hfp_emit_network_operator_event(hfp_callback, hfp_connection->network_operator);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (context->enable_extended_audio_gateway_error_report){
|
||||
context->enable_extended_audio_gateway_error_report = 0;
|
||||
if (hfp_connection->enable_extended_audio_gateway_error_report){
|
||||
hfp_connection->enable_extended_audio_gateway_error_report = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (context->codecs_state){
|
||||
switch (hfp_connection->codecs_state){
|
||||
case HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE:
|
||||
context->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
hfp_connection->codecs_state = HFP_CODECS_W4_AG_COMMON_CODEC;
|
||||
break;
|
||||
case HFP_CODECS_HF_CONFIRMED_CODEC:
|
||||
context->codecs_state = HFP_CODECS_EXCHANGED;
|
||||
hfp_connection->codecs_state = HFP_CODECS_EXCHANGED;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE, 0);
|
||||
break;
|
||||
default:
|
||||
@ -909,13 +923,13 @@ static void hfp_hf_switch_on_ok(hfp_connection_t *context){
|
||||
}
|
||||
|
||||
// done
|
||||
context->command = HFP_CMD_NONE;
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
}
|
||||
|
||||
|
||||
static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
hfp_connection_t * context = get_hfp_connection_context_for_rfcomm_cid(channel);
|
||||
if (!context) return;
|
||||
hfp_connection_t * hfp_connection = get_hfp_connection_context_for_rfcomm_cid(channel);
|
||||
if (!hfp_connection) return;
|
||||
|
||||
char last_char = packet[size-1];
|
||||
packet[size-1] = 0;
|
||||
@ -924,70 +938,68 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
|
||||
int pos, i, value;
|
||||
for (pos = 0; pos < size ; pos++){
|
||||
hfp_parse(context, packet[pos], 1);
|
||||
hfp_parse(hfp_connection, packet[pos], 1);
|
||||
}
|
||||
|
||||
switch (context->command){
|
||||
switch (hfp_connection->command){
|
||||
case HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION:
|
||||
context->command = HFP_CMD_NONE;
|
||||
printf("Subscriber Number: number %s, type %u\n", context->bnip_number, context->bnip_type);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_subscriber_number(hfp_connection);
|
||||
break;
|
||||
case HFP_CMD_RESPONSE_AND_HOLD_STATUS:
|
||||
context->command = HFP_CMD_NONE;
|
||||
printf("Response and Hold status: %s\n", context->line_buffer);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_response_and_hold_status(hfp_connection);
|
||||
break;
|
||||
case HFP_CMD_LIST_CURRENT_CALLS:
|
||||
context->command = HFP_CMD_NONE;
|
||||
printf("Enhanced Call Status: idx %u, dir %u, status %u, mpty %u, number %s, type %u\n",
|
||||
context->clcc_idx, context->clcc_dir, context->clcc_status, context->clcc_mpty,
|
||||
context->bnip_number, context->bnip_type);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_enhanced_call_status(hfp_connection);
|
||||
break;
|
||||
case HFP_CMD_SET_SPEAKER_GAIN:
|
||||
context->command = HFP_CMD_NONE;
|
||||
value = atoi((char*)context->line_buffer);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
value = atoi((char*)hfp_connection->line_buffer);
|
||||
hfp_hf_speaker_gain = value;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SPEAKER_VOLUME, value);
|
||||
break;
|
||||
case HFP_CMD_SET_MICROPHONE_GAIN:
|
||||
context->command = HFP_CMD_NONE;
|
||||
value = atoi((char*)context->line_buffer);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
value = atoi((char*)hfp_connection->line_buffer);
|
||||
hfp_hf_microphone_gain = value;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_MICROPHONE_VOLUME, value);
|
||||
break;
|
||||
case HFP_CMD_AG_SENT_PHONE_NUMBER:
|
||||
context->command = HFP_CMD_NONE;
|
||||
hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG, context->bnip_number);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG, hfp_connection->bnip_number);
|
||||
break;
|
||||
case HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR:
|
||||
context->ok_pending = 0;
|
||||
context->command = HFP_CMD_NONE;
|
||||
context->extended_audio_gateway_error = 0;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR, context->extended_audio_gateway_error_value);
|
||||
hfp_connection->ok_pending = 0;
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_connection->extended_audio_gateway_error = 0;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR, hfp_connection->extended_audio_gateway_error_value);
|
||||
break;
|
||||
case HFP_CMD_ERROR:
|
||||
context->ok_pending = 0;
|
||||
hfp_reset_context_flags(context);
|
||||
context->command = HFP_CMD_NONE;
|
||||
hfp_connection->ok_pending = 0;
|
||||
hfp_reset_context_flags(hfp_connection);
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
|
||||
break;
|
||||
case HFP_CMD_OK:
|
||||
hfp_hf_switch_on_ok(context);
|
||||
hfp_hf_switch_on_ok(hfp_connection);
|
||||
break;
|
||||
case HFP_CMD_RING:
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_RING, 0);
|
||||
break;
|
||||
case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS:
|
||||
for (i = 0; i < context->ag_indicators_nr; i++){
|
||||
if (context->ag_indicators[i].status_changed) {
|
||||
if (strcmp(context->ag_indicators[i].name, "callsetup") == 0){
|
||||
hfp_callsetup_status = (hfp_callsetup_status_t) context->ag_indicators[i].status;
|
||||
} else if (strcmp(context->ag_indicators[i].name, "callheld") == 0){
|
||||
hfp_callheld_status = (hfp_callheld_status_t) context->ag_indicators[i].status;
|
||||
} else if (strcmp(context->ag_indicators[i].name, "call") == 0){
|
||||
hfp_call_status = (hfp_call_status_t) context->ag_indicators[i].status;
|
||||
for (i = 0; i < hfp_connection->ag_indicators_nr; i++){
|
||||
if (hfp_connection->ag_indicators[i].status_changed) {
|
||||
if (strcmp(hfp_connection->ag_indicators[i].name, "callsetup") == 0){
|
||||
hfp_callsetup_status = (hfp_callsetup_status_t) hfp_connection->ag_indicators[i].status;
|
||||
} else if (strcmp(hfp_connection->ag_indicators[i].name, "callheld") == 0){
|
||||
hfp_callheld_status = (hfp_callheld_status_t) hfp_connection->ag_indicators[i].status;
|
||||
} else if (strcmp(hfp_connection->ag_indicators[i].name, "call") == 0){
|
||||
hfp_call_status = (hfp_call_status_t) hfp_connection->ag_indicators[i].status;
|
||||
}
|
||||
context->ag_indicators[i].status_changed = 0;
|
||||
hfp_emit_ag_indicator_event(hfp_callback, 0, context->ag_indicators[i]);
|
||||
hfp_connection->ag_indicators[i].status_changed = 0;
|
||||
hfp_emit_ag_indicator_event(hfp_callback, 0, hfp_connection->ag_indicators[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -995,7 +1007,7 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
default:
|
||||
break;
|
||||
}
|
||||
hfp_run_for_context(context);
|
||||
hfp_run_for_context(hfp_connection);
|
||||
}
|
||||
|
||||
static void hfp_run(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user