summaryrefslogtreecommitdiffstats
path: root/gatchat/gatppp.c
diff options
context:
space:
mode:
authorGuillaume Zajac <guillaume.zajac@linux.intel.com>2011-05-19 11:58:28 +0200
committerDenis Kenzior <denkenz@gmail.com>2011-05-24 12:10:22 -0500
commit7e5ccc18d77bb0919519747647f7f6559d313830 (patch)
tree74052085491308946692ebcb920edeab717c1267 /gatchat/gatppp.c
parentdb5e8287871633f40d88f20774d425d73a886773 (diff)
downloadofono-7e5ccc18d77bb0919519747647f7f6559d313830.tar.bz2
gatppp: Add new contructor to use external fd
Diffstat (limited to 'gatchat/gatppp.c')
-rw-r--r--gatchat/gatppp.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index f2f2484d..6d27dd6f 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -78,6 +78,7 @@ struct _GAtPPP {
guint ppp_dead_source;
GAtSuspendFunc suspend_func;
gpointer suspend_data;
+ int fd;
};
void ppp_debug(GAtPPP *ppp, const char *str)
@@ -290,7 +291,7 @@ void ppp_auth_notify(GAtPPP *ppp, gboolean success)
void ppp_ipcp_up_notify(GAtPPP *ppp, const char *local, const char *peer,
const char *dns1, const char *dns2)
{
- ppp->net = ppp_net_new(ppp);
+ ppp->net = ppp_net_new(ppp, ppp->fd);
if (ppp->net == NULL) {
ppp->disconnect_reason = G_AT_PPP_REASON_NET_FAIL;
@@ -316,6 +317,7 @@ void ppp_ipcp_down_notify(GAtPPP *ppp)
return;
ppp_net_free(ppp->net);
+ ppp->fd = -1;
ppp->net = NULL;
}
@@ -522,6 +524,8 @@ void g_at_ppp_unref(GAtPPP *ppp)
if (ppp->net)
ppp_net_free(ppp->net);
+ else if (ppp->fd >= 0)
+ close(ppp->fd);
if (ppp->chap)
ppp_chap_free(ppp->chap);
@@ -565,6 +569,8 @@ static GAtPPP *ppp_init_common(GAtHDLC *hdlc, gboolean is_server, guint32 ip)
ppp->ref_count = 1;
+ ppp->fd = -1;
+
/* set options to defaults */
ppp->mru = DEFAULT_MRU;
ppp->mtu = DEFAULT_MTU;
@@ -657,3 +663,28 @@ GAtPPP *g_at_ppp_server_new_from_io(GAtIO *io, const char *local)
return ppp;
}
+
+GAtPPP *g_at_ppp_server_new_full(GAtIO *io, const char *local, int fd)
+{
+ 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);
+
+ /* Set the fd value returned by ConnMan */
+ ppp->fd = fd;
+
+ g_at_hdlc_unref(hdlc);
+
+ return ppp;
+}