All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/6] shared/hfp: Add dial support
@ 2025-10-01  6:54 Frédéric Danis
  2025-10-01  6:54 ` [PATCH BlueZ 2/6] unit/test-hfp: Add dial tests for HF Frédéric Danis
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Frédéric Danis @ 2025-10-01  6:54 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.
---
 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 133bff248..c7a04b536 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;
+
+	DBG(hfp, "");
+
+	if (!hfp)
+		return false;
+
+	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] 7+ messages in thread

end of thread, other threads:[~2025-10-01  8:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01  6:54 [PATCH BlueZ 1/6] shared/hfp: Add dial support Frédéric Danis
2025-10-01  6:54 ` [PATCH BlueZ 2/6] unit/test-hfp: Add dial tests for HF Frédéric Danis
2025-10-01  6:54 ` [PATCH BlueZ 3/6] shared/hfp: Add in-band ring tone setting support Frédéric Danis
2025-10-01  6:54 ` [PATCH BlueZ 4/6] unit/test-hfp: Add Answer Incoming Call with In-Band Ring tests for HF Frédéric Danis
2025-10-01  6:54 ` [PATCH BlueZ 5/6] unit/test-hfp: Add incoming call prior to connection test Frédéric Danis
2025-10-01  6:54 ` [PATCH BlueZ 6/6] unit/test-hfp: Add incoming call interrupted test Frédéric Danis
2025-10-01  8:15 ` [BlueZ,1/6] shared/hfp: Add dial support bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.