All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect
@ 2013-03-12 14:21 Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 01/20] handsfree-audio: Add card driver for HFP 1.6 Claudio Takahasi
                   ` (19 more replies)
  0 siblings, 20 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

This RFC implements codec negotiation and HF initiated audio
connection for HFP 1.6

Dependency: "[PATCH v0 00/15] Add handsfree audio card driver"

Open issues:
* Use bitmask or keep the array to store the supported audio codecs?
* Return -EINPROGRESS for Audio Connect. Is it acceptable?

Missing:
* Unregister the codec watcher
* Some errors handling

Development branch:
git://git.infradead.org/users/cktakahasi/ofono.git external-hfp16

Claudio Takahasi (18):
  handsfree-audio: Add card driver for HFP 1.6
  handsfree-audio: Add user data to card driver
  hfp_hf_bluez5: Pass modem as user data
  handsfree-audio: Add user data to connect declaration
  hfp_hf_bluez5: Add user data to connect implementation
  hfp_hf_bluez5: Add HFP 1.6 connect implementation
  handsfree-audio: Add HFP 1.6 connect hook
  handsfree-audio: Add "Connect" reply for HFP 1.6
  handsfree-audio: Add function to get the codecs
  hfp_hf_bluez5: Register codec watcher
  handsfree-audio: Add function to select the codec
  hfp_hf_bluez5: Set the audio codec in the card
  handsfree-audio: Send the selected codec
  handsfree-audio: Set CVSD as default in the card
  handsfree-audio: Use bitmask for supported codecs
  handsfree-audio: Disable mSBC if defer is off
  bluetooth: Add define for SCO voice settings
  handsfree-audio: Add setting SCO air mode

Vinicius Costa Gomes (2):
  hfpmodem: Send AT+BAC with the supported codecs
  hfpmodem: Add codec watcher register

 drivers/hfpmodem/slc.c    |  89 +++++++++++++++++++++++++++++++-
 drivers/hfpmodem/slc.h    |   4 ++
 include/handsfree-audio.h |   9 +++-
 plugins/hfp_hf_bluez5.c   |  56 +++++++++++++++++++-
 src/bluetooth.h           |  12 +++++
 src/handsfree-audio.c     | 127 +++++++++++++++++++++++++++++++++++++++-------
 6 files changed, 274 insertions(+), 23 deletions(-)

-- 
1.7.11.7


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

* [RFC v0 01/20] handsfree-audio: Add card driver for HFP 1.6
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 02/20] handsfree-audio: Add user data to card driver Claudio Takahasi
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1826 bytes --]

This patch registers the Handsfree Audio Card driver for devices
compliant with HFP 1.6.
---
 plugins/hfp_hf_bluez5.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index dd0a782..810107f 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -360,6 +360,18 @@ static struct ofono_handsfree_card_driver card_driver15 = {
 	.audio_connect	= card_audio_connect15,
 };
 
+static int card_audio_connect16(const char *remote, const char *local)
+{
+	return 0;
+}
+
+static struct ofono_handsfree_card_driver card_driver16 = {
+	.version	= HFP_VERSION_1_6,
+	.probe		= card_probe,
+	.remove		= card_remove,
+	.audio_connect	= card_audio_connect16,
+};
+
 static ofono_bool_t device_path_compare(struct ofono_modem *modem,
 					void *userdata)
 {
@@ -708,9 +720,18 @@ static int hfp_init(void)
 		return err;
 	}
 
+	err = ofono_handsfree_card_driver_register(&card_driver16);
+	if (err < 0) {
+		ofono_handsfree_card_driver_unregister(&card_driver15);
+		g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
+						BLUEZ_PROFILE_INTERFACE);
+		return err;
+	}
+
 	err = ofono_modem_driver_register(&hfp_driver);
 	if (err < 0) {
 		ofono_handsfree_card_driver_unregister(&card_driver15);
+		ofono_handsfree_card_driver_unregister(&card_driver16);
 		g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
 						BLUEZ_PROFILE_INTERFACE);
 		return err;
@@ -742,6 +763,7 @@ static void hfp_exit(void)
 						BLUEZ_PROFILE_INTERFACE);
 	ofono_modem_driver_unregister(&hfp_driver);
 	ofono_handsfree_card_driver_unregister(&card_driver15);
+	ofono_handsfree_card_driver_unregister(&card_driver16);
 	g_dbus_client_unref(bluez);
 
 	ofono_handsfree_audio_unref();
-- 
1.7.11.7


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

* [RFC v0 02/20] handsfree-audio: Add user data to card driver
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 01/20] handsfree-audio: Add card driver for HFP 1.6 Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 03/20] hfp_hf_bluez5: Pass modem as user data Claudio Takahasi
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2088 bytes --]

For hfp_hf_bluez5 plugin, the modem reference needs to be passed using
the user data. Access to service level connection is required to send
AT commands.
---
 include/handsfree-audio.h | 3 ++-
 src/handsfree-audio.c     | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index e99a2dd..1a059b3 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -44,7 +44,8 @@ void ofono_handsfree_card_driver_unregister(
 			const struct ofono_handsfree_card_driver *d);
 
 struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
-					const char *local, uint16_t version);
+					const char *local, uint16_t version,
+					void *data);
 int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
 void ofono_handsfree_card_remove(struct ofono_handsfree_card *card);
 
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 62d316f..52e1ede 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -56,6 +56,7 @@ struct ofono_handsfree_card {
 	const struct ofono_handsfree_card_driver *driver;
 	DBusMessage *msg;
 	guint sco_watch;
+	void *data;
 };
 
 struct agent {
@@ -320,7 +321,8 @@ static const GDBusSignalTable card_signals[] = {
 };
 
 struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
-					const char *local, uint16_t version)
+					const char *local, uint16_t version,
+					void *data)
 {
 	struct ofono_handsfree_card *card;
 	GSList *l;
@@ -329,6 +331,7 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
 
 	card->remote = g_strdup(remote);
 	card->local = g_strdup(local);
+	card->data = data;
 
 	card_list = g_slist_prepend(card_list, card);
 
@@ -338,7 +341,7 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
 		if (drv->version != version)
 			continue;
 
-		if (drv->probe(card, NULL) < 0)
+		if (drv->probe(card, data) < 0)
 			continue;
 
 		card->driver = drv;
-- 
1.7.11.7


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

* [RFC v0 03/20] hfp_hf_bluez5: Pass modem as user data
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 01/20] handsfree-audio: Add card driver for HFP 1.6 Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 02/20] handsfree-audio: Add user data to card driver Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 04/20] handsfree-audio: Add user data to connect declaration Claudio Takahasi
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

This patch adds the modem reference as user data when the Handsfree
Audio Card is created, allowing to access the service level connection
in the connect callback.
---
 plugins/hfp_hf_bluez5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 810107f..1d26a28 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -495,7 +495,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	hfp = ofono_modem_get_data(modem);
 	hfp->msg = dbus_message_ref(msg);
-	hfp->card = ofono_handsfree_card_create(remote, local, version);
+	hfp->card = ofono_handsfree_card_create(remote, local, version, modem);
 
 	return NULL;
 
-- 
1.7.11.7


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

* [RFC v0 04/20] handsfree-audio: Add user data to connect declaration
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (2 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 03/20] hfp_hf_bluez5: Pass modem as user data Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 05/20] hfp_hf_bluez5: Add user data to connect implementation Claudio Takahasi
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1269 bytes --]

This patch adds the user data in the Handsfree Audio driver connect
callback declaration.
---
 include/handsfree-audio.h | 3 ++-
 src/handsfree-audio.c     | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index 1a059b3..c7a37dc 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -35,7 +35,8 @@ struct ofono_handsfree_card_driver {
 	uint16_t version;
 	int (*probe) (struct ofono_handsfree_card *card, void *data);
 	void (*remove) (struct ofono_handsfree_card *card);
-	int (*audio_connect) (const char *remote, const char *local);
+	int (*audio_connect) (const char *remote, const char *local,
+							void *data);
 };
 
 int ofono_handsfree_card_driver_register(
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 52e1ede..c9fed48 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -290,7 +290,7 @@ static DBusMessage *card_connect(DBusConnection *conn,
 	if (card->msg)
 		return __ofono_error_busy(msg);
 
-	sk = driver->audio_connect(card->remote, card->local);
+	sk = driver->audio_connect(card->remote, card->local, card->data);
 	if (sk < 0)
 		return __ofono_error_failed(msg);
 
-- 
1.7.11.7


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

* [RFC v0 05/20] hfp_hf_bluez5: Add user data to connect implementation
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (3 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 04/20] handsfree-audio: Add user data to connect declaration Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 " Claudio Takahasi
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]

This patch adds the user data in the Handsfree Audio driver connect
implementation to allow accessing modem reference.
---
 plugins/hfp_hf_bluez5.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 1d26a28..0d5d5c7 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -319,7 +319,8 @@ static void card_remove(struct ofono_handsfree_card *card)
 {
 }
 
-static int card_audio_connect15(const char *remote, const char *local)
+static int card_audio_connect15(const char *remote, const char *local,
+								void *data)
 {
 	struct sockaddr_sco addr;
 	int sk, ret;
@@ -360,7 +361,8 @@ static struct ofono_handsfree_card_driver card_driver15 = {
 	.audio_connect	= card_audio_connect15,
 };
 
-static int card_audio_connect16(const char *remote, const char *local)
+static int card_audio_connect16(const char *remote, const char *local,
+								void *data)
 {
 	return 0;
 }
-- 
1.7.11.7


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

* [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 connect implementation
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (4 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 05/20] hfp_hf_bluez5: Add user data to connect implementation Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-14 17:52   ` Vinicius Costa Gomes
  2013-03-12 14:21 ` [RFC v0 07/20] handsfree-audio: Add HFP 1.6 connect hook Claudio Takahasi
                   ` (13 subsequent siblings)
  19 siblings, 1 reply; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]

This patch implements the HF initiate SCO connection for devices
compliant with HFP 1.6. HF sends AT+BCC to inform the AG that audio
connection is required.
---
 plugins/hfp_hf_bluez5.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 0d5d5c7..6c55657 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -364,7 +364,18 @@ static struct ofono_handsfree_card_driver card_driver15 = {
 static int card_audio_connect16(const char *remote, const char *local,
 								void *data)
 {
-	return 0;
+	struct ofono_modem *modem = data;
+	struct hfp *hfp = ofono_modem_get_data(modem);
+	struct hfp_slc_info *info = &hfp->info;
+
+	if (info->chat == NULL)
+		return -ENOTCONN;
+
+	info->chat = g_at_chat_ref(info->chat);
+	g_at_chat_send(info->chat, "AT+BCC", NULL, NULL, info->chat,
+					(GDestroyNotify) g_at_chat_unref);
+
+	return -EINPROGRESS;
 }
 
 static struct ofono_handsfree_card_driver card_driver16 = {
-- 
1.7.11.7


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

* [RFC v0 07/20] handsfree-audio: Add HFP 1.6 connect hook
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (5 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 " Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 08/20] handsfree-audio: Add "Connect" reply for HFP 1.6 Claudio Takahasi
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]

This patch treats -EINPROGRESS as success return value for HFP 1.6
Audio Connection setup. For HFP 1.6, HF sends AT+BCC and waits the AG
to establish the SCO connection.
---
 src/handsfree-audio.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c9fed48..cb97c57 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -290,7 +290,15 @@ static DBusMessage *card_connect(DBusConnection *conn,
 	if (card->msg)
 		return __ofono_error_busy(msg);
 
+	/*
+	 * HFP 1.6 card driver returns in progress to inform that AT+BCC has
+	 * been sent. This command informs the AG that the audio connection
+	 * should be established.
+	 */
 	sk = driver->audio_connect(card->remote, card->local, card->data);
+	if (sk == -EINPROGRESS)
+		goto done;
+
 	if (sk < 0)
 		return __ofono_error_failed(msg);
 
@@ -301,6 +309,7 @@ static DBusMessage *card_connect(DBusConnection *conn,
 
 	g_io_channel_unref(io);
 
+done:
 	card->msg = dbus_message_ref(msg);
 
 	return NULL;
-- 
1.7.11.7


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

* [RFC v0 08/20] handsfree-audio: Add "Connect" reply for HFP 1.6
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (6 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 07/20] handsfree-audio: Add HFP 1.6 connect hook Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 09/20] handsfree-audio: Add function to get the codecs Claudio Takahasi
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

For HFP 1.6, the HF sends AT+BCC to inform the AG that a SCO connection
needs to be established, and the AG initiates the connection. For this
case, the "Connect" method reply needs to be sent when the link is
established.
---
 src/handsfree-audio.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index cb97c57..3a7dcee 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -156,6 +156,13 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 		return TRUE;
 	}
 
+	if (card->msg) {
+		DBusMessage *reply = dbus_message_new_method_return(card->msg);
+		g_dbus_send_message(ofono_dbus_get_connection(), reply);
+		dbus_message_unref(card->msg);
+		card->msg = NULL;
+	}
+
 	send_new_connection(card->path, nsk);
 	close(nsk);
 
-- 
1.7.11.7


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

* [RFC v0 09/20] handsfree-audio: Add function to get the codecs
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (7 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 08/20] handsfree-audio: Add "Connect" reply for HFP 1.6 Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs Claudio Takahasi
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1414 bytes --]

This patch adds a new handsfree-audio public function to read the
available codecs registered by the agent.
---
 include/handsfree-audio.h |  1 +
 src/handsfree-audio.c     | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index c7a37dc..839f0f8 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -49,6 +49,7 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
 					void *data);
 int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
 void ofono_handsfree_card_remove(struct ofono_handsfree_card *card);
+int ofono_handsfree_get_codecs(unsigned char *buffer, int buffer_len);
 
 void ofono_handsfree_audio_ref(void);
 void ofono_handsfree_audio_unref(void);
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 3a7dcee..2cbdb57 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -462,6 +462,19 @@ void ofono_handsfree_card_remove(struct ofono_handsfree_card *card)
 	g_free(card);
 }
 
+int ofono_handsfree_get_codecs(unsigned char *buffer, int buffer_len)
+{
+	int len;
+
+	if (agent == NULL)
+		return -EIO;
+
+	len = MIN(buffer_len, agent->codecs_len);
+	memcpy(buffer, agent->codecs, len);
+
+	return len;
+}
+
 static void agent_free(struct agent *agent)
 {
 	if (agent->watch > 0)
-- 
1.7.11.7


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

* [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (8 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 09/20] handsfree-audio: Add function to get the codecs Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 17:44   ` Vinicius Costa Gomes
  2013-03-12 14:21 ` [RFC v0 11/20] hfpmodem: Add codec watcher register Claudio Takahasi
                   ` (9 subsequent siblings)
  19 siblings, 1 reply; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1552 bytes --]

From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>

Before, the AT+BAC command was being sent with fixed information,
now we send the command (that inform the AG of the codecs supported by
the HF) with the codecs supported by the registered Handsfree Audio
Agent.
---
 drivers/hfpmodem/slc.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/hfpmodem/slc.c b/drivers/hfpmodem/slc.c
index 646befa..b9b687b 100644
--- a/drivers/hfpmodem/slc.c
+++ b/drivers/hfpmodem/slc.c
@@ -34,6 +34,7 @@
 #include <ofono/log.h>
 #include <ofono/modem.h>
 #include <ofono/emulator.h>
+#include <ofono/handsfree-audio.h>
 
 #include <drivers/atmodem/atutil.h>
 
@@ -305,9 +306,27 @@ static void brsf_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	if (info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION &&
 			info->hf_features & HFP_HF_FEATURE_CODEC_NEGOTIATION) {
 
+		unsigned char codecs[8];
+		GString *str;
+		int i, len;
+
+		len = ofono_handsfree_get_codecs(codecs, sizeof(codecs));
+		if (len < 0)
+			goto error;
+
+		str = g_string_new("AT+BAC=");
+
+		for (i = 0; i < (len - 1); i++)
+			g_string_append_printf(str, "%d,", codecs[i]);
+
+		g_string_append_printf(str, "%d", codecs[i]);
+
 		slc_establish_data_ref(sed);
-		g_at_chat_send(info->chat, "AT+BAC=1", NULL, bac_cb, sed,
+		g_at_chat_send(info->chat, str->str, NULL, bac_cb, sed,
 						slc_establish_data_unref);
+
+		g_string_free(str, TRUE);
+
 		return;
 	}
 
-- 
1.7.11.7


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

* [RFC v0 11/20] hfpmodem: Add codec watcher register
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (9 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 12/20] hfp_hf_bluez5: Register codec watcher Claudio Takahasi
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3221 bytes --]

From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>

This patch adds a function to monitor when the AG sends a new codec
before establishing the SCO connection.
---
 drivers/hfpmodem/slc.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/hfpmodem/slc.h |  4 +++
 2 files changed, 72 insertions(+)

diff --git a/drivers/hfpmodem/slc.c b/drivers/hfpmodem/slc.c
index b9b687b..905be68 100644
--- a/drivers/hfpmodem/slc.c
+++ b/drivers/hfpmodem/slc.c
@@ -53,6 +53,12 @@ struct slc_establish_data {
 	gpointer userdata;
 };
 
+struct codec_watch {
+	struct hfp_slc_info *slc;
+	hfp_slc_codec_watch_cb_t cb;
+	gpointer user_data;
+};
+
 void hfp_slc_info_init(struct hfp_slc_info *info, guint16 version)
 {
 	info->ag_features = 0;
@@ -355,3 +361,65 @@ void hfp_slc_establish(struct hfp_slc_info *info, hfp_slc_cb_t connect_cb,
 	g_at_chat_send(info->chat, buf, brsf_prefix,
 				brsf_cb, sed, slc_establish_data_unref);
 }
+
+static void bcs_notify(GAtResult *result, gpointer user_data)
+{
+	struct codec_watch *watch = user_data;
+	struct hfp_slc_info *info = watch->slc;
+	unsigned char codecs[8];
+	GAtResultIter iter;
+	GString *str;
+	int i, value, len;
+
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+BCS:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &value))
+		return;
+
+	/* If some codec matches, we confirm it */
+
+	len = ofono_handsfree_get_codecs(codecs, sizeof(codecs));
+	if (len < 0)
+		return;
+
+	for (i = 0; i < len; i++) {
+		if (codecs[i] == value) {
+
+			DBG("Negotiated HFP codec: %d", value);
+			watch->cb(value, watch->user_data);
+
+			str = g_string_new("AT+BCS=");
+			g_string_append_printf(str, "%d", value);
+			goto done;
+		}
+	}
+
+	/* If none matches, we send our supported codecs again */
+	str = g_string_new("AT+BAC=");
+
+	for (i = 0; i < (len - 1); i++)
+		g_string_append_printf(str, "%d,", codecs[i]);
+
+	g_string_append_printf(str, "%d", codecs[i]);
+
+done:
+	g_at_chat_send(info->chat, str->str, NULL, NULL, NULL, NULL);
+	g_string_free(str, TRUE);
+}
+
+guint hfp_slc_codec_watch_register(struct hfp_slc_info *info,
+				hfp_slc_codec_watch_cb_t cb, void *user_data)
+{
+	struct codec_watch *watch = g_new0(struct codec_watch, 1);
+
+	watch->slc = info;
+	watch->cb = cb;
+	watch->user_data = user_data;
+
+	return g_at_chat_register(info->chat, "+BCS:", bcs_notify, FALSE,
+								watch, g_free);
+}
diff --git a/drivers/hfpmodem/slc.h b/drivers/hfpmodem/slc.h
index b71ffe9..95539c8 100644
--- a/drivers/hfpmodem/slc.h
+++ b/drivers/hfpmodem/slc.h
@@ -45,6 +45,7 @@ enum hfp_indicator {
 };
 
 typedef void (*hfp_slc_cb_t)(void *userdata);
+typedef void (*hfp_slc_codec_watch_cb_t)(unsigned char codec, void *userdata);
 
 struct hfp_slc_info {
 	GAtChat *chat;
@@ -60,3 +61,6 @@ void hfp_slc_info_free(struct hfp_slc_info *info);
 
 void hfp_slc_establish(struct hfp_slc_info *info, hfp_slc_cb_t connect_cb,
 				hfp_slc_cb_t failed_cb, void *userdata);
+
+guint hfp_slc_codec_watch_register(struct hfp_slc_info *info,
+				hfp_slc_codec_watch_cb_t cb, void *user_data);
-- 
1.7.11.7


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

* [RFC v0 12/20] hfp_hf_bluez5: Register codec watcher
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (10 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 11/20] hfpmodem: Add codec watcher register Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 13/20] handsfree-audio: Add function to select the codec Claudio Takahasi
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1402 bytes --]

This patch registers the codec watcher when the Handsfree Audio Card
driver probe callback gets called.
---
 plugins/hfp_hf_bluez5.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 6c55657..f20aff7 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -64,6 +64,7 @@ struct hfp {
 	struct hfp_slc_info info;
 	DBusMessage *msg;
 	struct ofono_handsfree_card *card;
+	guint codec_watch;
 };
 
 static GDBusClient *bluez = NULL;
@@ -75,6 +76,14 @@ static void hfp_debug(const char *str, void *user_data)
 	ofono_info("%s%s", prefix, str);
 }
 
+static void codec_watcher_cb(unsigned char codec, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct hfp *hfp = ofono_modem_get_data(modem);
+
+	DBG("Card: %p selected codec: %d", hfp->card, codec);
+}
+
 static void slc_established(gpointer userdata)
 {
 	struct ofono_modem *modem = userdata;
@@ -312,6 +321,13 @@ static struct ofono_modem_driver hfp_driver = {
 
 static int card_probe(struct ofono_handsfree_card *card, void *data)
 {
+	struct ofono_modem *modem = data;
+	struct hfp *hfp = ofono_modem_get_data(modem);
+	struct hfp_slc_info *info = &hfp->info;
+
+	hfp->codec_watch = hfp_slc_codec_watch_register(info, codec_watcher_cb,
+									modem);
+
 	return 0;
 }
 
-- 
1.7.11.7


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

* [RFC v0 13/20] handsfree-audio: Add function to select the codec
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (11 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 12/20] hfp_hf_bluez5: Register codec watcher Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 14/20] hfp_hf_bluez5: Set the audio codec in the card Claudio Takahasi
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1758 bytes --]

This patch adds a public function to select the active codec in the
Audio Card. The AG informs the HF which codec ID is to be used before
establishing the Synchronous Connection. The selected codec is input
to set properly the SCO parameters.
---
 include/handsfree-audio.h |  2 ++
 src/handsfree-audio.c     | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index 839f0f8..696f153 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -49,6 +49,8 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
 					void *data);
 int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
 void ofono_handsfree_card_remove(struct ofono_handsfree_card *card);
+int ofono_handsfree_card_select_codec(struct ofono_handsfree_card *card,
+							unsigned char codec);
 int ofono_handsfree_get_codecs(unsigned char *buffer, int buffer_len);
 
 void ofono_handsfree_audio_ref(void);
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 2cbdb57..1b0a04d 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -57,6 +57,7 @@ struct ofono_handsfree_card {
 	DBusMessage *msg;
 	guint sco_watch;
 	void *data;
+	unsigned char selected_codec;
 };
 
 struct agent {
@@ -462,6 +463,17 @@ void ofono_handsfree_card_remove(struct ofono_handsfree_card *card)
 	g_free(card);
 }
 
+int ofono_handsfree_card_select_codec(struct ofono_handsfree_card *card,
+							unsigned char codec)
+{
+	if (card == NULL)
+		return -EINVAL;
+
+	card->selected_codec = codec;
+
+	return 0;
+}
+
 int ofono_handsfree_get_codecs(unsigned char *buffer, int buffer_len)
 {
 	int len;
-- 
1.7.11.7


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

* [RFC v0 14/20] hfp_hf_bluez5: Set the audio codec in the card
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (12 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 13/20] handsfree-audio: Add function to select the codec Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 15/20] handsfree-audio: Send the selected codec Claudio Takahasi
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

This patch updates the handsfree audio card codec when the AG notifies
the codec for the succeeding incoming SCO connection.
---
 plugins/hfp_hf_bluez5.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index f20aff7..49cc378 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -82,6 +82,7 @@ static void codec_watcher_cb(unsigned char codec, gpointer user_data)
 	struct hfp *hfp = ofono_modem_get_data(modem);
 
 	DBG("Card: %p selected codec: %d", hfp->card, codec);
+	ofono_handsfree_card_select_codec(hfp->card, codec);
 }
 
 static void slc_established(gpointer userdata)
-- 
1.7.11.7


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

* [RFC v0 15/20] handsfree-audio: Send the selected codec
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (13 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 14/20] hfp_hf_bluez5: Set the audio codec in the card Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 16/20] handsfree-audio: Set CVSD as default in the card Claudio Takahasi
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1421 bytes --]

This patch removes the hard-coded CVSD codec, and adds the selected
codec in the NewConnection method call, notifying the agent the codec
previously selected for the audio connection.
---
 src/handsfree-audio.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 1b0a04d..0d31712 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -74,11 +74,10 @@ static GSList *card_list = 0;
 static guint sco_watch = 0;
 static GSList *g_drivers = NULL;
 
-static void send_new_connection(const char *card, int fd)
+static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
 	DBusMessage *msg;
 	DBusMessageIter iter;
-	uint8_t codec = HFP_CODEC_CVSD;
 
 	msg = dbus_message_new_method_call(agent->owner, agent->path,
 				HFP_AUDIO_AGENT_INTERFACE, "NewConnection");
@@ -164,7 +163,7 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 		card->msg = NULL;
 	}
 
-	send_new_connection(card->path, nsk);
+	send_new_connection(card->path, nsk, card->selected_codec);
 	close(nsk);
 
 	return TRUE;
@@ -261,7 +260,7 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
 	sk = g_io_channel_unix_get_fd(io);
 
 	if (agent)
-		send_new_connection(card->path, sk);
+		send_new_connection(card->path, sk, card->selected_codec);
 
 	close(sk);
 
-- 
1.7.11.7


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

* [RFC v0 16/20] handsfree-audio: Set CVSD as default in the card
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (14 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 15/20] handsfree-audio: Send the selected codec Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 17/20] handsfree-audio: Use bitmask for supported codecs Claudio Takahasi
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

If the device doesn't support codec negotiation, the selected codec is
not being initialized. For this case set CVSD as default.
---
 src/handsfree-audio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 0d31712..0eb5c70 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -348,6 +348,7 @@ struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
 	card->remote = g_strdup(remote);
 	card->local = g_strdup(local);
 	card->data = data;
+	card->selected_codec = HFP_CODEC_CVSD;
 
 	card_list = g_slist_prepend(card_list, card);
 
-- 
1.7.11.7


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

* [RFC v0 17/20] handsfree-audio: Use bitmask for supported codecs
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (15 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 16/20] handsfree-audio: Set CVSD as default in the card Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 18/20] handsfree-audio: Disable mSBC if defer is off Claudio Takahasi
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3600 bytes --]

This patch changes the internal representation of the supported codecs.
Codecs are being declared in a sequentialily, represent the supported
codecs as bit-field helps to check for supported codecs and in some
cases it avoids dupplicated codec entries.
---
 src/handsfree-audio.c | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 0eb5c70..c0e644c 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -44,9 +44,11 @@
 #define HFP_AUDIO_CARD_INTERFACE	OFONO_SERVICE ".HandsfreeAudioCard"
 
 /* Supported agent codecs */
+#define MAX_SUPPORTED_CODECS		2
 enum hfp_codec {
 	HFP_CODEC_CVSD = 0x01,
 	HFP_CODEC_MSBC = 0x02,
+	HFP_CODEC_LAST = HFP_CODEC_MSBC,
 };
 
 struct ofono_handsfree_card {
@@ -63,8 +65,7 @@ struct ofono_handsfree_card {
 struct agent {
 	char *owner;
 	char *path;
-	unsigned char *codecs;
-	int codecs_len;
+	uint32_t codecs_bitmask;
 	guint watch;
 };
 
@@ -74,6 +75,16 @@ static GSList *card_list = 0;
 static guint sco_watch = 0;
 static GSList *g_drivers = NULL;
 
+static inline void set_bit(int nr, void *addr)
+{
+	*((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
+}
+
+static inline int test_bit(int nr, void *addr)
+{
+	return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
+}
+
 static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
 	DBusMessage *msg;
@@ -476,15 +487,20 @@ int ofono_handsfree_card_select_codec(struct ofono_handsfree_card *card,
 
 int ofono_handsfree_get_codecs(unsigned char *buffer, int buffer_len)
 {
-	int len;
+	unsigned char codecs[MAX_SUPPORTED_CODECS];
+	int i, j, min;
 
 	if (agent == NULL)
 		return -EIO;
 
-	len = MIN(buffer_len, agent->codecs_len);
-	memcpy(buffer, agent->codecs, len);
+	for (i = 0, j = 0; i <= HFP_CODEC_LAST; i++)
+		if (test_bit(i, &agent->codecs_bitmask))
+			codecs[j++] = i;
+
+	min = MIN(buffer_len, j);
+	memcpy(buffer, codecs, min);
 
-	return len;
+	return min;
 }
 
 static void agent_free(struct agent *agent)
@@ -494,7 +510,6 @@ static void agent_free(struct agent *agent)
 
 	g_free(agent->owner);
 	g_free(agent->path);
-	g_free(agent->codecs);
 	g_free(agent);
 }
 
@@ -572,7 +587,7 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 	unsigned char *codecs;
 	DBusMessageIter iter, array;
 	int length, i;
-	gboolean has_cvsd = FALSE;
+	uint32_t codecs_bitmask = 0;
 
 	if (agent)
 		return __ofono_error_in_use(msg);
@@ -593,12 +608,14 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 
 	for (i = 0; i < length; i++) {
 		if (codecs[i] == HFP_CODEC_CVSD)
-			has_cvsd = TRUE;
-		else if (codecs[i] != HFP_CODEC_MSBC)
+			set_bit(HFP_CODEC_CVSD, &codecs_bitmask);
+		else if (codecs[i] == HFP_CODEC_MSBC)
+			set_bit(HFP_CODEC_MSBC, &codecs_bitmask);
+		else
 			return __ofono_error_invalid_args(msg);
 	}
 
-	if (has_cvsd == FALSE) {
+	if (!test_bit(HFP_CODEC_CVSD, &codecs_bitmask)) {
 		ofono_error("CVSD codec is mandatory");
 		return __ofono_error_invalid_args(msg);
 	}
@@ -606,8 +623,7 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 	agent = g_new0(struct agent, 1);
 	agent->owner = g_strdup(sender);
 	agent->path = g_strdup(path);
-	agent->codecs = g_memdup(codecs, length);
-	agent->codecs_len = length;
+	agent->codecs_bitmask = codecs_bitmask;
 	agent->watch = g_dbus_add_disconnect_watch(conn, sender,
 						agent_disconnect, NULL, NULL);
 
-- 
1.7.11.7


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

* [RFC v0 18/20] handsfree-audio: Disable mSBC if defer is off
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (16 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 17/20] handsfree-audio: Use bitmask for supported codecs Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 19/20] bluetooth: Add define for SCO voice settings Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 20/20] handsfree-audio: Add setting SCO air mode Claudio Takahasi
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

If the kernel doesn't support defer setup, this patch disables the mSBC
codec support removing it from the supported codecs bitmask.
---
 src/handsfree-audio.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c0e644c..b644b0b 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -74,6 +74,7 @@ static int ref_count = 0;
 static GSList *card_list = 0;
 static guint sco_watch = 0;
 static GSList *g_drivers = NULL;
+static int defer_setup = 1;
 
 static inline void set_bit(int nr, void *addr)
 {
@@ -85,6 +86,11 @@ static inline int test_bit(int nr, void *addr)
 	return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
 }
 
+static inline void clear_bit(int nr, void *addr)
+{
+	*((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
+}
+
 static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
 	DBusMessage *msg;
@@ -184,7 +190,7 @@ static int sco_init(void)
 {
 	GIOChannel *sco_io;
 	struct sockaddr_sco saddr;
-	int sk, defer_setup = 1;
+	int sk;
 
 	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
 								BTPROTO_SCO);
@@ -202,9 +208,11 @@ static int sco_init(void)
 	}
 
 	if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP,
-				&defer_setup, sizeof(defer_setup)) < 0)
+				&defer_setup, sizeof(defer_setup)) < 0) {
+		defer_setup = 0;
 		ofono_warn("Can't enable deferred setup: %s (%d)",
 						strerror(errno), errno);
+	}
 
 	if (listen(sk, 5) < 0) {
 		close(sk);
@@ -620,6 +628,10 @@ static DBusMessage *am_agent_register(DBusConnection *conn,
 		return __ofono_error_invalid_args(msg);
 	}
 
+	/* Disable mSBC if defer setup is not supported */
+	if (defer_setup == 0 && test_bit(HFP_CODEC_MSBC, &codecs_bitmask))
+		clear_bit(HFP_CODEC_MSBC, &codecs_bitmask);
+
 	agent = g_new0(struct agent, 1);
 	agent->owner = g_strdup(sender);
 	agent->path = g_strdup(path);
-- 
1.7.11.7


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

* [RFC v0 19/20] bluetooth: Add define for SCO voice settings
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (17 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 18/20] handsfree-audio: Disable mSBC if defer is off Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  2013-03-12 14:21 ` [RFC v0 20/20] handsfree-audio: Add setting SCO air mode Claudio Takahasi
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 759 bytes --]

Add defines for SCO voice setting (Air Coding). Air mode "Transparent
Data" shall be supported if wide band speech is supported.
---
 src/bluetooth.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/bluetooth.h b/src/bluetooth.h
index af6f02c..f2fd7d5 100644
--- a/src/bluetooth.h
+++ b/src/bluetooth.h
@@ -54,6 +54,18 @@ struct sockaddr_sco {
 	bdaddr_t	sco_bdaddr;
 };
 
+/* SCO socket options */
+#define SCO_OPTIONS		0x01
+
+#define SCO_MODE_CVSD		0x00
+#define SCO_MODE_TRANSPARENT	0x01
+#define SCO_MODE_ENHANCED	0x02
+
+struct sco_options {
+	uint16_t mtu;
+	uint8_t mode;
+};
+
 static inline void bt_bacpy(bdaddr_t *dst, const bdaddr_t *src)
 {
 	memcpy(dst, src, sizeof(bdaddr_t));
-- 
1.7.11.7


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

* [RFC v0 20/20] handsfree-audio: Add setting SCO air mode
  2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
                   ` (18 preceding siblings ...)
  2013-03-12 14:21 ` [RFC v0 19/20] bluetooth: Add define for SCO voice settings Claudio Takahasi
@ 2013-03-12 14:21 ` Claudio Takahasi
  19 siblings, 0 replies; 24+ messages in thread
From: Claudio Takahasi @ 2013-03-12 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]

---
 src/handsfree-audio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index b644b0b..725b81c 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -91,6 +91,16 @@ static inline void clear_bit(int nr, void *addr)
 	*((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
 }
 
+static uint8_t codec2mode(uint8_t codec)
+{
+	switch (codec) {
+		case HFP_CODEC_CVSD:
+			return SCO_MODE_CVSD;
+		default:
+			return SCO_MODE_TRANSPARENT;
+	}
+}
+
 static void send_new_connection(const char *card, int fd, uint8_t codec)
 {
 	DBusMessage *msg;
@@ -130,6 +140,7 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 {
 	struct ofono_handsfree_card *card;
 	struct sockaddr_sco saddr;
+	struct sco_options options;
 	socklen_t alen;
 	int sk, nsk;
 	char local[18], remote[18];
@@ -180,6 +191,14 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 		card->msg = NULL;
 	}
 
+	memset(&options, 0, sizeof(options));
+	options.mode = codec2mode(card->selected_codec);
+
+	if (setsockopt(sk, SOL_SCO, SCO_OPTIONS, &options,
+						sizeof(options)) < 0)
+		ofono_error("Can't set SCO options: %s (%d)", strerror(errno),
+									errno);
+
 	send_new_connection(card->path, nsk, card->selected_codec);
 	close(nsk);
 
-- 
1.7.11.7


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

* Re: [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs
  2013-03-12 14:21 ` [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs Claudio Takahasi
@ 2013-03-12 17:44   ` Vinicius Costa Gomes
  0 siblings, 0 replies; 24+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-12 17:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1811 bytes --]

Hi,

On 11:21 Tue 12 Mar, Claudio Takahasi wrote:
> From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> 
> Before, the AT+BAC command was being sent with fixed information,
> now we send the command (that inform the AG of the codecs supported by
> the HF) with the codecs supported by the registered Handsfree Audio
> Agent.
> ---
>  drivers/hfpmodem/slc.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hfpmodem/slc.c b/drivers/hfpmodem/slc.c
> index 646befa..b9b687b 100644
> --- a/drivers/hfpmodem/slc.c
> +++ b/drivers/hfpmodem/slc.c
> @@ -34,6 +34,7 @@
>  #include <ofono/log.h>
>  #include <ofono/modem.h>
>  #include <ofono/emulator.h>
> +#include <ofono/handsfree-audio.h>
>  
>  #include <drivers/atmodem/atutil.h>
>  
> @@ -305,9 +306,27 @@ static void brsf_cb(gboolean ok, GAtResult *result, gpointer user_data)
>  	if (info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION &&
>  			info->hf_features & HFP_HF_FEATURE_CODEC_NEGOTIATION) {
>  
> +		unsigned char codecs[8];
> +		GString *str;
> +		int i, len;
> +
> +		len = ofono_handsfree_get_codecs(codecs, sizeof(codecs));
> +		if (len < 0)

This should read "if (len <= 0)". Will fix it in the next round.

> +			goto error;
> +
> +		str = g_string_new("AT+BAC=");
> +
> +		for (i = 0; i < (len - 1); i++)
> +			g_string_append_printf(str, "%d,", codecs[i]);
> +
> +		g_string_append_printf(str, "%d", codecs[i]);
> +
>  		slc_establish_data_ref(sed);
> -		g_at_chat_send(info->chat, "AT+BAC=1", NULL, bac_cb, sed,
> +		g_at_chat_send(info->chat, str->str, NULL, bac_cb, sed,
>  						slc_establish_data_unref);
> +
> +		g_string_free(str, TRUE);
> +
>  		return;
>  	}
>  
> -- 
> 1.7.11.7
> 


Cheers,
-- 
Vinicius

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

* Re: [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 connect implementation
  2013-03-12 14:21 ` [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 " Claudio Takahasi
@ 2013-03-14 17:52   ` Vinicius Costa Gomes
  2013-03-18 19:15     ` Denis Kenzior
  0 siblings, 1 reply; 24+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-14 17:52 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2080 bytes --]

Hi,

On 11:21 Tue 12 Mar, Claudio Takahasi wrote:
> This patch implements the HF initiate SCO connection for devices
> compliant with HFP 1.6. HF sends AT+BCC to inform the AG that audio
> connection is required.
> ---
>  plugins/hfp_hf_bluez5.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
> index 0d5d5c7..6c55657 100644
> --- a/plugins/hfp_hf_bluez5.c
> +++ b/plugins/hfp_hf_bluez5.c
> @@ -364,7 +364,18 @@ static struct ofono_handsfree_card_driver card_driver15 = {
>  static int card_audio_connect16(const char *remote, const char *local,
>  								void *data)
>  {
> -	return 0;
> +	struct ofono_modem *modem = data;
> +	struct hfp *hfp = ofono_modem_get_data(modem);
> +	struct hfp_slc_info *info = &hfp->info;
> +
> +	if (info->chat == NULL)
> +		return -ENOTCONN;
> +
> +	info->chat = g_at_chat_ref(info->chat);
> +	g_at_chat_send(info->chat, "AT+BCC", NULL, NULL, info->chat,
> +					(GDestroyNotify) g_at_chat_unref);

Testing with the iPhone, if there's no audio related things happening on
the phone, audio calls for example, the phone responds with an error.

We need to handle this case, we could think of two alternatives:

1. Adding a timeout when the driver returns -EINPROGRESS, if this timeout
expires before the SCO is established we return an error to the caller of the
Connect method;

2. Adding another method to the handsfree-audio.h API, something like:
"ofono_handsfree_audio_card_falied(card, err)" that would signify that the
audio connection attempt failed before its time.

The main advantage of (1) is that we are covered even in the case that
"AT+BCC" succeeds and the remote device doesn't open an SCO channel.


> +
> +	return -EINPROGRESS;
>  }
>  
>  static struct ofono_handsfree_card_driver card_driver16 = {
> -- 
> 1.7.11.7
> 
> _______________________________________________
> ofono mailing list
> ofono(a)ofono.org
> http://lists.ofono.org/listinfo/ofono


Cheers,
-- 
Vinicius

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

* Re: [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 connect implementation
  2013-03-14 17:52   ` Vinicius Costa Gomes
@ 2013-03-18 19:15     ` Denis Kenzior
  0 siblings, 0 replies; 24+ messages in thread
From: Denis Kenzior @ 2013-03-18 19:15 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2515 bytes --]

Hi Vinicius,

On 03/14/2013 12:52 PM, Vinicius Costa Gomes wrote:
> Hi,
>
> On 11:21 Tue 12 Mar, Claudio Takahasi wrote:
>> This patch implements the HF initiate SCO connection for devices
>> compliant with HFP 1.6. HF sends AT+BCC to inform the AG that audio
>> connection is required.
>> ---
>>   plugins/hfp_hf_bluez5.c | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
>> index 0d5d5c7..6c55657 100644
>> --- a/plugins/hfp_hf_bluez5.c
>> +++ b/plugins/hfp_hf_bluez5.c
>> @@ -364,7 +364,18 @@ static struct ofono_handsfree_card_driver card_driver15 = {
>>   static int card_audio_connect16(const char *remote, const char *local,
>>   								void *data)
>>   {
>> -	return 0;
>> +	struct ofono_modem *modem = data;
>> +	struct hfp *hfp = ofono_modem_get_data(modem);
>> +	struct hfp_slc_info *info =&hfp->info;
>> +
>> +	if (info->chat == NULL)
>> +		return -ENOTCONN;
>> +
>> +	info->chat = g_at_chat_ref(info->chat);
>> +	g_at_chat_send(info->chat, "AT+BCC", NULL, NULL, info->chat,
>> +					(GDestroyNotify) g_at_chat_unref);
>
> Testing with the iPhone, if there's no audio related things happening on
> the phone, audio calls for example, the phone responds with an error.
>
> We need to handle this case, we could think of two alternatives:
>
> 1. Adding a timeout when the driver returns -EINPROGRESS, if this timeout
> expires before the SCO is established we return an error to the caller of the
> Connect method;

Sounds fine

>
> 2. Adding another method to the handsfree-audio.h API, something like:
> "ofono_handsfree_audio_card_falied(card, err)" that would signify that the
> audio connection attempt failed before its time.

No, don't do this

>
> The main advantage of (1) is that we are covered even in the case that
> "AT+BCC" succeeds and the remote device doesn't open an SCO channel.
>

The problem is that the spec does not suggest any timing relationship 
between AT+BCC and the SCO establishment.  I suggest we ignore this case 
for now and simply return success / failure from Connect() based on the 
result of AT+BCC.

>
>> +
>> +	return -EINPROGRESS;
>>   }
>>
>>   static struct ofono_handsfree_card_driver card_driver16 = {
>> --
>> 1.7.11.7
>>
>> _______________________________________________
>> ofono mailing list
>> ofono(a)ofono.org
>> http://lists.ofono.org/listinfo/ofono
>
>
> Cheers,

Regards,
-Denis

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

end of thread, other threads:[~2013-03-18 19:15 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-12 14:21 [RFC v0 00/20] HFP1.6: Codec negotiation and HF Connect Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 01/20] handsfree-audio: Add card driver for HFP 1.6 Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 02/20] handsfree-audio: Add user data to card driver Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 03/20] hfp_hf_bluez5: Pass modem as user data Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 04/20] handsfree-audio: Add user data to connect declaration Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 05/20] hfp_hf_bluez5: Add user data to connect implementation Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 06/20] hfp_hf_bluez5: Add HFP 1.6 " Claudio Takahasi
2013-03-14 17:52   ` Vinicius Costa Gomes
2013-03-18 19:15     ` Denis Kenzior
2013-03-12 14:21 ` [RFC v0 07/20] handsfree-audio: Add HFP 1.6 connect hook Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 08/20] handsfree-audio: Add "Connect" reply for HFP 1.6 Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 09/20] handsfree-audio: Add function to get the codecs Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 10/20] hfpmodem: Send AT+BAC with the supported codecs Claudio Takahasi
2013-03-12 17:44   ` Vinicius Costa Gomes
2013-03-12 14:21 ` [RFC v0 11/20] hfpmodem: Add codec watcher register Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 12/20] hfp_hf_bluez5: Register codec watcher Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 13/20] handsfree-audio: Add function to select the codec Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 14/20] hfp_hf_bluez5: Set the audio codec in the card Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 15/20] handsfree-audio: Send the selected codec Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 16/20] handsfree-audio: Set CVSD as default in the card Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 17/20] handsfree-audio: Use bitmask for supported codecs Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 18/20] handsfree-audio: Disable mSBC if defer is off Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 19/20] bluetooth: Add define for SCO voice settings Claudio Takahasi
2013-03-12 14:21 ` [RFC v0 20/20] handsfree-audio: Add setting SCO air mode Claudio Takahasi

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.