Re: [PATCH 2/3] handsfree-audio: Add support for initiating SCO connections

2013-03-19 Thread Denis Kenzior

Hi Vinicius,

On 03/19/2013 07:10 PM, Vinicius Costa Gomes wrote:

When calling the card's .Connect() method, we should be able to
establish a SCO connection.

Right now, we only have support for establishing the SCO connection
directly, this is what is expected from HFP 1.5 HF/AG devices.
---
  src/handsfree-audio.c | 94 ++-
  1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c7fa2fb..9eecb8e 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -53,6 +53,8 @@ struct ofono_handsfree_card {
char *remote;
char *local;
char *path;
+   DBusMessage *msg;
+   guint sco_watch;
const struct ofono_handsfree_card_driver *driver;
void *driver_data;
  };
@@ -235,10 +237,100 @@ static DBusMessage *card_get_properties(DBusConnection 
*conn,
return reply;
  }

+static int card_connect_sco(struct ofono_handsfree_card *card)
+{
+   struct sockaddr_sco addr;
+   int sk, ret;
+
+   sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
+   BTPROTO_SCO);
+   if (sk<  0)
+   return -1;
+
+   /* Bind to local address */
+   memset(&addr, 0, sizeof(addr));
+   addr.sco_family = AF_BLUETOOTH;
+   bt_str2ba(card->local,&addr.sco_bdaddr);
+
+   if (bind(sk, (struct sockaddr *)&addr, sizeof(addr))<  0) {
+   close(sk);
+   return -1;
+   }
+
+   /* Connect to remote device */
+   memset(&addr, 0, sizeof(addr));
+   addr.sco_family = AF_BLUETOOTH;
+   bt_str2ba(card->remote,&addr.sco_bdaddr);
+
+   ret = connect(sk, (struct sockaddr *)&addr, sizeof(addr));
+   if (ret<  0&&  !(errno == EAGAIN || errno == EINPROGRESS)) {


Why do we use EAGAIN here?  I thought only EINPROGRESS can be returned 
from a non-blocking connect.  Or are Bluetooth semantics different?



+   close(sk);
+   return -1;
+   }
+
+   return sk;
+}
+
+static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
+   gpointer user_data)
+
+{
+   struct ofono_handsfree_card *card = user_data;
+   DBusMessage *reply;
+   int sk;
+
+   if (cond&  (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+   reply = __ofono_error_failed(card->msg);
+   goto done;
+   }
+
+   sk = g_io_channel_unix_get_fd(io);
+
+   close(sk);
+
+   reply = dbus_message_new_method_return(card->msg);
+


We probably should be paranoid and check whether we still have the agent.


+done:
+   g_dbus_send_message(ofono_dbus_get_connection(), reply);
+
+   return FALSE;
+}
+
+static void sco_watch_destroy(gpointer user_data)
+{
+   struct ofono_handsfree_card *card = user_data;
+
+   card->sco_watch = 0;
+   dbus_message_unref(card->msg);
+}
+
  static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
  {
-   return __ofono_error_not_implemented(msg);
+   struct ofono_handsfree_card *card = data;
+   GIOChannel *io;
+   int sk;
+
+   if (agent == NULL)
+   return __ofono_error_not_available(msg);
+
+   if (card->msg)
+   return __ofono_error_busy(msg);
+
+   sk = card_connect_sco(card);


I presume this fails if we already have a SCO link?


+   if (sk<  0)
+   return __ofono_error_failed(msg);
+
+   io = g_io_channel_unix_new(sk);
+   card->sco_watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
+   G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+   sco_connect_cb, card, sco_watch_destroy);
+
+   g_io_channel_unref(io);
+
+   card->msg = dbus_message_ref(msg);
+
+   return NULL;
  }

  static const GDBusMethodTable card_methods[] = {


Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 1/3] ofono.conf: Punch hole for HandsfreeAudioAgent

2013-03-19 Thread Denis Kenzior

Hi Vinicius,

On 03/19/2013 07:10 PM, Vinicius Costa Gomes wrote:

---
  src/ofono.conf | 1 +
  1 file changed, 1 insertion(+)



Patch has been applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 3/3] handsfree-audio: Add support for sending the SCO socket

2013-03-19 Thread Vinicius Costa Gomes
When there's an agent registered, send the SCO file descriptor to the
agent associated with the card after the connection is established.
---
 src/handsfree-audio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 9eecb8e..129f33f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -286,6 +286,9 @@ 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);
+
close(sk);
 
reply = dbus_message_new_method_return(card->msg);
-- 
1.8.1.5

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/3] handsfree-audio: Add support for initiating SCO connections

2013-03-19 Thread Vinicius Costa Gomes
When calling the card's .Connect() method, we should be able to
establish a SCO connection.

Right now, we only have support for establishing the SCO connection
directly, this is what is expected from HFP 1.5 HF/AG devices.
---
 src/handsfree-audio.c | 94 ++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c7fa2fb..9eecb8e 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -53,6 +53,8 @@ struct ofono_handsfree_card {
char *remote;
char *local;
char *path;
+   DBusMessage *msg;
+   guint sco_watch;
const struct ofono_handsfree_card_driver *driver;
void *driver_data;
 };
@@ -235,10 +237,100 @@ static DBusMessage *card_get_properties(DBusConnection 
*conn,
return reply;
 }
 
+static int card_connect_sco(struct ofono_handsfree_card *card)
+{
+   struct sockaddr_sco addr;
+   int sk, ret;
+
+   sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
+   BTPROTO_SCO);
+   if (sk < 0)
+   return -1;
+
+   /* Bind to local address */
+   memset(&addr, 0, sizeof(addr));
+   addr.sco_family = AF_BLUETOOTH;
+   bt_str2ba(card->local, &addr.sco_bdaddr);
+
+   if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+   close(sk);
+   return -1;
+   }
+
+   /* Connect to remote device */
+   memset(&addr, 0, sizeof(addr));
+   addr.sco_family = AF_BLUETOOTH;
+   bt_str2ba(card->remote, &addr.sco_bdaddr);
+
+   ret = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
+   if (ret < 0 && !(errno == EAGAIN || errno == EINPROGRESS)) {
+   close(sk);
+   return -1;
+   }
+
+   return sk;
+}
+
+static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
+   gpointer user_data)
+
+{
+   struct ofono_handsfree_card *card = user_data;
+   DBusMessage *reply;
+   int sk;
+
+   if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+   reply = __ofono_error_failed(card->msg);
+   goto done;
+   }
+
+   sk = g_io_channel_unix_get_fd(io);
+
+   close(sk);
+
+   reply = dbus_message_new_method_return(card->msg);
+
+done:
+   g_dbus_send_message(ofono_dbus_get_connection(), reply);
+
+   return FALSE;
+}
+
+static void sco_watch_destroy(gpointer user_data)
+{
+   struct ofono_handsfree_card *card = user_data;
+
+   card->sco_watch = 0;
+   dbus_message_unref(card->msg);
+}
+
 static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
 {
-   return __ofono_error_not_implemented(msg);
+   struct ofono_handsfree_card *card = data;
+   GIOChannel *io;
+   int sk;
+
+   if (agent == NULL)
+   return __ofono_error_not_available(msg);
+
+   if (card->msg)
+   return __ofono_error_busy(msg);
+
+   sk = card_connect_sco(card);
+   if (sk < 0)
+   return __ofono_error_failed(msg);
+
+   io = g_io_channel_unix_new(sk);
+   card->sco_watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
+   G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+   sco_connect_cb, card, sco_watch_destroy);
+
+   g_io_channel_unref(io);
+
+   card->msg = dbus_message_ref(msg);
+
+   return NULL;
 }
 
 static const GDBusMethodTable card_methods[] = {
-- 
1.8.1.5

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/3] ofono.conf: Punch hole for HandsfreeAudioAgent

2013-03-19 Thread Vinicius Costa Gomes
---
 src/ofono.conf | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/ofono.conf b/src/ofono.conf
index 8a83cd0..ed56d3b 100644
--- a/src/ofono.conf
+++ b/src/ofono.conf
@@ -14,6 +14,7 @@
 
 
 
+
   
 
   
-- 
1.8.1.5

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v2 07/13] dundee: Listen to devices property changes

2013-03-19 Thread Daniel Wagner

Hi Paulo,

I talked to Denis and he pointed out that this property_changed() 
function looks suspicious.


On 03/14/2013 02:32 PM, Paulo Borges wrote:

When a bluetooth device property change and this property is Alias
or UUIDs, we need to refresh our representation of this device.
---
  dundee/bluez5.c |   28 +++-
  1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index ca44656..d48aadf 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -169,11 +169,37 @@ static void property_changed(GDBusProxy *proxy, const 
char *name,
  {
const char *path = g_dbus_proxy_get_path(proxy);
const char *interface = g_dbus_proxy_get_interface(proxy);
+   const char *alias;
+   struct bluetooth_device *bt_device;
+   gboolean uuid;

if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
return;

-   DBG("%s %s.%s", path, interface, name);
+   bt_device = g_hash_table_lookup(registered_devices, path);
+
+   if (g_str_equal(name, "Alias")) {
+   if (bt_device == NULL)
+   return;
+
+   dbus_message_iter_get_basic(iter, &alias);
+
+   DBG("%s alias changed: %s", path, alias);
+
+   bt_device->name = g_strdup(alias);
+   } else if (g_str_equal(name, "UUIDs")) {
+   DBG("%s uuids changed", path);
+
+   uuid = has_dun_uuid(iter);
+
+   if (uuid) {
+   if (bt_device == NULL)
+   bluetooth_device_register(proxy);
+   } else {
+   if (bt_device != NULL)
+   bluetooth_device_unregister(path);
+   }
+   }


So first thing, the nesting is should be avoided. Sorry, that's my bad.

if (uuid && bt_device == NULL) register

if (!uuid && bt_device) unregister

is what is an the ofono style.


  }

  static void connect_handler(DBusConnection *conn, void *user_data)



The next thing is why don't you use g_dbus_proxy_set_property_watch() 
for the property change. Then it might also be worth to split out the

the property handling into individual function. So one for Alias change
and one for UUID change.

See how Alias is handled in plugins/hfp_hf_bluez5.c

And there is the question came up, why it is necessary to handle UUID 
changes. Is this because a phone can enable/disable tethering?


cheers,
daniel

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee

2013-03-19 Thread Vinicius Costa Gomes
Hi Daniel,

On 10:55 Mon 18 Mar, Daniel Wagner wrote:
> Hi Paulo,
> 
> I have tested this version and it seems to work. I say 'seems' because I was 
> not able
> keep open the connection. All phones I have tested open the connection and 
> close
> them right after. I am not sure if just my setup is broken. Testing against 
> bluez4
> gave the same behaviour. So I don't think your patches are causing this.

Just for information, I did some field testing this weekend and I got it to work
fine with my N9.


Cheers,
-- 
Vinicius
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono