From deca4a32d38885b5c3bb9832dea9db38e5d56e4d Mon Sep 17 00:00:00 2001 From: "Gustavo F. Padovan" Date: Wed, 28 Sep 2011 18:24:13 -0300 Subject: [PATCH] telit: add suport the disable SAP client --- plugins/bluetooth.h | 1 + plugins/telit.c | 100 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h index 7e94f96..d38e72e 100644 --- a/plugins/bluetooth.h +++ b/plugins/bluetooth.h @@ -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; diff --git a/plugins/telit.c b/plugins/telit.c index d2f6c5a..9a33840 100644 --- a/plugins/telit.c +++ b/plugins/telit.c @@ -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; -- 2.7.4