summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gatchat/gatppp.c50
-rw-r--r--gatchat/ppp.h34
-rw-r--r--gatchat/ppp_cp.c22
-rw-r--r--gatchat/ppp_ipcp.c14
4 files changed, 64 insertions, 56 deletions
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index b5e9d3e5..bf28aae6 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -38,6 +38,56 @@
#include "gatppp.h"
#include "ppp.h"
+#define BUFFERSZ DEFAULT_MRU*2
+
+struct _GAtPPP {
+ gint ref_count;
+ enum ppp_phase phase;
+ struct pppcp_data *lcp;
+ struct auth_data *auth;
+ struct pppcp_data *ipcp;
+ struct ppp_net_data *net;
+ guint8 buffer[BUFFERSZ];
+ int index;
+ gint mru;
+ guint16 auth_proto;
+ char user_name[256];
+ char passwd[256];
+ gboolean pfc;
+ gboolean acfc;
+ guint32 xmit_accm[8];
+ guint32 recv_accm;
+ GIOChannel *modem;
+ GAtPPPConnectFunc connect_cb;
+ gpointer connect_data;
+ GAtDisconnectFunc disconnect_cb;
+ gpointer disconnect_data;
+ gint read_watch;
+ gint write_watch;
+ GAtDebugFunc debugf;
+ gpointer debug_data;
+ int record_fd;
+ GQueue *xmit_queue;
+};
+
+void ppp_debug(GAtPPP *ppp, const char *str)
+{
+ if (!ppp || !ppp->debugf)
+ return;
+
+ ppp->debugf(str, ppp->debug_data);
+}
+
+void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success,
+ const char *ip, const char *dns1, const char *dns2)
+{
+ if (ppp->connect_cb == NULL)
+ return;
+
+ ppp->connect_cb(success, ppp->net->if_name,
+ ip, dns1, dns2, ppp->connect_data);
+}
+
#define PPPINITFCS16 0xffff /* Initial FCS value */
#define PPPGOODFCS16 0xf0b8 /* Good final FCS value */
diff --git a/gatchat/ppp.h b/gatchat/ppp.h
index 7b09fa90..90e22ce2 100644
--- a/gatchat/ppp.h
+++ b/gatchat/ppp.h
@@ -22,7 +22,6 @@
#include "ppp_cp.h"
#define DEFAULT_MRU 1500
-#define BUFFERSZ DEFAULT_MRU*2
#define DEFAULT_ACCM 0x00000000
#define PPP_ESC 0x7d
#define PPP_FLAG_SEQ 0x7e
@@ -108,36 +107,7 @@ struct ppp_net_data {
gint watch;
};
-struct _GAtPPP {
- gint ref_count;
- enum ppp_phase phase;
- struct pppcp_data *lcp;
- struct auth_data *auth;
- struct pppcp_data *ipcp;
- struct ppp_net_data *net;
- guint8 buffer[BUFFERSZ];
- int index;
- gint mru;
- guint16 auth_proto;
- char user_name[256];
- char passwd[256];
- gboolean pfc;
- gboolean acfc;
- guint32 xmit_accm[8];
- guint32 recv_accm;
- GIOChannel *modem;
- GAtPPPConnectFunc connect_cb;
- gpointer connect_data;
- GAtDisconnectFunc disconnect_cb;
- gpointer disconnect_data;
- gint read_watch;
- gint write_watch;
- GAtDebugFunc debugf;
- gpointer debug_data;
- int record_fd;
- GQueue *xmit_queue;
-};
-
+void ppp_debug(GAtPPP *ppp, const char *str);
void ppp_generate_event(GAtPPP *ppp, enum ppp_event event);
void ppp_transmit(GAtPPP *ppp, guint8 *packet, guint infolen);
void ppp_set_auth(GAtPPP *ppp, guint8 *auth_data);
@@ -166,3 +136,5 @@ void ppp_net_close(struct ppp_net_data *data);
void ppp_net_free(struct ppp_net_data *data);
struct pppcp_data *ipcp_new(GAtPPP *ppp);
void ipcp_free(struct pppcp_data *data);
+void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success,
+ const char *ip, const char *dns1, const char *dns2);
diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c
index cf2f5fa5..46c62c17 100644
--- a/gatchat/ppp_cp.c
+++ b/gatchat/ppp_cp.c
@@ -38,21 +38,13 @@ static const char *pppcp_state_strings[] =
{"INITIAL", "STARTING", "CLOSED", "STOPPED", "CLOSING", "STOPPING",
"REQSENT", "ACKRCVD", "ACKSENT", "OPENED" };
-static void pppcp_debug(struct pppcp_data *p, const char *func)
-{
- GAtPPP *ppp = p->ppp;
- char *str;
-
- if (!ppp || !ppp->debugf)
- return;
-
- str = g_strdup_printf("%s: %s: current state %d:%s",
- p->prefix, func, p->state, pppcp_state_strings[p->state]);
- ppp->debugf(str, ppp->debug_data);
- g_free(str);
-}
-
-#define pppcp_trace(p) pppcp_debug(p, __FUNCTION__)
+#define pppcp_trace(p) do { \
+ char *str = g_strdup_printf("%s: %s: current state %d:%s", \
+ p->prefix, __FUNCTION__, \
+ p->state, pppcp_state_strings[p->state]); \
+ ppp_debug(p->ppp, str); \
+ g_free(str); \
+} while (0);
#define pppcp_to_ppp_packet(p) \
(((guint8 *) p) - PPP_HEADROOM)
diff --git a/gatchat/ppp_ipcp.c b/gatchat/ppp_ipcp.c
index a7ce2a5a..6b1566fe 100644
--- a/gatchat/ppp_ipcp.c
+++ b/gatchat/ppp_ipcp.c
@@ -66,15 +66,11 @@ enum ipcp_option_types {
static void ipcp_up(struct pppcp_data *pppcp)
{
struct ipcp_data *data = pppcp->priv;
- GAtPPP *ppp = pppcp->ppp;
char ip[INET_ADDRSTRLEN];
char dns1[INET_ADDRSTRLEN];
char dns2[INET_ADDRSTRLEN];
struct in_addr addr;
- if (ppp->connect_cb == NULL)
- return;
-
memset(ip, 0, sizeof(ip));
addr.s_addr = __get_unaligned_long(data->ip_address);
inet_ntop(AF_INET, &addr, ip, INET_ADDRSTRLEN);
@@ -87,12 +83,10 @@ static void ipcp_up(struct pppcp_data *pppcp)
addr.s_addr = __get_unaligned_long(data->secondary_dns);
inet_ntop(AF_INET, &addr, dns2, INET_ADDRSTRLEN);
- ppp->connect_cb(G_AT_PPP_CONNECT_SUCCESS,
- pppcp->ppp->net->if_name,
- ip[0] ? ip : NULL,
- dns1[0] ? dns1 : NULL,
- dns2[0] ? dns2 : NULL,
- ppp->connect_data);
+ ppp_connect_cb(pppcp->ppp, G_AT_PPP_CONNECT_SUCCESS,
+ ip[0] ? ip : NULL,
+ dns1[0] ? dns1 : NULL,
+ dns2[0] ? dns2 : NULL);
}
static void ipcp_down(struct pppcp_data *data)