summaryrefslogtreecommitdiffstats
path: root/gatchat/gatppp.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-06-29 11:53:11 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-06-29 11:53:11 -0500
commit820b1f55c8f9e615ef860327ef58a54006ec8822 (patch)
treef760579f42c3d87d9dc415848414cfa4b8a6e4a2 /gatchat/gatppp.c
parent969862337a77d10081cc72ca9ec0aaafaa3e977e (diff)
downloadofono-820b1f55c8f9e615ef860327ef58a54006ec8822.tar.bz2
ppp: Refactor server-side API
The biggest update here is that the server needs to be in dormant mode by default, so as not to send a Configure-Req to the peer until the peer is ready. This requires adding special constructor for LCP to initialize it to Stopped state instead of initial state. Along with this, we pass the server local IP directly to the ppp server constructor.
Diffstat (limited to 'gatchat/gatppp.c')
-rw-r--r--gatchat/gatppp.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index e7a9f19a..1d41ded6 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -479,7 +479,7 @@ void g_at_ppp_set_server_info(GAtPPP *ppp, const char *remote,
ipcp_set_server_info(ppp->ipcp, r, d1, d2);
}
-static GAtPPP *ppp_init_common(GAtHDLC *hdlc)
+static GAtPPP *ppp_init_common(GAtHDLC *hdlc, gboolean is_server, guint32 ip)
{
GAtPPP *ppp;
@@ -496,15 +496,18 @@ static GAtPPP *ppp_init_common(GAtHDLC *hdlc)
ppp->mtu = DEFAULT_MTU;
/* initialize the lcp state */
- ppp->lcp = lcp_new(ppp);
+ ppp->lcp = lcp_new(ppp, is_server);
/* initialize IPCP state */
- ppp->ipcp = ipcp_new(ppp);
+ ppp->ipcp = ipcp_new(ppp, is_server, ip);
g_at_hdlc_set_receive(ppp->hdlc, ppp_receive, ppp);
g_at_io_set_disconnect_function(g_at_hdlc_get_io(ppp->hdlc),
io_disconnect, ppp);
+ if (is_server)
+ ppp_enter_phase(ppp, PPP_PHASE_ESTABLISHMENT);
+
return ppp;
}
@@ -517,7 +520,7 @@ GAtPPP *g_at_ppp_new(GIOChannel *modem)
if (hdlc == NULL)
return NULL;
- ppp = ppp_init_common(hdlc);
+ ppp = ppp_init_common(hdlc, FALSE, 0);
g_at_hdlc_unref(hdlc);
return ppp;
@@ -532,7 +535,49 @@ GAtPPP *g_at_ppp_new_from_io(GAtIO *io)
if (hdlc == NULL)
return NULL;
- ppp = ppp_init_common(hdlc);
+ ppp = ppp_init_common(hdlc, FALSE, 0);
+ g_at_hdlc_unref(hdlc);
+
+ return ppp;
+}
+
+GAtPPP *g_at_ppp_server_new(GIOChannel *modem, const char *local)
+{
+ GAtHDLC *hdlc;
+ GAtPPP *ppp;
+ guint32 ip;
+
+ if (local == NULL)
+ ip = 0;
+ else if (inet_pton(AF_INET, local, &ip) != 1)
+ return NULL;
+
+ hdlc = g_at_hdlc_new(modem);
+ if (hdlc == NULL)
+ return NULL;
+
+ ppp = ppp_init_common(hdlc, TRUE, ip);
+ g_at_hdlc_unref(hdlc);
+
+ return ppp;
+}
+
+GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local)
+{
+ GAtHDLC *hdlc;
+ GAtPPP *ppp;
+ guint32 ip;
+
+ if (local == NULL)
+ ip = 0;
+ else if (inet_pton(AF_INET, local, &ip) != 1)
+ return NULL;
+
+ hdlc = g_at_hdlc_new_from_io(io);
+ if (hdlc == NULL)
+ return NULL;
+
+ ppp = ppp_init_common(hdlc, TRUE, ip);
g_at_hdlc_unref(hdlc);
return ppp;