hfp: support attach phone number to voice tag by HF

This commit is contained in:
Matthias Ringwald 2015-11-28 14:14:55 +01:00
parent 6d6770b5f9
commit f36add6afd
6 changed files with 73 additions and 20 deletions

View File

@ -642,11 +642,12 @@ extern "C" {
#define HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER 0x0D
#define HFP_SUBEVENT_REDIAL_LAST_NUMBER 0x0E
#define HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 0x0F
#define HFP_SUBEVENT_TRANSMIT_DTMF_CODES 0x10
#define HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 0x11
#define HFP_SUBEVENT_CALL_ANSWERED 0x12
#define HFP_SUBEVENT_CONFERENCE_CALL 0x13
#define HFP_SUBEVENT_RING 0x14
#define HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG 0x10
#define HFP_SUBEVENT_TRANSMIT_DTMF_CODES 0x11
#define HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 0x12
#define HFP_SUBEVENT_CALL_ANSWERED 0x13
#define HFP_SUBEVENT_CONFERENCE_CALL 0x14
#define HFP_SUBEVENT_RING 0x15
// ANCS Client
#define ANCS_CLIENT_CONNECTED 0xF0

View File

@ -663,7 +663,7 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
}
if (strncmp(line_buffer+offset, HFP_PHONE_NUMBER_FOR_VOICE_TAG, strlen(HFP_PHONE_NUMBER_FOR_VOICE_TAG)) == 0){
if (isHandsFree) return HFP_CMD_AG_SEND_PHONE_NUMBER;
if (isHandsFree) return HFP_CMD_AG_SENT_PHONE_NUMBER;
return HFP_CMD_HF_REQUEST_PHONE_NUMBER;
}
@ -843,13 +843,8 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
return HFP_CMD_NONE;
}
#if 0
uint32_t fromBinary(char *s) {
return (uint32_t) strtol(s, NULL, 2);
}
#endif
static void hfp_parser_store_byte(hfp_connection_t * context, uint8_t byte){
// printf("hfp_parser_store_byte %c at pos %u\n", (char) byte, context->line_size);
// TODO: add limit
context->line_buffer[context->line_size++] = byte;
context->line_buffer[context->line_size] = 0;
@ -892,6 +887,7 @@ static void hfp_parser_next_state(hfp_connection_t * context, uint8_t byte){
break;
case HFP_PARSER_CMD_SEQUENCE:
switch (context->command){
case HFP_CMD_AG_SENT_PHONE_NUMBER:
case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS:
case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME:
case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT:
@ -1031,6 +1027,9 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
context->ag_indicators[context->parser_item_index].min_range = atoi((char *)context->line_buffer);
log_info("%s, ", context->line_buffer);
break;
case HFP_CMD_AG_SENT_PHONE_NUMBER:
context->bnip_type = (uint8_t)atoi((char*)context->line_buffer);
break;
default:
break;
}
@ -1194,6 +1193,10 @@ static void parse_sequence(hfp_connection_t * context){
context->ok_pending = 1;
context->extended_audio_gateway_error = 0;
break;
case HFP_CMD_AG_SENT_PHONE_NUMBER:
strncpy(context->bnip_number, (char *)context->line_buffer, sizeof(context->bnip_number));
context->bnip_number[sizeof(context->bnip_number)-1] = 0;
break;
default:
break;
}

View File

@ -187,7 +187,7 @@ typedef enum {
HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION,
HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION,
HFP_CMD_HF_REQUEST_PHONE_NUMBER,
HFP_CMD_AG_SEND_PHONE_NUMBER,
HFP_CMD_AG_SENT_PHONE_NUMBER,
HFP_CMD_TRANSMIT_DTMF_CODES,
HFP_CMD_SET_MICROPHONE_GAIN,
HFP_CMD_SET_SPEAKER_GAIN,
@ -564,6 +564,7 @@ typedef struct hfp_connection {
uint8_t hf_send_chld_3;
uint8_t hf_send_chld_4;
char hf_send_dtmf_code;
uint8_t hf_send_binp;
uint8_t hf_activate_call_waiting_notification;
uint8_t hf_deactivate_call_waiting_notification;
@ -573,7 +574,10 @@ typedef struct hfp_connection {
uint8_t hf_deactivate_echo_canceling_and_noise_reduction;
uint8_t hf_activate_voice_recognition_notification;
uint8_t hf_deactivate_voice_recognition_notification;
uint8_t bnip_type; // 0 == not set
char bnip_number[25]; //
} hfp_connection_t;
// UTILS_START : TODO move to utils

View File

@ -310,6 +310,12 @@ static int hfp_hf_send_dtmf(uint16_t cid, char code){
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_hf_send_binp(uint16_t cid){
char buffer[20];
sprintf(buffer, "AT%s=1\r\n", HFP_PHONE_NUMBER_FOR_VOICE_TAG);
return send_str_over_rfcomm(cid, buffer);
}
static void hfp_emit_ag_indicator_event(hfp_callback_t callback, int status, hfp_ag_indicator_t indicator){
if (!callback) return;
uint8_t event[6+HFP_MAX_INDICATOR_DESC_SIZE+1];
@ -678,6 +684,13 @@ static void hfp_run_for_context(hfp_connection_t * context){
return;
}
if (context->hf_send_binp){
context->hf_send_binp = 0;
context->ok_pending = 1;
hfp_hf_send_binp(context->rfcomm_cid);
return;
}
if (done) return;
// deal with disconnect
switch (context->state){
@ -830,16 +843,21 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
}
switch (context->command){
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);
break;
case HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR:
context->ok_pending = 0;
context->extended_audio_gateway_error = 0;
context->command = HFP_CMD_NONE;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR, context->extended_audio_gateway_error);
break;
case HFP_CMD_ERROR:
context->ok_pending = 0;
hfp_reset_context_flags(context);
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
context->command = HFP_CMD_NONE;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
break;
case HFP_CMD_OK:
hfp_hf_switch_on_ok(context);
@ -1278,9 +1296,20 @@ void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain){
/*
* @brief
*/
void hfp_hf_send_dtmf_code(bd_addr_t bd_addr, char code){
hfp_hf_establish_service_level_connection(bd_addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
void hfp_hf_send_dtmf_code(bd_addr_t addr, char code){
hfp_hf_establish_service_level_connection(addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(addr);
connection->hf_send_dtmf_code = code;
hfp_run_for_context(connection);
}
}
/*
* @brief
*/
void hfp_hf_request_phone_number_for_voice_tag(bd_addr_t addr){
hfp_hf_establish_service_level_connection(addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(addr);
connection->hf_send_binp = 1;
hfp_run_for_context(connection);
}

View File

@ -260,6 +260,11 @@ void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain);
*/
void hfp_hf_send_dtmf_code(bd_addr_t bd_addr, char code);
/*
* @brief
*/
void hfp_hf_request_phone_number_for_voice_tag(bd_addr_t addr);
/* API_END */
#if defined __cplusplus

View File

@ -152,6 +152,8 @@ static void show_usage(void){
printf("W - redial\n");
printf("0123456789#*-+ - send DTMF dial tones\n");
printf("x - request phone number for voice tag\n");
printf("---\n");
printf("Ctrl-c - exit\n");
printf("---\n");
@ -333,6 +335,10 @@ static int stdin_process(struct data_source *ds){
printf("Redial\n");
hfp_hf_redial_last_number(device_addr);
break;
case 'x':
printf("Request phone number for voice tag\n");
hfp_hf_request_phone_number_for_voice_tag(device_addr);
break;
default:
show_usage();
break;
@ -349,7 +355,9 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
if (event[3] && event[2] != HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR){
if (event[3]
&& event[2] != HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR
&& event[2] != HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG){
printf("ERROR, status: %u\n", event[3]);
return;
}
@ -390,6 +398,9 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
case HFP_SUBEVENT_RING:
printf("** Ring **\n");
break;
case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG:
printf("Phone number for voice tag: %s\n", (const char *) &event[3]);
break;
default:
printf("event not handled %u\n", event[2]);
break;