diff --git a/src/hfp.h b/src/hfp.h index 8d37895ba..85838bbd1 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -563,6 +563,7 @@ typedef struct hfp_connection { uint8_t hf_send_chld_2; uint8_t hf_send_chld_3; uint8_t hf_send_chld_4; + char hf_send_dtmf_code; uint8_t hf_activate_call_waiting_notification; uint8_t hf_deactivate_call_waiting_notification; diff --git a/src/hfp_hf.c b/src/hfp_hf.c index fd028c5d5..e7b6e6ddc 100644 --- a/src/hfp_hf.c +++ b/src/hfp_hf.c @@ -304,6 +304,12 @@ static int hfp_hf_send_chld(uint16_t cid, int number){ return send_str_over_rfcomm(cid, buffer); } +static int hfp_hf_send_dtmf(uint16_t cid, char code){ + char buffer[20]; + sprintf(buffer, "AT%s=%c\r\n", HFP_TRANSMIT_DTMF_CODES, code); + 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]; @@ -664,6 +670,14 @@ static void hfp_run_for_context(hfp_connection_t * context){ 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); + return; + } + if (done) return; // deal with disconnect switch (context->state){ @@ -1261,3 +1275,12 @@ void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain){ hfp_run_for_context(connection); } +/* + * @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); + connection->hf_send_dtmf_code = code; + hfp_run_for_context(connection); +} \ No newline at end of file diff --git a/src/hfp_hf.h b/src/hfp_hf.h index 232ab26e4..af538f99c 100644 --- a/src/hfp_hf.h +++ b/src/hfp_hf.h @@ -255,6 +255,11 @@ void hfp_hf_set_microphone_gain(bd_addr_t bd_addr, int gain); */ 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); + /* API_END */ #if defined __cplusplus diff --git a/test/pts/hfp_hf_test.c b/test/pts/hfp_hf_test.c index 0fdf1d11a..09977618f 100644 --- a/test/pts/hfp_hf_test.c +++ b/test/pts/hfp_hf_test.c @@ -150,6 +150,7 @@ static void show_usage(void){ printf("V - Join held call (Three-Way Call 3)\n"); printf("w - Connect calls (Three-Way Call 4)\n"); printf("W - redial\n"); + printf("0123456789#*-+ - send DTMF dial tones\n"); printf("---\n"); printf("Ctrl-c - exit\n"); @@ -158,7 +159,21 @@ static void show_usage(void){ static int stdin_process(struct data_source *ds){ read(ds->fd, &cmd, 1); + + if (cmd >= '0' && cmd <= '9'){ + printf("DTMF Code: %c\n", cmd); + hfp_hf_send_dtmf_code(device_addr, cmd); + return 0; + } + switch (cmd){ + case '#': + case '-': + case '+': + case '*': + printf("DTMF Code: %c\n", cmd); + hfp_hf_send_dtmf_code(device_addr, cmd); + break; case 'a': printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr)); hfp_hf_establish_service_level_connection(device_addr);