From 217bd72c128a5b9fcb913d0ea18ac503c7bdc82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Thu, 9 Oct 2025 21:58:37 +0200 Subject: [PATCH] shared/hfp: Add dial support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If no number, NULL or empry string, is passed to hfp_hf_dial() this will try to call the last dialed phone number using AT+BLDN. If the phone number starts with '>' and is followed by a number nnn…, up to 10 digits, it will call the phone number in memory entry nnn…. Else it will performed a voice call to the number provided. --- src/shared/hfp.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-- src/shared/hfp.h | 3 +++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/shared/hfp.c b/src/shared/hfp.c index 94adccada..a6f9645d8 100644 --- a/src/shared/hfp.c +++ b/src/shared/hfp.c @@ -102,6 +102,7 @@ struct hfp_hf { uint8_t battchg; struct queue *calls; + char *dialing_number; }; struct cmd_handler { @@ -1388,6 +1389,11 @@ void hfp_hf_unref(struct hfp_hf *hfp) queue_destroy(hfp->calls, remove_call_cb); hfp->calls = NULL; + if (hfp->dialing_number) { + free(hfp->dialing_number); + hfp->dialing_number = NULL; + } + if (!hfp->in_disconnect) { free(hfp); return; @@ -1622,7 +1628,8 @@ static struct hf_call *call_new(struct hfp_hf *hfp, unsigned int id, call = new0(struct hf_call, 1); call->id = id; call->status = status; - call->line_id = number; + if (number) + call->line_id = strdup(number); call->hfp = hfp; queue_push_tail(hfp->calls, call); @@ -1807,7 +1814,11 @@ static void ciev_callsetup_cb(uint8_t val, void *user_data) DBG(hfp, "hf: No new call index available"); return; } - call_new(hfp, id, status, NULL); + call_new(hfp, id, status, hfp->dialing_number); + if (hfp->dialing_number) { + free(hfp->dialing_number); + hfp->dialing_number = NULL; + } break; } } @@ -2421,6 +2432,50 @@ const char *hfp_hf_call_get_number(struct hfp_hf *hfp, uint id) return call->line_id; } +bool hfp_hf_dial(struct hfp_hf *hfp, const char *number, + hfp_response_func_t resp_cb, + void *user_data) +{ + const char *c; + int count = 0; + + if (!hfp) + return false; + + DBG(hfp, ""); + + if (number == NULL || strlen(number) == 0) + return hfp_hf_send_command(hfp, resp_cb, user_data, + "AT+BLDN"); + + if (number[0] == '>') { + for (c = number + 1; *c != '\0'; c++) { + if (!(*c >= '0' && *c <= '9')) + return false; + count++; + } + if (count < 1 || count > 10) + return false; + } else { + for (c = number; *c != '\0'; c++) { + if (!(*c >= '0' && *c <= '9') && + !(*c >= 'A' && *c <= 'D') && + *c != '#' && *c != '*' && + *c != '+' && *c != ',') + return false; + count++; + } + if (count < 1 || count > 80) + return false; + } + + if (hfp->dialing_number) + free(hfp->dialing_number); + hfp->dialing_number = strdup(number); + + return hfp_hf_send_command(hfp, resp_cb, user_data, "ATD%s;", number); +} + bool hfp_hf_call_answer(struct hfp_hf *hfp, uint id, hfp_response_func_t resp_cb, void *user_data) diff --git a/src/shared/hfp.h b/src/shared/hfp.h index 4b171ad88..21214eee4 100644 --- a/src/shared/hfp.h +++ b/src/shared/hfp.h @@ -237,6 +237,9 @@ bool hfp_hf_session(struct hfp_hf *hfp); const char *hfp_hf_call_get_number(struct hfp_hf *hfp, uint id); +bool hfp_hf_dial(struct hfp_hf *hfp, const char *number, + hfp_response_func_t resp_cb, + void *user_data); bool hfp_hf_call_answer(struct hfp_hf *hfp, uint id, hfp_response_func_t resp_cb, void *user_data); -- 2.47.3