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

Send AT+COPS=3,0 at the end of the SLC creation to set the format of
the operator selection to long alphanumeric, then query the currently
selected operator name from the AG.

Register +COPS handler to call the update_operator callback on event.
---
v1->v2 : Move changes from patch 2 to fix unit/test-hfp

 src/shared/hfp.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/shared/hfp.h |  1 +
 unit/test-hfp.c  |  7 +++-
 3 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index d01915ab1..f94df90f1 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -1710,7 +1710,30 @@ static void ciev_cb(struct hfp_context *context, void *user_data)
 	set_indicator_value(index, val, hfp->ag_ind, hfp);
 }
 
-static void slc_cmer_resp(enum hfp_result result, enum hfp_error cme_err,
+static void cops_cb(struct hfp_context *context, void *user_data)
+{
+	struct hfp_hf *hfp = user_data;
+	unsigned int mode, val;
+	char name[255];
+
+	DBG(hfp, "");
+
+	if (!hfp_context_get_number(context, &mode))
+		return;
+
+	if (!hfp_context_get_number(context, &val))
+		return;
+
+	if (!hfp_context_get_string(context, name, sizeof(name))) {
+		DBG(hfp, "hf: Could not get string");
+		return;
+	}
+
+	if (hfp->callbacks && hfp->callbacks->update_operator)
+		hfp->callbacks->update_operator(name, hfp->callbacks_data);
+}
+
+static void cops_resp(enum hfp_result result, enum hfp_error cme_err,
 	void *user_data)
 {
 	struct hfp_hf *hfp = user_data;
@@ -1718,7 +1741,7 @@ static void slc_cmer_resp(enum hfp_result result, enum hfp_error cme_err,
 	DBG(hfp, "");
 
 	if (result != HFP_RESULT_OK) {
-		DBG(hfp, "hf: CMER error: %d", result);
+		DBG(hfp, "hf: COPS? error: %d", result);
 		goto failed;
 	}
 
@@ -1726,8 +1749,65 @@ static void slc_cmer_resp(enum hfp_result result, enum hfp_error cme_err,
 		hfp->callbacks->session_ready(HFP_RESULT_OK, 0,
 						hfp->callbacks_data);
 
+	return;
+
+failed:
+	if (hfp->callbacks->session_ready)
+		hfp->callbacks->session_ready(result, cme_err,
+						hfp->callbacks_data);
+}
+
+static void cops_conf_resp(enum hfp_result result, enum hfp_error cme_err,
+	void *user_data)
+{
+	struct hfp_hf *hfp = user_data;
+
+	DBG(hfp, "");
+
+	if (result != HFP_RESULT_OK) {
+		DBG(hfp, "hf: COPS= error: %d", result);
+		goto failed;
+	}
+
+	/* SLC creation done, continue with default setup */
+	if (!hfp_hf_send_command(hfp, cops_resp, hfp,
+		"AT+COPS?")) {
+		DBG(hfp, "hf: Could not send AT+COPS?");
+		result = HFP_RESULT_ERROR;
+		goto failed;
+	}
+
+	return;
+
+failed:
+	if (hfp->callbacks->session_ready)
+		hfp->callbacks->session_ready(result, cme_err,
+						hfp->callbacks_data);
+}
+
+static void slc_cmer_resp(enum hfp_result result, enum hfp_error cme_err,
+	void *user_data)
+{
+	struct hfp_hf *hfp = user_data;
+
+	DBG(hfp, "");
+
+	if (result != HFP_RESULT_OK) {
+		DBG(hfp, "hf: CMER error: %d", result);
+		goto failed;
+	}
+
+	/* SLC creation done, continue with default setup */
+	if (!hfp_hf_send_command(hfp, cops_conf_resp, hfp,
+		"AT+COPS=3,0")) {
+		DBG(hfp, "hf: Could not send AT+COPS=3,0");
+		result = HFP_RESULT_ERROR;
+		goto failed;
+	}
+
 	/* Register unsolicited results handlers */
 	hfp_hf_register(hfp, ciev_cb, "+CIEV", hfp, NULL);
+	hfp_hf_register(hfp, cops_cb, "+COPS", hfp, NULL);
 
 	return;
 
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index e6f7bbbb6..27f6d2d7c 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -190,6 +190,7 @@ struct hfp_hf_callbacks {
 							void *user_data);
 	void (*update_indicator)(enum hfp_indicator indicator, uint32_t val,
 							void *user_data);
+	void (*update_operator)(const char *operator_name, void *user_data);
 };
 
 struct hfp_hf *hfp_hf_new(int fd);
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 371415a68..2a85ec575 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -725,7 +725,12 @@ static void test_hf_robustness(gconstpointer data)
 	frg_pdu('0', ',', '0', ',', '0', ',', '0', ',', '5'), \
 	frg_pdu(',', '0', ',', '5', '\r', '\n'), \
 	frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
-	raw_pdu('\r', '\n', 'O', 'K', '\r', '\n')
+	raw_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
+	raw_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
+	raw_pdu('\r', '\n', '+', 'C', 'O', 'P', 'S', ':', ' '), \
+	frg_pdu('0', ',', '0', ',', '\"', 'T', 'E', 'S', 'T'), \
+	frg_pdu('\"', '\r', '\n'), \
+	frg_pdu('\r', '\n', 'O', 'K', '\r', '\n')
 
 static void hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 							void *user_data)
-- 
2.43.0


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

end of thread, other threads:[~2025-09-17 13:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 16:34 [PATCH BlueZ v2 1/4] shared/hfp: Add Operator name support Frédéric Danis
2025-09-15 16:34 ` [PATCH BlueZ v2 2/4] unit/test-hfp: Add Operator name test for HF Frédéric Danis
2025-09-15 16:34 ` [PATCH BlueZ v2 3/4] shared/hfp: Add Call Line Identification support Frédéric Danis
2025-09-15 16:34 ` [PATCH BlueZ v2 4/4] unit/test-hfp: Add Call Line Identification test for HF Frédéric Danis
2025-09-15 18:05 ` [BlueZ,v2,1/4] shared/hfp: Add Operator name support bluez.test.bot
2025-09-17 13:30 ` [PATCH BlueZ v2 1/4] " 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