All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 00/22] HFP 1.6 AG implementation
@ 2013-05-16 17:16 Paulo Borges
  2013-05-16 17:16 ` [RFC 01/22] include: Add ofono_emulator_create_card() Paulo Borges
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

PTS fails in tests related to codec negotiation when the driverless
approach to AG implementation is used. So I am sending this series that
uses card driver as a RFC to get feedback from the mailing list.

This series needs two not-yet-upstream patches from Vinicius Gomes.

Paulo Borges (22):
  include: Add ofono_emulator_create_card()
  emulator: Implement ofono_emulator_create_card()
  hfp_ag_bluez5: Create card when connect
  emulator: Register card when establish SLC
  emulator: Set local and remote address of card
  hfp_ag_bluez5: Check if card creation fails
  include: Add emulator init and cleanup functions
  emulator: Implement init and cleanup functions
  main: Call emulator init and cleanup functions
  emulator: Add HFP 1.6 AG card driver
  emulator: Set card driver
  hfp_ag_bluez5: Send HFP version to card creation
  hfp_ag_bluez5: Register HFP AG version 1.6
  emulator: Add AT+BAC support
  emulator: Add AT+BCC support
  emulator: Setup codec connection
  emulator: Add AT+BCS support
  emulator: Resend +BCS after receive AT+BAC
  emulator: Setup synchronous connection
  emulator: Reuse last negotiated codec
  emulator: Copy callback mechanism from atutil.h
  emulator: Implement AG card .Connect() for HFP 1.6

 include/emulator.h      |    2 +
 plugins/hfp_ag_bluez5.c |   55 +++++++-
 src/emulator.c          |  345 +++++++++++++++++++++++++++++++++++++++++++++++
 src/main.c              |    4 +
 src/ofono.h             |    3 +
 5 files changed, 408 insertions(+), 1 deletion(-)

-- 
1.7.9.5


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

* [RFC 01/22] include: Add ofono_emulator_create_card()
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 02/22] emulator: Implement ofono_emulator_create_card() Paulo Borges
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 include/emulator.h |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/emulator.h b/include/emulator.h
index 5cd894b..f4e9115 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -74,6 +74,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd);
 
 void ofono_emulator_remove(struct ofono_emulator *em);
 
+int ofono_emulator_create_card(struct ofono_emulator *em, int version);
+
 void ofono_emulator_send_final(struct ofono_emulator *em,
 				const struct ofono_error *final);
 void ofono_emulator_send_unsolicited(struct ofono_emulator *em,
-- 
1.7.9.5


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

* [RFC 02/22] emulator: Implement ofono_emulator_create_card()
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
  2013-05-16 17:16 ` [RFC 01/22] include: Add ofono_emulator_create_card() Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 03/22] hfp_ag_bluez5: Create card when connect Paulo Borges
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This patch adds a Handsfree Audio Card to the emulator structure and a
function to create it. When the emulator is about to be removed, its
card is also removed.
---
 src/emulator.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 70505b5..48998f5 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -29,6 +29,9 @@
 
 #include <glib.h>
 
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/handsfree-audio.h>
+
 #include "ofono.h"
 #include "common.h"
 #include "hfp.h"
@@ -53,6 +56,7 @@ struct ofono_emulator {
 	gboolean clip;
 	gboolean ccwa;
 	int pns_id;
+	struct ofono_handsfree_card *card;
 };
 
 struct indicator {
@@ -880,6 +884,11 @@ static void emulator_unregister(struct ofono_atom *atom)
 
 	g_at_server_unref(em->server);
 	em->server = NULL;
+
+	if (em->card) {
+		ofono_handsfree_card_remove(em->card);
+		em->card = NULL;
+	}
 }
 
 void ofono_emulator_register(struct ofono_emulator *em, int fd)
@@ -990,6 +999,13 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	return em;
 }
 
+int ofono_emulator_create_card(struct ofono_emulator *em, int version)
+{
+	em->card = ofono_handsfree_card_create(0, NULL, NULL);
+
+	return 0;
+}
+
 void ofono_emulator_remove(struct ofono_emulator *em)
 {
 	__ofono_atom_free(em->atom);
-- 
1.7.9.5


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

* [RFC 03/22] hfp_ag_bluez5: Create card when connect
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
  2013-05-16 17:16 ` [RFC 01/22] include: Add ofono_emulator_create_card() Paulo Borges
  2013-05-16 17:16 ` [RFC 02/22] emulator: Implement ofono_emulator_create_card() Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 04/22] emulator: Register card when establish SLC Paulo Borges
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

When the HFP AG plugin accepts an incoming connection it now creates a
Handsfree Audio Card for the corresponding emulator.
---
 plugins/hfp_ag_bluez5.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 245de21..64a786c 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -122,6 +122,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	}
 
 	ofono_emulator_register(em, fd);
+	ofono_emulator_create_card(em, 0);
 
 	fd_dup = dup(fd);
 	io = g_io_channel_unix_new(fd_dup);
-- 
1.7.9.5


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

* [RFC 04/22] emulator: Register card when establish SLC
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (2 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 03/22] hfp_ag_bluez5: Create card when connect Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 05/22] emulator: Set local and remote address of card Paulo Borges
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

When the service level connection is established, the emulator now
registers its Handsfree Audio Card. This registers a DBus interface
for that card.
---
 src/emulator.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 48998f5..b75d0bd 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -641,6 +641,9 @@ done:
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
 
 		em->slc = TRUE;
+
+		ofono_handsfree_card_register(em->card);
+
 		break;
 	}
 
-- 
1.7.9.5


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

* [RFC 05/22] emulator: Set local and remote address of card
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (3 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 04/22] emulator: Register card when establish SLC Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 06/22] hfp_ag_bluez5: Check if card creation fails Paulo Borges
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This commit extracts local and remote address from the socket and
stores them into the Handsfree Audio Card.
---
 src/emulator.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/emulator.c b/src/emulator.c
index b75d0bd..079a5b8 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -23,11 +23,15 @@
 #include <config.h>
 #endif
 
+#include <stdlib.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <glib.h>
+#include <sys/socket.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
 #include <ofono/handsfree-audio.h>
@@ -37,6 +41,7 @@
 #include "hfp.h"
 #include "gatserver.h"
 #include "gatppp.h"
+#include "bluetooth.h"
 
 #define RING_TIMEOUT 3
 
@@ -1002,11 +1007,56 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	return em;
 }
 
+static int card_set_local_remote(struct ofono_handsfree_card *card, int fd)
+{
+	struct sockaddr_rc saddr;
+	socklen_t optlen;
+	char local[18], remote[18];
+	int err;
+
+	memset(&saddr, 0, sizeof(saddr));
+	optlen = sizeof(saddr);
+
+	if (getsockname(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+		err = errno;
+		ofono_error("RFCOMM getsockname: %s (%d)", strerror(err), err);
+		return -err;
+	}
+
+	bt_ba2str(&saddr.rc_bdaddr, local);
+
+	DBG("local %s", local);
+
+	memset(&saddr, 0, sizeof(saddr));
+	optlen = sizeof(saddr);
+
+	if (getpeername(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+		err = errno;
+		ofono_error("RFCOMM getpeername: %s (%d)", strerror(err), err);
+		return -err;
+	}
+
+	bt_ba2str(&saddr.rc_bdaddr, remote);
+
+	DBG("remote %s", remote);
+
+	ofono_handsfree_card_set_local(card, local);
+	ofono_handsfree_card_set_remote(card, remote);
+
+	return 0;
+}
+
 int ofono_emulator_create_card(struct ofono_emulator *em, int version)
 {
+	GIOChannel *io;
+	int fd;
+
 	em->card = ofono_handsfree_card_create(0, NULL, NULL);
 
-	return 0;
+	io = g_at_server_get_channel(em->server);
+	fd = g_io_channel_unix_get_fd(io);
+
+	return card_set_local_remote(em->card, fd);
 }
 
 void ofono_emulator_remove(struct ofono_emulator *em)
-- 
1.7.9.5


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

* [RFC 06/22] hfp_ag_bluez5: Check if card creation fails
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (4 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 05/22] emulator: Set local and remote address of card Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 07/22] include: Add emulator init and cleanup functions Paulo Borges
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

If the card creation fails, the HFP AG plugin aborts the connection
and removes the emulator.
---
 plugins/hfp_ag_bluez5.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 64a786c..6451be4 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -122,7 +122,14 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	}
 
 	ofono_emulator_register(em, fd);
-	ofono_emulator_create_card(em, 0);
+
+	if (ofono_emulator_create_card(em, 0) < 0) {
+		close(fd);
+		ofono_emulator_remove(em);
+		return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".Rejected",
+						"Not enough resources");
+	}
 
 	fd_dup = dup(fd);
 	io = g_io_channel_unix_new(fd_dup);
-- 
1.7.9.5


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

* [RFC 07/22] include: Add emulator init and cleanup functions
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (5 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 06/22] hfp_ag_bluez5: Check if card creation fails Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 08/22] emulator: Implement " Paulo Borges
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 src/ofono.h |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/ofono.h b/src/ofono.h
index 8abaf1e..030e559 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -33,6 +33,9 @@ void __ofono_manager_cleanup(void);
 int __ofono_handsfree_audio_manager_init(void);
 void __ofono_handsfree_audio_manager_cleanup(void);
 
+int __ofono_emulator_init(void);
+void __ofono_emulator_cleanup(void);
+
 void __ofono_modem_shutdown(void);
 
 #include <ofono/log.h>
-- 
1.7.9.5


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

* [RFC 08/22] emulator: Implement init and cleanup functions
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (6 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 07/22] include: Add emulator init and cleanup functions Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 09/22] main: Call emulator " Paulo Borges
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 src/emulator.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 079a5b8..8ac79d5 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -1335,3 +1335,12 @@ void __ofono_emulator_set_indicator_forced(struct ofono_emulator *em,
 			ind->deferred = TRUE;
 	}
 }
+
+int __ofono_emulator_init(void)
+{
+	return 0;
+}
+
+void __ofono_emulator_cleanup(void)
+{
+}
-- 
1.7.9.5


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

* [RFC 09/22] main: Call emulator init and cleanup functions
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (7 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 08/22] emulator: Implement " Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 10/22] emulator: Add HFP 1.6 AG card driver Paulo Borges
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 src/main.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/main.c b/src/main.c
index d6349cb..38aff7d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -241,6 +241,8 @@ int main(int argc, char **argv)
 
 	__ofono_handsfree_audio_manager_init();
 
+	__ofono_emulator_init();
+
 	__ofono_plugin_init(option_plugin, option_noplugin);
 
 	g_free(option_plugin);
@@ -250,6 +252,8 @@ int main(int argc, char **argv)
 
 	__ofono_plugin_cleanup();
 
+	__ofono_emulator_cleanup();
+
 	__ofono_handsfree_audio_manager_cleanup();
 
 	__ofono_manager_cleanup();
-- 
1.7.9.5


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

* [RFC 10/22] emulator: Add HFP 1.6 AG card driver
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (8 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 09/22] main: Call emulator " Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 11/22] emulator: Set " Paulo Borges
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This commit adds a Handsfree Audio Card driver for HFP AG 1.6.

The current connect implementation is the legacy one (direct SCO
connection without codec negotiation).
---
 src/emulator.c |   30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/emulator.c b/src/emulator.c
index 8ac79d5..a2e895a 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -45,6 +45,8 @@
 
 #define RING_TIMEOUT 3
 
+#define HFP_16_AG_DRIVER "hfp16-ag-driver"
+
 struct ofono_emulator {
 	struct ofono_atom *atom;
 	enum ofono_emulator_type type;
@@ -1007,6 +1009,31 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	return em;
 }
 
+static int hfp16_card_probe(struct ofono_handsfree_card *card,
+					unsigned int vendor, void *data)
+{
+	return 0;
+}
+
+static void hfp16_card_remove(struct ofono_handsfree_card *card)
+{
+}
+
+static void hfp16_card_connect(struct ofono_handsfree_card *card,
+			ofono_handsfree_card_connect_cb_t cb, void *data)
+{
+	DBG("");
+
+	ofono_handsfree_card_connect_sco(card);
+}
+
+static struct ofono_handsfree_card_driver hfp16_ag_driver = {
+	.name		= HFP_16_AG_DRIVER,
+	.probe		= hfp16_card_probe,
+	.remove		= hfp16_card_remove,
+	.connect	= hfp16_card_connect,
+};
+
 static int card_set_local_remote(struct ofono_handsfree_card *card, int fd)
 {
 	struct sockaddr_rc saddr;
@@ -1338,9 +1365,10 @@ void __ofono_emulator_set_indicator_forced(struct ofono_emulator *em,
 
 int __ofono_emulator_init(void)
 {
-	return 0;
+	return ofono_handsfree_card_driver_register(&hfp16_ag_driver);
 }
 
 void __ofono_emulator_cleanup(void)
 {
+	ofono_handsfree_card_driver_unregister(&hfp16_ag_driver);
 }
-- 
1.7.9.5


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

* [RFC 11/22] emulator: Set card driver
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (9 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 10/22] emulator: Add HFP 1.6 AG card driver Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 12/22] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

If the version is 1.6, send the corresponding card driver name to card
creation. If the version is not 1.6, send NULL.
---
 src/emulator.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/emulator.c b/src/emulator.c
index a2e895a..490ee73 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -1075,10 +1075,14 @@ static int card_set_local_remote(struct ofono_handsfree_card *card, int fd)
 
 int ofono_emulator_create_card(struct ofono_emulator *em, int version)
 {
+	char *driver = NULL;
 	GIOChannel *io;
 	int fd;
 
-	em->card = ofono_handsfree_card_create(0, NULL, NULL);
+	if (version == HFP_VERSION_1_6)
+		driver = HFP_16_AG_DRIVER;
+
+	em->card = ofono_handsfree_card_create(0, driver, NULL);
 
 	io = g_at_server_get_channel(em->server);
 	fd = g_io_channel_unix_get_fd(io);
-- 
1.7.9.5


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

* [RFC 12/22] hfp_ag_bluez5: Send HFP version to card creation
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (10 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 11/22] emulator: Set " Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 13/22] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

Extract the version from the fd_properties dictionary, if present.
Fallback to HFP version 1.5 if not present.

After that, send it to the card creation.
---
 plugins/hfp_ag_bluez5.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 6451be4..4523165 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -70,6 +70,45 @@ static gboolean io_hup_cb(GIOChannel *io, GIOCondition cond, gpointer data)
 	return FALSE;
 }
 
+static int get_version(DBusMessageIter *iter, uint16_t *version)
+{
+	DBusMessageIter dict, entry, valiter;
+	const char *key;
+	uint16_t value = HFP_VERSION_1_5;
+
+	/* Points to dict */
+	dbus_message_iter_recurse(iter, &dict);
+
+	/* For each entry in this dict */
+	while (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_INVALID) {
+		/* I want to access the entry's contents */
+		dbus_message_iter_recurse(&dict, &entry);
+
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return -EINVAL;
+
+		/* If the current key isn't "Version", keep looking */
+		dbus_message_iter_get_basic(&entry, &key);
+		if (!g_str_equal("Version", key)) {
+			dbus_message_iter_next(&dict);
+			continue;
+		}
+
+		dbus_message_iter_next(&entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+			return -EINVAL;
+
+		dbus_message_iter_recurse(&entry, &valiter);
+		dbus_message_iter_get_basic(&valiter, &value);
+		break;
+	}
+
+	if (version)
+		*version = value;
+
+	return 0;
+}
+
 static DBusMessage *profile_new_connection(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
@@ -79,6 +118,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	int fd, fd_dup;
 	struct ofono_emulator *em;
 	struct ofono_modem *modem;
+	uint16_t version;
 
 	DBG("Profile handler NewConnection");
 
@@ -100,6 +140,11 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	if (fd < 0)
 		goto invalid;
 
+	if (get_version(&entry, &version) < 0) {
+		close(fd);
+		goto invalid;
+	}
+
 	DBG("%s", device);
 
 	/* Pick the first voicecall capable modem */
@@ -123,7 +168,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	ofono_emulator_register(em, fd);
 
-	if (ofono_emulator_create_card(em, 0) < 0) {
+	if (ofono_emulator_create_card(em, version) < 0) {
 		close(fd);
 		ofono_emulator_remove(em);
 		return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-- 
1.7.9.5


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

* [RFC 13/22] hfp_ag_bluez5: Register HFP AG version 1.6
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (11 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 12/22] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 14/22] emulator: Add AT+BAC support Paulo Borges
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 plugins/hfp_ag_bluez5.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 4523165..58785d1 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -285,7 +285,7 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
 	if (modems->next != NULL)
 		return;
 
-	bt_register_profile(conn, HFP_AG_UUID, HFP_VERSION_1_5, "hfp_ag",
+	bt_register_profile(conn, HFP_AG_UUID, HFP_VERSION_1_6, "hfp_ag",
 					HFP_AG_EXT_PROFILE_PATH, NULL, 0);
 }
 
-- 
1.7.9.5


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

* [RFC 14/22] emulator: Add AT+BAC support
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (12 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 13/22] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 15/22] emulator: Add AT+BCC support Paulo Borges
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

When the emulator receives a AT+BAC SET command, it stores the
available HF codecs.
---
 src/emulator.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 490ee73..24c5e48 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -55,6 +55,7 @@ struct ofono_emulator {
 	gboolean slc;
 	int l_features;
 	int r_features;
+	int r_codecs;
 	int events_mode;
 	gboolean events_ind;
 	unsigned char cmee_mode;
@@ -481,6 +482,36 @@ fail:
 	}
 }
 
+static void bac_cb(GAtServer *server, GAtServerRequestType type,
+					GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GAtResultIter iter;
+	int codec, codecs = 0;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		while (g_at_result_iter_next_number(&iter, &codec))
+			codecs |= codec;
+
+		if (!(codecs & HFP_CODEC_CVSD))
+			goto fail;
+
+		em->r_codecs = codecs;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+
 static void cind_cb(GAtServer *server, GAtServerRequestType type,
 			GAtResult *result, gpointer user_data)
 {
@@ -941,6 +972,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 									FALSE);
 
 		g_at_server_register(em->server, "+BRSF", brsf_cb, em, NULL);
+		g_at_server_register(em->server, "+BAC", bac_cb, em, NULL);
 		g_at_server_register(em->server, "+CIND", cind_cb, em, NULL);
 		g_at_server_register(em->server, "+CMER", cmer_cb, em, NULL);
 		g_at_server_register(em->server, "+CLIP", clip_cb, em, NULL);
-- 
1.7.9.5


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

* [RFC 15/22] emulator: Add AT+BCC support
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (13 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 14/22] emulator: Add AT+BAC support Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 16/22] emulator: Setup codec connection Paulo Borges
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This commit verifies the conditions where the AT+BCC command will fail.

The codec connection setup is missing.
---
 src/emulator.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 24c5e48..f358a0e 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -871,6 +871,30 @@ fail:
 	}
 }
 
+static void bcc_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+
+	switch(type) {
+	case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
+		if (!em->slc)
+			goto fail;
+
+		if (!(em->l_features & HFP_AG_FEATURE_CODEC_NEGOTIATION) &&
+			!(em->r_features & HFP_HF_FEATURE_CODEC_NEGOTIATION))
+			goto fail;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt,
 					gboolean mandatory)
@@ -979,6 +1003,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+CCWA", ccwa_cb, em, NULL);
 		g_at_server_register(em->server, "+CMEE", cmee_cb, em, NULL);
 		g_at_server_register(em->server, "+BIA", bia_cb, em, NULL);
+		g_at_server_register(em->server, "+BCC", bcc_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
-- 
1.7.9.5


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

* [RFC 16/22] emulator: Setup codec connection
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (14 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 15/22] emulator: Add AT+BCC support Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 17/22] emulator: Add AT+BCS support Paulo Borges
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This commit sends an unsolicited +BCS command with the selected codec
when the AG receives with success a AT+BCC command.

Currently the codec is hardcoded to CVSD.
---
 src/emulator.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index f358a0e..96e6ad1 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -61,6 +61,7 @@ struct ofono_emulator {
 	unsigned char cmee_mode;
 	GSList *indicators;
 	guint callsetup_source;
+	guint audiosetup_source;
 	gboolean clip;
 	gboolean ccwa;
 	int pns_id;
@@ -449,6 +450,21 @@ static gboolean notify_ring(void *user_data)
 	return TRUE;
 }
 
+static gboolean setup_codec_connection(void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+	char str[16];
+
+	DBG("");
+
+	sprintf(str, "+BCS: %d", HFP_CODEC_CVSD);
+	g_at_server_send_unsolicited(em->server, str);
+
+	em->audiosetup_source = 0;
+
+	return FALSE;
+}
+
 static void brsf_cb(GAtServer *server, GAtServerRequestType type,
 			GAtResult *result, gpointer user_data)
 {
@@ -886,6 +902,10 @@ static void bcc_cb(GAtServer *server, GAtServerRequestType type,
 			goto fail;
 
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+
+		em->audiosetup_source = g_timeout_add_seconds(0,
+						setup_codec_connection, em);
+
 		break;
 
 	default:
@@ -929,6 +949,11 @@ static void emulator_unregister(struct ofono_atom *atom)
 		em->callsetup_source = 0;
 	}
 
+	if (em->audiosetup_source) {
+		g_source_remove(em->audiosetup_source);
+		em->audiosetup_source = 0;
+	}
+
 	for (l = em->indicators; l; l = l->next) {
 		struct indicator *ind = l->data;
 
-- 
1.7.9.5


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

* [RFC 17/22] emulator: Add AT+BCS support
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (15 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 16/22] emulator: Setup codec connection Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 18/22] emulator: Resend +BCS after receive AT+BAC Paulo Borges
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

This commit verifies if the codec id sent by HF is the same as
previous sent by AG.

It also verifies if the emulator is expecting a AT+BCS command. If not,
returns an ERROR.

We also need to unset the bcs flag in AT+BAC handler because it is a
valid +BCS response.
---
 src/emulator.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 96e6ad1..a228df4 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -64,6 +64,7 @@ struct ofono_emulator {
 	guint audiosetup_source;
 	gboolean clip;
 	gboolean ccwa;
+	gboolean bcs;
 	int pns_id;
 	struct ofono_handsfree_card *card;
 };
@@ -450,6 +451,41 @@ static gboolean notify_ring(void *user_data)
 	return TRUE;
 }
 
+static void bcs_cb(GAtServer *server, GAtServerRequestType type,
+				GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GAtResultIter iter;
+	int codec;
+
+	if (!em->bcs)
+		goto fail;
+
+	em->bcs = FALSE;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (g_at_result_iter_next_number(&iter, &codec) == FALSE)
+			goto fail;
+
+		if (codec != HFP_CODEC_CVSD)
+			goto fail;
+
+		ofono_handsfree_card_set_codec(em->card, codec);
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+
 static gboolean setup_codec_connection(void *user_data)
 {
 	struct ofono_emulator *em = user_data;
@@ -460,6 +496,7 @@ static gboolean setup_codec_connection(void *user_data)
 	sprintf(str, "+BCS: %d", HFP_CODEC_CVSD);
 	g_at_server_send_unsolicited(em->server, str);
 
+	em->bcs = TRUE;
 	em->audiosetup_source = 0;
 
 	return FALSE;
@@ -505,6 +542,8 @@ static void bac_cb(GAtServer *server, GAtServerRequestType type,
 	GAtResultIter iter;
 	int codec, codecs = 0;
 
+	em->bcs = FALSE;
+
 	switch (type) {
 	case G_AT_SERVER_REQUEST_TYPE_SET:
 		g_at_result_iter_init(&iter, result);
@@ -1028,6 +1067,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+CCWA", ccwa_cb, em, NULL);
 		g_at_server_register(em->server, "+CMEE", cmee_cb, em, NULL);
 		g_at_server_register(em->server, "+BIA", bia_cb, em, NULL);
+		g_at_server_register(em->server, "+BCS", bcs_cb, em, NULL);
 		g_at_server_register(em->server, "+BCC", bcc_cb, em, NULL);
 	}
 
-- 
1.7.9.5


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

* [RFC 18/22] emulator: Resend +BCS after receive AT+BAC
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (16 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 17/22] emulator: Add AT+BCS support Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 19/22] emulator: Setup synchronous connection Paulo Borges
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

If the AG receives AT+BAC as a response to an unsolicited +BCS, it
will resend +BCS based on new list of available codecs.
---
 src/emulator.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index a228df4..7f6604a 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -541,6 +541,7 @@ static void bac_cb(GAtServer *server, GAtServerRequestType type,
 	struct ofono_emulator *em = user_data;
 	GAtResultIter iter;
 	int codec, codecs = 0;
+	gboolean bcs = em->bcs;
 
 	em->bcs = FALSE;
 
@@ -558,6 +559,11 @@ static void bac_cb(GAtServer *server, GAtServerRequestType type,
 		em->r_codecs = codecs;
 
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+
+		if (bcs)
+			em->audiosetup_source = g_timeout_add_seconds(0,
+						setup_codec_connection, em);
+
 		break;
 
 	default:
-- 
1.7.9.5


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

* [RFC 19/22] emulator: Setup synchronous connection
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (17 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 18/22] emulator: Resend +BCS after receive AT+BAC Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 20/22] emulator: Reuse last negotiated codec Paulo Borges
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

After respond OK to AT+BCS, the AG should establish a synchronous
connection with HF.
---
 src/emulator.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 7f6604a..84b07e6 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -451,6 +451,19 @@ static gboolean notify_ring(void *user_data)
 	return TRUE;
 }
 
+static gboolean setup_synchronous_connection(void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+
+	DBG("");
+
+	ofono_handsfree_card_connect_sco(em->card);
+
+	em->audiosetup_source = 0;
+
+	return FALSE;
+}
+
 static void bcs_cb(GAtServer *server, GAtServerRequestType type,
 				GAtResult *result, gpointer user_data)
 {
@@ -477,6 +490,10 @@ static void bcs_cb(GAtServer *server, GAtServerRequestType type,
 		ofono_handsfree_card_set_codec(em->card, codec);
 
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+
+		em->audiosetup_source = g_timeout_add_seconds(0,
+					setup_synchronous_connection, em);
+
 		break;
 
 	default:
-- 
1.7.9.5


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

* [RFC 20/22] emulator: Reuse last negotiated codec
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (18 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 19/22] emulator: Setup synchronous connection Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 21/22] emulator: Copy callback mechanism from atutil.h Paulo Borges
  2013-05-16 17:16 ` [RFC 22/22] emulator: Implement AG card .Connect() for HFP 1.6 Paulo Borges
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

If a synchronous connection will be established and the last used
codec is still available, the AG will use it instead of negotiate.
---
 src/emulator.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 84b07e6..2ce1542 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -56,6 +56,7 @@ struct ofono_emulator {
 	int l_features;
 	int r_features;
 	int r_codecs;
+	int last_codec;
 	int events_mode;
 	gboolean events_ind;
 	unsigned char cmee_mode;
@@ -488,6 +489,7 @@ static void bcs_cb(GAtServer *server, GAtServerRequestType type,
 			goto fail;
 
 		ofono_handsfree_card_set_codec(em->card, codec);
+		em->last_codec = codec;
 
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
 
@@ -510,10 +512,15 @@ static gboolean setup_codec_connection(void *user_data)
 
 	DBG("");
 
-	sprintf(str, "+BCS: %d", HFP_CODEC_CVSD);
-	g_at_server_send_unsolicited(em->server, str);
+	if (em->r_codecs & em->last_codec) {
+		setup_synchronous_connection(em);
+	} else {
+		sprintf(str, "+BCS: %d", HFP_CODEC_CVSD);
+		g_at_server_send_unsolicited(em->server, str);
+
+		em->bcs = TRUE;
+	}
 
-	em->bcs = TRUE;
 	em->audiosetup_source = 0;
 
 	return FALSE;
-- 
1.7.9.5


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

* [RFC 21/22] emulator: Copy callback mechanism from atutil.h
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (19 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 20/22] emulator: Reuse last negotiated codec Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  2013-05-16 17:16 ` [RFC 22/22] emulator: Implement AG card .Connect() for HFP 1.6 Paulo Borges
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

atutil.h needs GAtChat and GAtResult definitions and we do not have
these definitions inside emulator.c.
---
 src/emulator.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/emulator.c b/src/emulator.c
index 2ce1542..c468452 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -47,6 +47,28 @@
 
 #define HFP_16_AG_DRIVER "hfp16-ag-driver"
 
+#define CALLBACK_WITH_FAILURE(cb, args...)		\
+	do {						\
+		struct ofono_error cb_e;		\
+		cb_e.type = OFONO_ERROR_TYPE_FAILURE;	\
+		cb_e.error = 0;				\
+							\
+		cb(&cb_e, ##args);			\
+	} while (0)					\
+
+#define CALLBACK_WITH_SUCCESS(cb, args...)		\
+	do {						\
+		struct ofono_error e;			\
+		e.type = OFONO_ERROR_TYPE_NO_ERROR;	\
+		e.error = 0;				\
+		cb(&e, ##args);				\
+	} while (0)
+
+struct cb_data {
+	void *cb;
+	void *data;
+};
+
 struct ofono_emulator {
 	struct ofono_atom *atom;
 	enum ofono_emulator_type type;
@@ -80,6 +102,17 @@ struct indicator {
 	gboolean mandatory;
 };
 
+static inline struct cb_data *cb_data_new(void *cb, void *data)
+{
+	struct cb_data *ret;
+
+	ret = g_new0(struct cb_data, 1);
+	ret->cb = cb;
+	ret->data = data;
+
+	return ret;
+}
+
 static void emulator_debug(const char *str, void *data)
 {
 	ofono_info("%s: %s\n", (char *)data, str);
-- 
1.7.9.5


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

* [RFC 22/22] emulator: Implement AG card .Connect() for HFP 1.6
  2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
                   ` (20 preceding siblings ...)
  2013-05-16 17:16 ` [RFC 21/22] emulator: Copy callback mechanism from atutil.h Paulo Borges
@ 2013-05-16 17:16 ` Paulo Borges
  21 siblings, 0 replies; 23+ messages in thread
From: Paulo Borges @ 2013-05-16 17:16 UTC (permalink / raw)
  To: ofono

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

---
 src/emulator.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index c468452..8b4fd80 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -90,6 +90,7 @@ struct ofono_emulator {
 	gboolean bcs;
 	int pns_id;
 	struct ofono_handsfree_card *card;
+	struct cb_data *codec_data;
 };
 
 struct indicator {
@@ -485,6 +486,26 @@ static gboolean notify_ring(void *user_data)
 	return TRUE;
 }
 
+static void call_card_connect_callback(struct ofono_emulator *em,
+							GAtServerResult result)
+{
+	struct cb_data *cbd = em->codec_data;
+	ofono_handsfree_card_connect_cb_t cb;
+
+	if (cbd == NULL)
+		return;
+
+	cb = cbd->cb;
+
+	if (result == G_AT_SERVER_RESULT_OK)
+		CALLBACK_WITH_SUCCESS(cb, cbd->data);
+	else
+		CALLBACK_WITH_FAILURE(cb, cbd->data);
+
+	g_free(cbd);
+	em->codec_data = NULL;
+}
+
 static gboolean setup_synchronous_connection(void *user_data)
 {
 	struct ofono_emulator *em = user_data;
@@ -533,14 +554,19 @@ static void bcs_cb(GAtServer *server, GAtServerRequestType type,
 
 	default:
 fail:
+		call_card_connect_callback(em, G_AT_SERVER_RESULT_ERROR);
+
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+
 		break;
 	}
+
+	
 }
 
-static gboolean setup_codec_connection(void *user_data)
+static void setup_codec_connection(struct ofono_emulator *em,
+							struct cb_data *cbd)
 {
-	struct ofono_emulator *em = user_data;
 	char str[16];
 
 	DBG("");
@@ -554,6 +580,15 @@ static gboolean setup_codec_connection(void *user_data)
 		em->bcs = TRUE;
 	}
 
+	em->codec_data = cbd;
+}
+
+static gboolean call_setup_codec_connection(void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+
+	setup_codec_connection(em, NULL);
+
 	em->audiosetup_source = 0;
 
 	return FALSE;
@@ -619,13 +654,18 @@ static void bac_cb(GAtServer *server, GAtServerRequestType type,
 
 		if (bcs)
 			em->audiosetup_source = g_timeout_add_seconds(0,
-						setup_codec_connection, em);
+					call_setup_codec_connection, em);
 
 		break;
 
 	default:
 fail:
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+
+		if (bcs)
+			call_card_connect_callback(em,
+						G_AT_SERVER_RESULT_ERROR);
+
 		break;
 	}
 }
@@ -1006,7 +1046,7 @@ static void bcc_cb(GAtServer *server, GAtServerRequestType type,
 		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
 
 		em->audiosetup_source = g_timeout_add_seconds(0,
-						setup_codec_connection, em);
+					call_setup_codec_connection, em);
 
 		break;
 
@@ -1207,8 +1247,17 @@ static void hfp16_card_remove(struct ofono_handsfree_card *card)
 static void hfp16_card_connect(struct ofono_handsfree_card *card,
 			ofono_handsfree_card_connect_cb_t cb, void *data)
 {
+	struct ofono_emulator *em = ofono_handsfree_card_get_data(card);
+
 	DBG("");
 
+	if (em->r_features & HFP_HF_FEATURE_CODEC_NEGOTIATION &&
+			em->l_features & HFP_AG_FEATURE_CODEC_NEGOTIATION) {
+		struct cb_data *cbd = cb_data_new(cb, data);
+		setup_codec_connection(em, cbd);
+		return;
+	}
+
 	ofono_handsfree_card_connect_sco(card);
 }
 
@@ -1268,6 +1317,7 @@ int ofono_emulator_create_card(struct ofono_emulator *em, int version)
 		driver = HFP_16_AG_DRIVER;
 
 	em->card = ofono_handsfree_card_create(0, driver, NULL);
+	ofono_handsfree_card_set_data(em->card, em);
 
 	io = g_at_server_get_channel(em->server);
 	fd = g_io_channel_unix_get_fd(io);
-- 
1.7.9.5


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

end of thread, other threads:[~2013-05-16 17:16 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-16 17:16 [RFC 00/22] HFP 1.6 AG implementation Paulo Borges
2013-05-16 17:16 ` [RFC 01/22] include: Add ofono_emulator_create_card() Paulo Borges
2013-05-16 17:16 ` [RFC 02/22] emulator: Implement ofono_emulator_create_card() Paulo Borges
2013-05-16 17:16 ` [RFC 03/22] hfp_ag_bluez5: Create card when connect Paulo Borges
2013-05-16 17:16 ` [RFC 04/22] emulator: Register card when establish SLC Paulo Borges
2013-05-16 17:16 ` [RFC 05/22] emulator: Set local and remote address of card Paulo Borges
2013-05-16 17:16 ` [RFC 06/22] hfp_ag_bluez5: Check if card creation fails Paulo Borges
2013-05-16 17:16 ` [RFC 07/22] include: Add emulator init and cleanup functions Paulo Borges
2013-05-16 17:16 ` [RFC 08/22] emulator: Implement " Paulo Borges
2013-05-16 17:16 ` [RFC 09/22] main: Call emulator " Paulo Borges
2013-05-16 17:16 ` [RFC 10/22] emulator: Add HFP 1.6 AG card driver Paulo Borges
2013-05-16 17:16 ` [RFC 11/22] emulator: Set " Paulo Borges
2013-05-16 17:16 ` [RFC 12/22] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
2013-05-16 17:16 ` [RFC 13/22] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
2013-05-16 17:16 ` [RFC 14/22] emulator: Add AT+BAC support Paulo Borges
2013-05-16 17:16 ` [RFC 15/22] emulator: Add AT+BCC support Paulo Borges
2013-05-16 17:16 ` [RFC 16/22] emulator: Setup codec connection Paulo Borges
2013-05-16 17:16 ` [RFC 17/22] emulator: Add AT+BCS support Paulo Borges
2013-05-16 17:16 ` [RFC 18/22] emulator: Resend +BCS after receive AT+BAC Paulo Borges
2013-05-16 17:16 ` [RFC 19/22] emulator: Setup synchronous connection Paulo Borges
2013-05-16 17:16 ` [RFC 20/22] emulator: Reuse last negotiated codec Paulo Borges
2013-05-16 17:16 ` [RFC 21/22] emulator: Copy callback mechanism from atutil.h Paulo Borges
2013-05-16 17:16 ` [RFC 22/22] emulator: Implement AG card .Connect() for HFP 1.6 Paulo Borges

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.