summaryrefslogtreecommitdiffstats
path: root/gatchat/gatppp.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-30 15:31:26 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-30 15:31:26 -0500
commit6d20194e7520a2190429b9f4582a7ee3b573d3c9 (patch)
tree982d847212b6658c7c1835c2cd6f55f6a6fbc430 /gatchat/gatppp.c
parent9ae0dcb47d71803681a205c4708be82d27111443 (diff)
downloadofono-6d20194e7520a2190429b9f4582a7ee3b573d3c9.tar.bz2
ppp: Refactor connect / disconnect callbacks
Right now it is very hard to figure out whether we should be calling the connect callback or the disconnect callback. So refactor as follows: - Connect callback is only called once the net is actually up - Disconnect callback is called once ppp is down, with a reason for why it is so.
Diffstat (limited to 'gatchat/gatppp.c')
-rw-r--r--gatchat/gatppp.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 253b33fe..70669b04 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -66,8 +66,9 @@ struct _GAtPPP {
char password[256];
GAtPPPConnectFunc connect_cb;
gpointer connect_data;
- GAtDisconnectFunc disconnect_cb;
+ GAtPPPDisconnectFunc disconnect_cb;
gpointer disconnect_data;
+ GAtPPPDisconnectReason disconnect_reason;
GAtDebugFunc debugf;
gpointer debug_data;
};
@@ -177,7 +178,8 @@ static void ppp_dead(GAtPPP *ppp)
{
/* notify interested parties */
if (ppp->disconnect_cb)
- ppp->disconnect_cb(ppp->disconnect_data);
+ ppp->disconnect_cb(ppp->disconnect_reason,
+ ppp->disconnect_data);
}
static inline void ppp_enter_phase(GAtPPP *ppp, enum ppp_phase phase)
@@ -209,6 +211,7 @@ void ppp_set_auth(GAtPPP *ppp, const guint8* auth_data)
void ppp_auth_notify(GAtPPP *ppp, gboolean success)
{
if (success == FALSE) {
+ ppp->disconnect_reason = G_AT_PPP_REASON_AUTH_FAIL;
pppcp_signal_close(ppp->lcp);
return;
}
@@ -225,20 +228,19 @@ void ppp_ipcp_up_notify(GAtPPP *ppp, const char *ip,
{
ppp->net = ppp_net_new(ppp);
+ if (ppp->net == NULL) {
+ ppp->disconnect_reason = G_AT_PPP_REASON_NET_FAIL;
+ pppcp_signal_close(ppp->lcp);
+ return;
+ }
+
if (ppp_net_set_mtu(ppp->net, ppp->mtu) == FALSE)
g_printerr("Unable to set MTU\n");
ppp_enter_phase(ppp, PPP_PHASE_LINK_UP);
- if (ppp->connect_cb == NULL)
- return;
-
- if (ppp->net == NULL)
- ppp->connect_cb(G_AT_PPP_CONNECT_FAIL, NULL,
- NULL, NULL, NULL, ppp->connect_data);
- else
- ppp->connect_cb(G_AT_PPP_CONNECT_SUCCESS,
- ppp_net_get_interface(ppp->net),
+ if (ppp->connect_cb)
+ ppp->connect_cb(ppp_net_get_interface(ppp->net),
ip, dns1, dns2, ppp->connect_data);
}
@@ -258,6 +260,7 @@ void ppp_ipcp_finished_notify(GAtPPP *ppp)
return;
/* Our IPCP parameter negotiation failed */
+ ppp->disconnect_reason = G_AT_PPP_REASON_IPCP_FAIL;
pppcp_signal_close(ppp->ipcp);
pppcp_signal_close(ppp->lcp);
}
@@ -279,6 +282,9 @@ void ppp_lcp_down_notify(GAtPPP *ppp)
if (ppp->phase == PPP_PHASE_NETWORK || ppp->phase == PPP_PHASE_LINK_UP)
pppcp_signal_down(ppp->ipcp);
+ if (ppp->disconnect_reason == G_AT_PPP_REASON_UNKNOWN)
+ ppp->disconnect_reason = G_AT_PPP_REASON_PEER_CLOSED;
+
ppp_enter_phase(ppp, PPP_PHASE_TERMINATION);
}
@@ -312,6 +318,7 @@ static void io_disconnect(gpointer user_data)
{
GAtPPP *ppp = user_data;
+ ppp->disconnect_reason = G_AT_PPP_REASON_LINK_DEAD;
pppcp_signal_down(ppp->lcp);
pppcp_signal_close(ppp->lcp);
}
@@ -375,7 +382,7 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func,
ppp->connect_data = user_data;
}
-void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func,
+void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtPPPDisconnectFunc func,
gpointer user_data)
{
if (func == NULL)
@@ -399,6 +406,7 @@ void g_at_ppp_shutdown(GAtPPP *ppp)
if (ppp->phase == PPP_PHASE_DEAD || ppp->phase == PPP_PHASE_TERMINATION)
return;
+ ppp->disconnect_reason = G_AT_PPP_REASON_LOCAL_CLOSE;
pppcp_signal_close(ppp->lcp);
}