From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 1/6] shared/hfp: Add dial support
Date: Thu, 9 Oct 2025 21:58:37 +0200 [thread overview]
Message-ID: <20251009195842.776231-1-frederic.danis@collabora.com> (raw)
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.
---
v1->v2: Fix issue found by codacy in previous commit
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.43.0
next reply other threads:[~2025-10-09 19:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-09 19:58 Frédéric Danis [this message]
2025-10-09 19:58 ` [PATCH BlueZ v2 2/6] unit/test-hfp: Add dial tests for HF Frédéric Danis
2025-10-09 19:58 ` [PATCH BlueZ v2 3/6] shared/hfp: Add in-band ring tone setting support Frédéric Danis
2025-10-09 19:58 ` [PATCH BlueZ v2 4/6] unit/test-hfp: Add Answer Incoming Call with In-Band Ring tests for HF Frédéric Danis
2025-10-09 19:58 ` [PATCH BlueZ v2 5/6] unit/test-hfp: Add incoming call prior to connection test Frédéric Danis
2025-10-09 19:58 ` [PATCH BlueZ v2 6/6] unit/test-hfp: Add incoming call interrupted test Frédéric Danis
2025-10-09 21:31 ` [BlueZ,v2,1/6] shared/hfp: Add dial support bluez.test.bot
2025-10-13 16:00 ` [PATCH BlueZ v2 1/6] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251009195842.776231-1-frederic.danis@collabora.com \
--to=frederic.danis@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox