summaryrefslogtreecommitdiffstats
path: root/src/handsfree-audio.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2013-03-27 21:13:00 -0300
committerDenis Kenzior <denkenz@gmail.com>2013-03-28 09:34:03 -0500
commit4f02f03abb5a9fd2a1805f7aa60304e01a223ebc (patch)
tree999afdea296a626d4668736d5f9bcec904ec91c9 /src/handsfree-audio.c
parent405961a65744b3bf6a4af14168e040602cac5213 (diff)
downloadofono-4f02f03abb5a9fd2a1805f7aa60304e01a223ebc.tar.bz2
handsfree-audio: Add ofono_handsfree_card_connect_sco
Diffstat (limited to 'src/handsfree-audio.c')
-rw-r--r--src/handsfree-audio.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index f8df6d61..571ed54f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -236,40 +236,6 @@ 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 != EINPROGRESS) {
- close(sk);
- return -1;
- }
-
- return sk;
-}
-
static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
@@ -311,9 +277,8 @@ static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ofono_handsfree_card *card = data;
- GIOChannel *io;
const char *sender;
- int sk;
+ int err;
if (agent == NULL)
return __ofono_error_not_available(msg);
@@ -326,15 +291,10 @@ static DBusMessage *card_connect(DBusConnection *conn,
if (card->msg)
return __ofono_error_busy(msg);
- sk = card_connect_sco(card);
- if (sk < 0)
+ err = ofono_handsfree_card_connect_sco(card);
+ if (err < 0)
return __ofono_error_failed(msg);
- io = g_io_channel_unix_new(sk);
- g_io_add_watch(io, G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
- sco_connect_cb, card);
- g_io_channel_unref(io);
-
card->msg = dbus_message_ref(msg);
return NULL;
@@ -420,6 +380,47 @@ const char *ofono_handsfree_card_get_local(struct ofono_handsfree_card *card)
return card->local;
}
+int ofono_handsfree_card_connect_sco(struct ofono_handsfree_card *card)
+{
+ GIOChannel *io;
+ 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) {
+ ofono_error("Could not bind SCO socket");
+ 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 != EINPROGRESS) {
+ close(sk);
+ return -1;
+ }
+
+ io = g_io_channel_unix_new(sk);
+ g_io_add_watch(io, G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ sco_connect_cb, card);
+ g_io_channel_unref(io);
+
+ return 0;
+}
+
static void emit_card_added(struct ofono_handsfree_card *card)
{
DBusMessage *signal;