diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c index 556387ae..fc845492 100644 --- a/gatchat/gatppp.c +++ b/gatchat/gatppp.c @@ -44,13 +44,13 @@ void g_at_ppp_open(GAtPPP *ppp) } void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username, - const char *passwd) + const char *passwd) { auth_set_credentials(ppp->auth, username, passwd); } void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func, - gpointer user_data) + gpointer user_data) { if (func == NULL) return; @@ -60,7 +60,7 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc func, } void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func, - gpointer user_data) + gpointer user_data) { if (func == NULL) return; @@ -69,6 +69,15 @@ void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc func, ppp->disconnect_data = user_data; } +void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data) +{ + if (ppp == NULL) + return; + + ppp->debugf = func; + ppp->debug_data = user_data; +} + void g_at_ppp_shutdown(GAtPPP *ppp) { /* close the ppp link */ diff --git a/gatchat/gatppp.h b/gatchat/gatppp.h index b37f74d5..3d1f74e7 100644 --- a/gatchat/gatppp.h +++ b/gatchat/gatppp.h @@ -47,6 +47,7 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc callback, gpointer user_data); void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtDisconnectFunc 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_ref(GAtPPP *ppp); void g_at_ppp_unref(GAtPPP *ppp); diff --git a/gatchat/gsmdial.c b/gatchat/gsmdial.c index 1050bd6c..d15aaa91 100644 --- a/gatchat/gsmdial.c +++ b/gatchat/gsmdial.c @@ -71,7 +71,7 @@ static int oldmode = 0; static void gsmdial_debug(const char *str, void *data) { - g_print("%s: %s\n", (const char *)data, str); + g_print("%s: %s\n", (const char *) data, str); } static gboolean quit_eventloop(gpointer user_data) @@ -269,8 +269,9 @@ static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data) g_print("Unable to create PPP object\n"); exit(1); } - g_at_ppp_set_credentials(ppp, option_username, - option_password); + g_at_ppp_set_debug(ppp, gsmdial_debug, "PPP"); + + g_at_ppp_set_credentials(ppp, option_username, option_password); /* set connect and disconnect callbacks */ g_at_ppp_set_connect_function(ppp, ppp_connect, NULL); diff --git a/gatchat/ppp.h b/gatchat/ppp.h index b8d51ece..bf1f5508 100644 --- a/gatchat/ppp.h +++ b/gatchat/ppp.h @@ -137,6 +137,8 @@ struct _GAtPPP { GAtDisconnectFunc disconnect_cb; gpointer disconnect_data; gint modem_watch; + GAtDebugFunc debugf; + gpointer debug_data; }; gboolean ppp_cb(GIOChannel *channel, GIOCondition cond, gpointer data); diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c index 82e5b10b..a0461e33 100644 --- a/gatchat/ppp_cp.c +++ b/gatchat/ppp_cp.c @@ -34,19 +34,25 @@ #include "gatppp.h" #include "ppp.h" -#define DEBUG -#ifdef DEBUG static const char *pppcp_state_strings[] = {"INITIAL", "STARTING", "CLOSED", "STOPPED", "CLOSING", "STOPPING", "REQSENT", "ACKRCVD", "ACKSENT", "OPENED" }; -#define pppcp_trace(p) do { \ - g_print("%s: %s: current state %d:%s\n", p->prefix, __FUNCTION__, \ - p->state, pppcp_state_strings[p->state]); \ -} while (0) -#else -#define pppcp_trace(p) do { } while (0) -#endif +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_to_ppp_packet(p) \ (((guint8 *) p) - PPP_HEADROOM)