From: "Gustavo F. Padovan" <[email protected]>

Only put modem powered when Remote SAP Server is enabled
---
 plugins/bluetooth.h |    2 +-
 plugins/sap.c       |    4 +---
 plugins/telit.c     |   18 +++++++++++++++---
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 96e3215..e66e179 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -45,7 +45,7 @@ struct bluetooth_profile {
 
 struct bluetooth_sap_driver {
        const char *name;
-       int (*enable) (struct ofono_modem *modem);
+       int (*enable) (struct ofono_modem *modem, struct ofono_modem 
*sap_modem);
        int (*disable) (struct ofono_modem *modem);
 };
 
diff --git a/plugins/sap.c b/plugins/sap.c
index abff14c..31b5f06 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -235,7 +235,7 @@ static void sap_connect_reply(DBusPendingCall *call, 
gpointer user_data)
        data->hw_modem = sap_hw_modem;
        data->sap_driver = sap_hw_driver;
 
-       fd = data->sap_driver->enable(data->hw_modem);
+       fd = data->sap_driver->enable(data->hw_modem, modem);
        if (fd < 0)
                return;
 
@@ -254,8 +254,6 @@ static void sap_connect_reply(DBusPendingCall *call, 
gpointer user_data)
                                G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
                                hw_event_cb, modem, hw_watch_remove);
 
-       ofono_modem_set_powered(modem, TRUE);
-
 done:
        dbus_message_unref(reply);
 }
diff --git a/plugins/telit.c b/plugins/telit.c
index d5db39f..c2a5650 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -68,6 +68,7 @@ struct telit_data {
        GAtChat *aux;
        struct ofono_sim *sim;
        guint sim_inserted_source;
+       struct ofono_modem *sap_modem;
 };
 
 static void telit_debug(const char *str, void *user_data)
@@ -112,6 +113,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
 static void telit_rsen_notify(GAtResult *result, gpointer user_data)
 {
        struct ofono_modem *modem = user_data;
+       struct telit_data *data = ofono_modem_get_data(modem);
        int status;
        GAtResultIter iter;
 
@@ -123,6 +125,13 @@ static void telit_rsen_notify(GAtResult *result, gpointer 
user_data)
                return;
 
        g_at_result_iter_next_number(&iter, &status);
+
+       if (status == 0) {
+               ofono_modem_set_powered(data->sap_modem, FALSE);
+               return;
+       }
+
+       ofono_modem_set_powered(data->sap_modem, TRUE);
 }
 
 static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -135,7 +144,7 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
        if (!ok) {
                g_at_chat_unref(data->aux);
                data->aux = NULL;
-               ofono_modem_set_powered(modem, FALSE);
+               ofono_modem_set_powered(data->sap_modem, FALSE);
                return;
        }
 }
@@ -151,7 +160,7 @@ static void rsen_disable_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
        data->aux = NULL;
 
        if (ok)
-               ofono_modem_set_powered(modem, FALSE);
+               ofono_modem_set_powered(data->sap_modem, FALSE);
 }
 
 static int telit_sap_open()
@@ -179,7 +188,8 @@ static int telit_sap_open()
        return fd;
 }
 
-static int telit_sap_enable(struct ofono_modem *modem)
+static int telit_sap_enable(struct ofono_modem *modem,
+                                       struct ofono_modem *sap_modem)
 {
        struct telit_data *data = ofono_modem_get_data(modem);
        int fd;
@@ -194,6 +204,8 @@ static int telit_sap_enable(struct ofono_modem *modem)
        if (fd < 0)
                return fd;
 
+       data->sap_modem = sap_modem;
+
        g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify,
                                FALSE, modem, NULL);
 
-- 
1.7.6.2

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to