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

---
 plugins/bluetooth.h |    1 +
 plugins/sap.c       |    4 +-
 plugins/telit.c     |  109 ++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 76 insertions(+), 38 deletions(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index f980ebe..1658b75 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -45,6 +45,7 @@ struct bluetooth_profile {
 
 struct bluetooth_sap_driver {
        const char *name;
+       int (*enable) (struct ofono_modem *modem);
 };
 
 struct server;
diff --git a/plugins/sap.c b/plugins/sap.c
index 88663c2..2a5db74 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -117,9 +117,9 @@ static void sap_remove(struct ofono_modem *modem)
 /* power up hardware */
 static int sap_enable(struct ofono_modem *modem)
 {
-       DBG("%p", modem);
+       struct sap_data *data = ofono_modem_get_data(modem);
 
-       return 0;
+       return data->sap_driver->enable(data->hw_modem);
 }
 
 static int sap_disable(struct ofono_modem *modem)
diff --git a/plugins/telit.c b/plugins/telit.c
index 18cf0c4..cc10668 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -58,6 +58,7 @@
 
 static const char *none_prefix[] = { NULL };
 static const char *qss_prefix[] = { "#QSS:", NULL };
+static const char *rsen_prefix[]= { "#RSEN:", NULL };
 
 struct telit_data {
        GAtChat *chat;
@@ -65,10 +66,6 @@ struct telit_data {
        guint sim_inserted_source;
 };
 
-static struct bluetooth_sap_driver sap_driver = {
-       .name = "telit",
-};
-
 static void telit_debug(const char *str, void *user_data)
 {
        const char *prefix = user_data;
@@ -76,6 +73,78 @@ static void telit_debug(const char *str, void *user_data)
        ofono_info("%s%s", prefix, str);
 }
 
+static GAtChat *open_device(struct ofono_modem *modem,
+                               const char *key, char *debug)
+{
+       const char *device;
+       GAtSyntax *syntax;
+       GIOChannel *channel;
+       GAtChat *chat;
+
+       device = ofono_modem_get_string(modem, key);
+       if (device == NULL)
+               return NULL;
+
+       DBG("%s %s", key, device);
+
+       channel = g_at_tty_open(device, NULL);
+       if (channel == NULL)
+               return NULL;
+
+       syntax = g_at_syntax_new_gsmv1();
+       chat = g_at_chat_new(channel, syntax);
+       g_at_syntax_unref(syntax);
+       g_io_channel_unref(channel);
+
+       if (chat == NULL)
+               return NULL;
+
+       if (getenv("OFONO_AT_DEBUG"))
+               g_at_chat_set_debug(chat, telit_debug, debug);
+
+       return chat;
+}
+
+static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+       struct ofono_modem *modem = user_data;
+       struct telit_data *data = ofono_modem_get_data(modem);
+
+       DBG("%p", modem);
+
+       if (!ok) {
+               g_at_chat_unref(data->chat);
+               data->chat = NULL;
+               ofono_modem_set_powered(modem, FALSE);
+               return;
+       }
+
+}
+
+static int telit_sap_enable(struct ofono_modem *modem)
+{
+       struct telit_data *data = ofono_modem_get_data(modem);
+
+       DBG("%p", modem);
+
+       data->chat = open_device(modem, "Data", "Aux: ");
+       if (data->chat == NULL)
+               return -EINVAL;
+
+       g_at_chat_send(data->chat, "AT#NOPT=3", NULL, NULL, NULL, NULL);
+
+       /* Set SAP functionality */
+       g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
+                               rsen_enable_cb, modem, NULL);
+
+       return -EINPROGRESS;
+}
+
+static struct bluetooth_sap_driver sap_driver = {
+       .name = "telit",
+       .enable = telit_sap_enable,
+};
+
 static int telit_probe(struct ofono_modem *modem)
 {
        struct telit_data *data;
@@ -232,38 +301,6 @@ static void cfun_disable_cb(gboolean ok, GAtResult 
*result, gpointer user_data)
                ofono_modem_set_powered(modem, FALSE);
 }
 
-static GAtChat *open_device(struct ofono_modem *modem,
-                               const char *key, char *debug)
-{
-       const char *device;
-       GAtSyntax *syntax;
-       GIOChannel *channel;
-       GAtChat *chat;
-
-       device = ofono_modem_get_string(modem, key);
-       if (device == NULL)
-               return NULL;
-
-       DBG("%s %s", key, device);
-
-       channel = g_at_tty_open(device, NULL);
-       if (channel == NULL)
-               return NULL;
-
-       syntax = g_at_syntax_new_gsmv1();
-       chat = g_at_chat_new(channel, syntax);
-       g_at_syntax_unref(syntax);
-       g_io_channel_unref(channel);
-
-       if (chat == NULL)
-               return NULL;
-
-       if (getenv("OFONO_AT_DEBUG"))
-               g_at_chat_set_debug(chat, telit_debug, debug);
-
-       return chat;
-}
-
 static int telit_enable(struct ofono_modem *modem)
 {
        struct telit_data *data = ofono_modem_get_data(modem);
-- 
1.7.6.2

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

Reply via email to