Open Source Telephony
 help / color / mirror / Atom feed
* Re: [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver
  2013-04-25 19:09 ` [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver Paulo Borges
@ 2013-04-25 17:58   ` Denis Kenzior
  0 siblings, 0 replies; 15+ messages in thread
From: Denis Kenzior @ 2013-04-25 17:58 UTC (permalink / raw)
  To: ofono

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

Hi Paulo,

On 04/25/2013 02:09 PM, Paulo Borges wrote:
> ---
>   src/emulator.c |   31 ++++++++++++++++++++++++++++++-
>   1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/src/emulator.c b/src/emulator.c
> index 8ac79d5..5027b02 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,32 @@ 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)
> +{
> +	DBG("HFP 1.6 AG card driver probe");
> +
> +	return 0;
> +}
> +
> +static void hfp16_card_remove(struct ofono_handsfree_card *card)
> +{
> +	DBG("HFP 1.6 AG card driver remove");
> +}
> +
> +static void hfp16_card_connect(struct ofono_handsfree_card *card,
> +			ofono_handsfree_card_connect_cb_t cb, void *data)
> +{
> +	DBG("HFP 1.6 AG card driver connect");
> +}
> +
> +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,
> +};
> +

So why do we need this exactly?  There is already a default 
implementation inside handsfree_audio_card if the driver is NULL.  How 
is this going to be different from the default implementation?

>   static int card_set_local_remote(struct ofono_handsfree_card *card, int fd)
>   {
>   	struct sockaddr_rc saddr;
> @@ -1338,9 +1366,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);
>   }

Regards,
-Denis

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

* [PATCH v2 00/12] Add HandsfreeAudioCard to emulator
@ 2013-04-25 19:09 Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 01/12] include: Add ofono_emulator_create_card() Paulo Borges
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

This patch series starts to implement HandsfreeAudioCard logic to Audio
Gateway role from HFP version 1.6 profile.

Changelog v2:

* Extract fd from emulator's GAtServer
* Add card driver for HFP 1.6 AG
* Send HFP version to card creation

Paulo Borges (12):
  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
  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

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

-- 
1.7.9.5


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

* [PATCH v2 01/12] include: Add ofono_emulator_create_card()
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 02/12] emulator: Implement ofono_emulator_create_card() Paulo Borges
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* [PATCH v2 02/12] emulator: Implement ofono_emulator_create_card()
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 01/12] include: Add ofono_emulator_create_card() Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 03/12] hfp_ag_bluez5: Create card when connect Paulo Borges
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

---
 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] 15+ messages in thread

* [PATCH v2 03/12] hfp_ag_bluez5: Create card when connect
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 01/12] include: Add ofono_emulator_create_card() Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 02/12] emulator: Implement ofono_emulator_create_card() Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 04/12] emulator: Register card when establish SLC Paulo Borges
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

---
 plugins/hfp_ag_bluez5.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 245de21..6451be4 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -123,6 +123,14 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	ofono_emulator_register(em, fd);
 
+	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);
 	g_io_add_watch_full(io, G_PRIORITY_DEFAULT, G_IO_HUP, io_hup_cb,
-- 
1.7.9.5


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

* [PATCH v2 04/12] emulator: Register card when establish SLC
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (2 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 03/12] hfp_ag_bluez5: Create card when connect Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 05/12] emulator: Set local and remote address of card Paulo Borges
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

---
 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] 15+ messages in thread

* [PATCH v2 05/12] emulator: Set local and remote address of card
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (3 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 04/12] emulator: Register card when establish SLC Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 06/12] include: Add emulator init and cleanup functions Paulo Borges
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

This commit extract local and remote address from the socket and
store them into the 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] 15+ messages in thread

* [PATCH v2 06/12] include: Add emulator init and cleanup functions
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (4 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 05/12] emulator: Set local and remote address of card Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 07/12] emulator: Implement " Paulo Borges
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* [PATCH v2 07/12] emulator: Implement init and cleanup functions
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (5 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 06/12] include: Add emulator init and cleanup functions Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 08/12] main: Call emulator " Paulo Borges
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* [PATCH v2 08/12] main: Call emulator init and cleanup functions
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (6 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 07/12] emulator: Implement " Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver Paulo Borges
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (7 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 08/12] main: Call emulator " Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 17:58   ` Denis Kenzior
  2013-04-25 19:09 ` [PATCH v2 10/12] emulator: Set " Paulo Borges
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 UTC (permalink / raw)
  To: ofono

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

---
 src/emulator.c |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/emulator.c b/src/emulator.c
index 8ac79d5..5027b02 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,32 @@ 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)
+{
+	DBG("HFP 1.6 AG card driver probe");
+
+	return 0;
+}
+
+static void hfp16_card_remove(struct ofono_handsfree_card *card)
+{
+	DBG("HFP 1.6 AG card driver remove");
+}
+
+static void hfp16_card_connect(struct ofono_handsfree_card *card,
+			ofono_handsfree_card_connect_cb_t cb, void *data)
+{
+	DBG("HFP 1.6 AG card driver connect");
+}
+
+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 +1366,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] 15+ messages in thread

* [PATCH v2 10/12] emulator: Set card driver
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (8 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 11/12] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 12/12] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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 5027b02..98235fa 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -1076,10 +1076,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] 15+ messages in thread

* [PATCH v2 11/12] hfp_ag_bluez5: Send HFP version to card creation
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (9 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 10/12] emulator: Set " Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  2013-04-25 19:09 ` [PATCH v2 12/12] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* [PATCH v2 12/12] hfp_ag_bluez5: Register HFP AG version 1.6
  2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
                   ` (10 preceding siblings ...)
  2013-04-25 19:09 ` [PATCH v2 11/12] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
@ 2013-04-25 19:09 ` Paulo Borges
  11 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-25 19:09 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] 15+ messages in thread

* Re: [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver
       [not found] <517A756D.2060305@gmail.com>
@ 2013-04-26 19:20 ` Paulo Borges
  0 siblings, 0 replies; 15+ messages in thread
From: Paulo Borges @ 2013-04-26 19:20 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

On Fri, Apr 26, 2013 at 9:39 AM, Denis Kenzior <denkenz@gmail.com> wrote:

> Hi Paulo,
>
>
> On 04/26/2013 12:53 PM, Paulo Borges wrote:
>
>> Hi Denis,
>>
>> On Thu, Apr 25, 2013 at 2:58 PM, Denis Kenzior <denkenz@gmail.com
>> <mailto:denkenz@gmail.com>> wrote:
>>
>>     Hi Paulo,
>>
>>
>>     On 04/25/2013 02:09 PM, Paulo Borges wrote:
>>
>>         ---
>>            src/emulator.c |   31 ++++++++++++++++++++++++++++++**__-
>>
>>            1 file changed, 30 insertions(+), 1 deletion(-)
>>
>>         diff --git a/src/emulator.c b/src/emulator.c
>>         index 8ac79d5..5027b02 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,32 @@ 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)
>>         +{
>>         +       DBG("HFP 1.6 AG card driver probe");
>>         +
>>         +       return 0;
>>         +}
>>         +
>>         +static void hfp16_card_remove(struct ofono_handsfree_card *card)
>>         +{
>>         +       DBG("HFP 1.6 AG card driver remove");
>>         +}
>>         +
>>         +static void hfp16_card_connect(struct ofono_handsfree_card *card,
>>         +                       ofono_handsfree_card_connect__**_cb_t cb,
>>
>>         void *data)
>>         +{
>>         +       DBG("HFP 1.6 AG card driver connect");
>>         +}
>>         +
>>         +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,
>>         +};
>>         +
>>
>>
>>     So why do we need this exactly?  There is already a default
>>     implementation inside handsfree_audio_card if the driver is NULL.
>>       How is this going to be different from the default implementation?
>>
>>
>>            static int card_set_local_remote(struct ofono_handsfree_card
>>         *card, int fd)
>>            {
>>                  struct sockaddr_rc saddr;
>>         @@ -1338,9 +1366,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);
>>
>>            }
>>
>>
>>     Regards,
>>     -Denis
>>
>>
>> When both roles support codec negotiation feature AG must first send an
>> unsolicited +BCS and only call the default implementation after HF
>> respond with AT+BCS [1].
>>
>> [1] HFP 1.6 spec page 31: 4.11.3 "Codec Connection Setup".
>>
>>
> This is where the spec is a bit fuzzy.  There is some room for
> interpretation on the timing of the codec negotiation exchange.
>
> Can we do the codec negotiation before hand, not as part of the .connect
> implementation?  e.g. can we negotiate the codec right after SLC
> establishment and from then on simply establish the SCO link, or must we
> always perform codec negotiation right before the SCO link establishment?
>
> Regards,
> -Denis
>

Yes, we can negotiate the codec after an incoming AT+BAC command from HF.
This way, we can ensure that the chosen codec is valid and we don't need to
use a card driver.

I'll change this and send a new version.

-- 
Cheers,
Paulo.

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 5463 bytes --]

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

end of thread, other threads:[~2013-04-26 19:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-25 19:09 [PATCH v2 00/12] Add HandsfreeAudioCard to emulator Paulo Borges
2013-04-25 19:09 ` [PATCH v2 01/12] include: Add ofono_emulator_create_card() Paulo Borges
2013-04-25 19:09 ` [PATCH v2 02/12] emulator: Implement ofono_emulator_create_card() Paulo Borges
2013-04-25 19:09 ` [PATCH v2 03/12] hfp_ag_bluez5: Create card when connect Paulo Borges
2013-04-25 19:09 ` [PATCH v2 04/12] emulator: Register card when establish SLC Paulo Borges
2013-04-25 19:09 ` [PATCH v2 05/12] emulator: Set local and remote address of card Paulo Borges
2013-04-25 19:09 ` [PATCH v2 06/12] include: Add emulator init and cleanup functions Paulo Borges
2013-04-25 19:09 ` [PATCH v2 07/12] emulator: Implement " Paulo Borges
2013-04-25 19:09 ` [PATCH v2 08/12] main: Call emulator " Paulo Borges
2013-04-25 19:09 ` [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver Paulo Borges
2013-04-25 17:58   ` Denis Kenzior
2013-04-25 19:09 ` [PATCH v2 10/12] emulator: Set " Paulo Borges
2013-04-25 19:09 ` [PATCH v2 11/12] hfp_ag_bluez5: Send HFP version to card creation Paulo Borges
2013-04-25 19:09 ` [PATCH v2 12/12] hfp_ag_bluez5: Register HFP AG version 1.6 Paulo Borges
     [not found] <517A756D.2060305@gmail.com>
2013-04-26 19:20 ` [PATCH v2 09/12] emulator: Add HFP 1.6 AG card driver Paulo Borges

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