diff options
author | Guillaume Zajac <guillaume.zajac@linux.intel.com> | 2011-05-20 11:38:14 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2011-05-24 12:25:07 -0500 |
commit | ab027e9e9c92c3830359a54b5b9ef02711dbc88e (patch) | |
tree | eb3c30c7b900390c51019dce83572adc6a499dca | |
parent | 7617c492b8d11031892df8c6ae0cdd368a03eca8 (diff) | |
download | ofono-ab027e9e9c92c3830359a54b5b9ef02711dbc88e.tar.bz2 |
gatppp: Add GAtPPP suspend API
-rw-r--r-- | gatchat/gatppp.c | 40 | ||||
-rw-r--r-- | gatchat/gatppp.h | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c index 2608d522..2f97d552 100644 --- a/gatchat/gatppp.c +++ b/gatchat/gatppp.c @@ -46,6 +46,8 @@ #define PPP_ADDR_FIELD 0xff #define PPP_CTRL 0x03 +#define GUARD_TIMEOUTS 1500 + enum ppp_phase { PPP_PHASE_DEAD = 0, /* Link dead */ PPP_PHASE_ESTABLISHMENT, /* LCP started */ @@ -79,6 +81,7 @@ struct _GAtPPP { GAtSuspendFunc suspend_func; gpointer suspend_data; int fd; + guint guard_timeout_src; gboolean suspended; }; @@ -509,6 +512,43 @@ void g_at_ppp_shutdown(GAtPPP *ppp) pppcp_signal_close(ppp->lcp); } +static gboolean call_suspend_cb(gpointer user_data) +{ + GAtPPP *ppp = user_data; + + ppp->guard_timeout_src = 0; + + if (ppp->suspend_func) + ppp->suspend_func(ppp->suspend_data); + + return FALSE; +} + +static gboolean send_escape_sequence(gpointer user_data) +{ + GAtPPP *ppp = user_data; + GAtIO *io = g_at_hdlc_get_io(ppp->hdlc); + + ppp->guard_timeout_src = 0; + g_at_io_write(io, "+++", 3); + ppp->guard_timeout_src = g_timeout_add(GUARD_TIMEOUTS, + call_suspend_cb, ppp); + + return FALSE; +} + +void g_at_ppp_suspend(GAtPPP *ppp) +{ + if (ppp == NULL) + return; + + ppp->suspended = TRUE; + ppp_net_suspend_interface(ppp->net); + g_at_hdlc_suspend(ppp->hdlc); + ppp->guard_timeout_src = g_timeout_add(GUARD_TIMEOUTS, + send_escape_sequence, ppp); +} + void g_at_ppp_resume(GAtPPP *ppp) { if (ppp == NULL) diff --git a/gatchat/gatppp.h b/gatchat/gatppp.h index b1b02341..4a27feae 100644 --- a/gatchat/gatppp.h +++ b/gatchat/gatppp.h @@ -65,6 +65,7 @@ void g_at_ppp_set_suspend_function(GAtPPP *ppp, GAtSuspendFunc func, gpointer user_data); void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data); void g_at_ppp_shutdown(GAtPPP *ppp); +void g_at_ppp_suspend(GAtPPP *ppp); void g_at_ppp_resume(GAtPPP *ppp); void g_at_ppp_ref(GAtPPP *ppp); void g_at_ppp_unref(GAtPPP *ppp); |