telit: add suport the disable SAP client
authorGustavo F. Padovan <padovan@profusion.mobi>
Wed, 28 Sep 2011 21:24:13 +0000 (18:24 -0300)
committerDenis Kenzior <denkenz@gmail.com>
Thu, 29 Sep 2011 16:13:05 +0000 (11:13 -0500)
plugins/bluetooth.h
plugins/telit.c

index 7e94f96..d38e72e 100644 (file)
@@ -47,6 +47,7 @@ struct bluetooth_sap_driver {
        const char *name;
        int (*enable) (struct ofono_modem *modem, struct ofono_modem *sap_modem,
                                                                int bt_fd);
+       int (*disable) (struct ofono_modem *modem);
 };
 
 struct server;
index d2f6c5a..9a33840 100644 (file)
@@ -243,6 +243,58 @@ static void rsen_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
        }
 }
 
+static void cfun_disable_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+       struct ofono_modem *modem = user_data;
+       struct telit_data *data = ofono_modem_get_data(modem);
+
+       if(data->sap_modem)
+               modem = data->sap_modem;
+
+       DBG("%p", modem);
+
+       g_at_chat_unref(data->chat);
+       data->chat = NULL;
+
+       if (data->sim_inserted_source > 0)
+               g_source_remove(data->sim_inserted_source);
+
+       if (ok)
+               ofono_modem_set_powered(modem, FALSE);
+
+       data->sap_modem = NULL;
+}
+
+static int telit_disable(struct ofono_modem *modem)
+{
+       struct telit_data *data = ofono_modem_get_data(modem);
+       DBG("%p", modem);
+
+       g_at_chat_cancel_all(data->chat);
+       g_at_chat_unregister_all(data->chat);
+
+       /* Power down modem */
+       g_at_chat_send(data->chat, "AT+CFUN=0", none_prefix,
+                               cfun_disable_cb, modem, NULL);
+
+       return -EINPROGRESS;
+}
+
+static void rsen_disable_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);
+
+       g_at_chat_unref(data->aux);
+       data->aux = NULL;
+
+       sap_close_io(modem);
+
+       telit_disable(modem);
+}
+
 static int telit_sap_open()
 {
        const char *device = "/dev/ttyUSB4";
@@ -331,9 +383,25 @@ error:
        return -EINVAL;
 }
 
+static int telit_sap_disable(struct ofono_modem *modem)
+{
+       struct telit_data *data = ofono_modem_get_data(modem);
+
+       DBG("%p", modem);
+
+       g_at_chat_cancel_all(data->aux);
+       g_at_chat_unregister_all(data->aux);
+
+       g_at_chat_send(data->aux, "AT#RSEN=0", rsen_prefix,
+                               rsen_disable_cb, modem, NULL);
+
+       return -EINPROGRESS;
+}
+
 static struct bluetooth_sap_driver sap_driver = {
        .name = "telit",
        .enable = telit_sap_enable,
+       .disable = telit_sap_disable,
 };
 
 static int telit_probe(struct ofono_modem *modem)
@@ -475,23 +543,6 @@ static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
                                telit_qss_cb, modem, NULL);
 }
 
-static void cfun_disable_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);
-
-       g_at_chat_unref(data->chat);
-       data->chat = NULL;
-
-       if (data->sim_inserted_source > 0)
-               g_source_remove(data->sim_inserted_source);
-
-       if (ok)
-               ofono_modem_set_powered(modem, FALSE);
-}
-
 static int telit_enable(struct ofono_modem *modem)
 {
        struct telit_data *data = ofono_modem_get_data(modem);
@@ -516,21 +567,6 @@ static int telit_enable(struct ofono_modem *modem)
        return -EINPROGRESS;
 }
 
-static int telit_disable(struct ofono_modem *modem)
-{
-       struct telit_data *data = ofono_modem_get_data(modem);
-       DBG("%p", modem);
-
-       g_at_chat_cancel_all(data->chat);
-       g_at_chat_unregister_all(data->chat);
-
-       /* Power down modem */
-       g_at_chat_send(data->chat, "AT+CFUN=0", none_prefix,
-                               cfun_disable_cb, modem, NULL);
-
-       return -EINPROGRESS;
-}
-
 static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
        struct cb_data *cbd = user_data;