From: "Gustavo F. Padovan" <[email protected]>
data is now passed from one side to another
---
plugins/sap.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/plugins/sap.c b/plugins/sap.c
index 6ff52d2..043fb6c 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -55,7 +55,9 @@ struct sap_data {
struct ofono_modem *hw_modem;
struct bluetooth_sap_driver *sap_driver;
GIOChannel *bt_io;
+ GIOChannel *hw_io;
guint bt_watch;
+ guint hw_watch;
};
int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
@@ -107,12 +109,16 @@ static gboolean bt_event_cb(GIOChannel *bt_io,
GIOCondition condition,
if (condition & G_IO_IN) {
GIOStatus status;
- gsize bytes_read;
+ gsize bytes_read, bytes_written;
gchar buf[300];
status = g_io_channel_read_chars(bt_io, buf, 300,
&bytes_read, NULL);
+ if (bytes_read > 0)
+ g_io_channel_write_chars(sap_data->bt_io, buf,
+ bytes_read, &bytes_written, NULL);
+
if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
return FALSE;
@@ -126,6 +132,37 @@ static gboolean bt_event_cb(GIOChannel *bt_io,
GIOCondition condition,
return FALSE;
}
+static gboolean hw_event_cb(GIOChannel *hw_io, GIOCondition condition,
+ gpointer data)
+{
+ struct ofono_modem *modem = data;
+ struct sap_data *sap_data = ofono_modem_get_data(modem);
+
+ if (condition & G_IO_IN) {
+ GIOStatus status;
+ gsize bytes_read, bytes_written;
+ gchar buf[300];
+
+ status = g_io_channel_read_chars(hw_io, buf, 300,
+ &bytes_read, NULL);
+
+ if (bytes_read > 0)
+ g_io_channel_write_chars(sap_data->bt_io, buf,
+ bytes_read, &bytes_written, NULL);
+
+ if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
+ return FALSE;
+
+ return TRUE;
+ }
+
+ ofono_modem_set_powered(modem, FALSE);
+
+ sap_data->hw_watch = 0;
+
+ return FALSE;
+}
+
static int sap_probe(struct ofono_modem *modem)
{
DBG("%p", modem);
@@ -200,6 +237,30 @@ static void sap_connect_reply(DBusPendingCall *call,
gpointer user_data)
data->bt_watch = g_io_add_watch(data->bt_io, G_IO_HUP | G_IO_ERR
| G_IO_NVAL | G_IO_IN, bt_event_cb, modem);
+ fd = data->sap_driver->open(data->hw_modem);
+ if (!fd) {
+ g_io_channel_unref(data->bt_io);
+ return;
+ }
+
+ data->hw_io = g_io_channel_unix_new(fd);
+ if (data->hw_io == NULL) {
+ g_io_channel_unref(data->bt_io);
+ close(fd);
+ return;
+ }
+
+ g_io_channel_set_encoding(data->hw_io, NULL, NULL);
+ g_io_channel_set_buffered(data->hw_io, FALSE);
+ g_io_channel_set_close_on_unref(data->hw_io, TRUE);
+
+ data->hw_watch = g_io_add_watch(data->hw_io, G_IO_HUP | G_IO_ERR
+ | G_IO_NVAL | G_IO_IN, hw_event_cb, modem);
+
+ data->sap_driver->enable(data->hw_modem);
+
+ ofono_modem_set_powered(modem, TRUE);
+
done:
dbus_message_unref(reply);
}
--
1.7.6.2
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono