public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 1/6] shared/hfp: Add dial support
@ 2025-10-09 19:58 Frédéric Danis
  2025-10-09 19:58 ` [PATCH BlueZ v2 2/6] unit/test-hfp: Add dial tests for HF Frédéric Danis
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Frédéric Danis @ 2025-10-09 19:58 UTC (permalink / raw)
  To: linux-bluetooth

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-10-13 16:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-09 19:58 [PATCH BlueZ v2 1/6] shared/hfp: Add dial support Frédéric Danis
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox