Skip to contentSkip to conversation

Add PPP protocol support with HDLC framing

PATCH In review Kristen Carlson Accardi 2 participants 8 messages Mar 19, 2010 – Mar 20, 2010 1 message not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/6 Add PPP protocol support with HDLC framing

This patch implements the basic PPP protocol. LCP, NCP etc. are handled in a different patch.

---
 Makefile.am      |    4 
 gatchat/gatppp.c |  133 ++++++++++++++++
 gatchat/gatppp.h |   59 +++++++
 gatchat/ppp.c    |  455 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gatchat/ppp.h    |  130 +++++++++++++++
 5 files changed, 780 insertions(+), 1 deletion(-)
Makefile.am +3 -1
Index: ofono/Makefile.am
===================================================================
@@ -55,7 +55,9 @@
 				gatchat/gattty.h gatchat/gattty.c \
 				gatchat/gatutil.h gatchat/gatutil.c \
 				gatchat/gat.h \
-				gatchat/gatserver.h gatchat/gatserver.c
+				gatchat/gatserver.h gatchat/gatserver.c \
+				gatchat/gatppp.c gatchat/gatppp.h \
+				gatchat/ppp.c gatchat/ppp.h
 
 udev_files = plugins/ofono.rules
 
gatchat/gatppp.c new file +133 -0

133 lines not on this page · raw message

gatchat/gatppp.h new file +59 -0

59 lines not on this page · raw message

gatchat/ppp.c new file +455 -0

455 lines not on this page · raw message

gatchat/ppp.h new file +130 -0

130 lines not on this page · raw message

#2 lore raw

Hi Kristen,

Quoted 10 lines

This patch implements the basic PPP protocol. LCP, NCP etc. are handled in a different patch.

---
 Makefile.am      |    4 
 gatchat/gatppp.c |  133 ++++++++++++++++
 gatchat/gatppp.h |   59 +++++++
 gatchat/ppp.c    |  455 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gatchat/ppp.h    |  130 +++++++++++++++
 5 files changed, 780 insertions(+), 1 deletion(-)

please keep the patches whitespace clean. Otherwise you will make it really hard and complicated for everybody if we have to do whitespace cleanup in between patches.

Applying: Add PPP protocol support with HDLC framing /data/devel/ofono/.git/rebase-apply/patch:572: space before tab in indent.

        	if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
/data/devel/ofono/.git/rebase-apply/patch:573: space before tab in indent.
                	return FALSE;

fatal: 2 lines add whitespace errors.

Using an editor that visualizes whitespaces and tabs might help here.

And empty lines at the end of a file. Please remove them and if your editor is too stupid, then please pick a different editor.

Applying: Add PPP protocol support with HDLC framing /data/devel/ofono/.git/rebase-apply/patch:166: new blank line at EOF. +
/data/devel/ofono/.git/rebase-apply/patch:230: new blank line at EOF. +
fatal: 2 lines add whitespace errors.

Before you submit any patches, you might wanna quickly check with git am that they still apply. My .gitconfig uses a strict apply policy:

[diff]
color = auto
check = true
[apply]
whitespace = error
[format-patch]
check = true

Having diff and format-patch color your whitespace damages is always a good idea. Then you see what is wrong.

Regards

Marcel

#3 lore raw

PATCH 2/6 Generic PPP control protocol

In reply to a message not in the archive

Implement a generic control protocol that can be shared by both LCP and NCP implementations.

---
 Makefile.am      |    3 
 gatchat/ppp.h    |    2 
 gatchat/ppp_cp.c | 1503 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gatchat/ppp_cp.h |  139 +++++
 4 files changed, 1646 insertions(+), 1 deletion(-)
Makefile.am +2 -1
Index: ofono/Makefile.am
===================================================================
@@ -57,7 +57,8 @@
 				gatchat/gat.h \
 				gatchat/gatserver.h gatchat/gatserver.c \
 				gatchat/gatppp.c gatchat/gatppp.h \
-				gatchat/ppp.c gatchat/ppp.h
+				gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \
+				gatchat/ppp_cp.c
 
 udev_files = plugins/ofono.rules
 
gatchat/ppp_cp.c new file +1503 -0

1,503 lines not on this page · raw message

gatchat/ppp_cp.h new file +139 -0

139 lines not on this page · raw message

gatchat/ppp.h +2 -0
Index: ofono/gatchat/ppp.h
===================================================================
@@ -18,6 +18,8 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+#include "ppp_cp.h"
+
 #define DEFAULT_MRU	1500
 #define BUFFERSZ	DEFAULT_MRU*2
 #define DEFAULT_ACCM	0x00000000
#4 lore raw

PATCH 3/6 LCP support

In reply to a message not in the archive

Implement LCP support for the PPP protocol

---
 Makefile.am       |    2 
 gatchat/gatppp.c  |    6 +
 gatchat/ppp.c     |   48 ++++++++++
 gatchat/ppp.h     |    8 +
 gatchat/ppp_lcp.c |  246 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 308 insertions(+), 2 deletions(-)
Makefile.am +1 -1
Index: ofono/Makefile.am
===================================================================
@@ -58,7 +58,7 @@
 				gatchat/gatserver.h gatchat/gatserver.c \
 				gatchat/gatppp.c gatchat/gatppp.h \
 				gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \
-				gatchat/ppp_cp.c
+				gatchat/ppp_cp.c gatchat/ppp_lcp.c
 
 udev_files = plugins/ofono.rules
 
gatchat/ppp.c +48 -0

67 lines not on this page · raw message

gatchat/ppp.h +8 -0
Index: ofono/gatchat/ppp.h
===================================================================
@@ -98,6 +98,7 @@
 struct _GAtPPP {
 	gint ref_count;
 	enum ppp_phase phase;
+	struct pppcp_data *lcp;
 	guint8 buffer[BUFFERSZ];
 	int index;
 	gint mru;
@@ -130,3 +131,10 @@
 gboolean ppp_get_pfc(GAtPPP *ppp);
 void ppp_set_acfc(GAtPPP *ppp, gboolean acfc);
 gboolean ppp_get_acfc(GAtPPP *ppp);
+struct pppcp_data * lcp_new(GAtPPP *ppp);
+void lcp_free(struct pppcp_data *lcp);
+void lcp_open(struct pppcp_data *data);
+void lcp_close(struct pppcp_data *data);
+void lcp_establish(struct pppcp_data *data);
+void lcp_terminate(struct pppcp_data *data);
+
gatchat/ppp_lcp.c new file +246 -0

246 lines not on this page · raw message

gatchat/gatppp.c +5 -1
Index: ofono/gatchat/gatppp.c
===================================================================
@@ -40,6 +40,7 @@
 void g_at_ppp_open(GAtPPP *ppp)
 {
 	/* send an OPEN event to the lcp layer */
+	lcp_open(ppp->lcp);
 }
 
 void g_at_ppp_set_connect_function(GAtPPP *ppp,
@@ -69,6 +70,9 @@
 	/* cleanup modem channel */
 	g_source_remove(ppp->modem_watch);
 	g_io_channel_unref(ppp->modem);
+
+	/* remove lcp */
+	lcp_free(ppp->lcp);
 }
 
 void g_at_ppp_ref(GAtPPP *ppp)
@@ -117,7 +121,7 @@
 	ppp->index = 0;
 
 	/* initialize the lcp state */
-
+	ppp->lcp = lcp_new(ppp);
 
 	/* initialize the autentication state */
 
#5 lore raw

PATCH 4/6 CHAP with MD5 authentication

In reply to a message not in the archive

Implement authentication support with CHAP and MD5 digest

---
 Makefile.am        |    3 
 gatchat/gatppp.c   |   11 ++
 gatchat/gatppp.h   |    2 
 gatchat/ppp.c      |    1 
 gatchat/ppp.h      |   15 +++
 gatchat/ppp_auth.c |  230 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 260 insertions(+), 2 deletions(-)
Makefile.am +2 -1
Index: ofono/Makefile.am
===================================================================
@@ -58,7 +58,8 @@
 				gatchat/gatserver.h gatchat/gatserver.c \
 				gatchat/gatppp.c gatchat/gatppp.h \
 				gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \
-				gatchat/ppp_cp.c gatchat/ppp_lcp.c
+				gatchat/ppp_cp.c gatchat/ppp_lcp.c \
+				gatchat/ppp_auth.c
 
 udev_files = plugins/ofono.rules
 
gatchat/gatppp.c +10 -1
Index: ofono/gatchat/gatppp.c
===================================================================
@@ -43,6 +43,12 @@
 	lcp_open(ppp->lcp);
 }
 
+void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username,
+				const char *passwd)
+{
+	auth_set_credentials(ppp->auth, username, passwd);
+}
+
 void g_at_ppp_set_connect_function(GAtPPP *ppp,
 			       GAtPPPConnectFunc callback, gpointer user_data)
 {
@@ -73,6 +79,9 @@
 
 	/* remove lcp */
 	lcp_free(ppp->lcp);
+
+	/* remove auth */
+	auth_free(ppp->auth);
 }
 
 void g_at_ppp_ref(GAtPPP *ppp)
@@ -124,7 +133,7 @@
 	ppp->lcp = lcp_new(ppp);
 
 	/* initialize the autentication state */
-
+	ppp->auth = auth_new(ppp);
 
 	/* intialize the network state */
 
gatchat/gatppp.h +2 -0
Index: ofono/gatchat/gatppp.h
===================================================================
@@ -51,6 +51,8 @@
 void g_at_ppp_shutdown(GAtPPP *ppp);
 void g_at_ppp_ref(GAtPPP *ppp);
 void g_at_ppp_unref(GAtPPP *ppp);
+void g_at_ppp_set_credentials(GAtPPP *ppp, const char *username,
+				const char *passwd);
 #ifdef __cplusplus
 }
 #endif
gatchat/ppp.h +15 -0
Index: ofono/gatchat/ppp.h
===================================================================
@@ -95,10 +95,20 @@
 #define ppp_proto(packet) \
 	(get_host_short(packet + 2))
 
+struct auth_data {
+	guint16 proto;
+	gpointer proto_data;
+	void (*process_packet)(struct auth_data *data, guint8 *packet);
+	char *username;
+	char *passwd;
+	GAtPPP *ppp;
+};
+
 struct _GAtPPP {
 	gint ref_count;
 	enum ppp_phase phase;
 	struct pppcp_data *lcp;
+	struct auth_data *auth;
 	guint8 buffer[BUFFERSZ];
 	int index;
 	gint mru;
@@ -137,4 +147,9 @@
 void lcp_close(struct pppcp_data *data);
 void lcp_establish(struct pppcp_data *data);
 void lcp_terminate(struct pppcp_data *data);
+void auth_set_credentials(struct auth_data *data, const char *username,
+				const char *passwd);
+void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method);
+struct auth_data *auth_new(GAtPPP *ppp);
+void auth_free(struct auth_data *auth);
 
gatchat/ppp_auth.c new file +230 -0

230 lines not on this page · raw message

gatchat/ppp.c +1 -0
Index: ofono/gatchat/ppp.c
===================================================================
@@ -463,6 +463,7 @@
 	switch (proto) {
 	case CHAP_PROTOCOL:
 		/* get the algorithm */
+		auth_set_proto(ppp->auth, proto, auth_data[2]);
 		break;
 	default:
 		g_printerr("unknown authentication proto\n");
#6 lore raw

PATCH 5/6 IP support for PPP

In reply to a message not in the archive

Implement IPCP support. Creates a tun interface to pass IP traffic.

---
 Makefile.am       |    2 
 gatchat/gatppp.c  |    1 
 gatchat/ppp.c     |    1 
 gatchat/ppp.h     |   12 +
 gatchat/ppp_net.c |  356 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 371 insertions(+), 1 deletion(-)
Makefile.am +1 -1
Index: ofono/Makefile.am
===================================================================
@@ -59,7 +59,7 @@
 				gatchat/gatppp.c gatchat/gatppp.h \
 				gatchat/ppp.c gatchat/ppp.h gatchat/ppp_cp.h \
 				gatchat/ppp_cp.c gatchat/ppp_lcp.c \
-				gatchat/ppp_auth.c
+				gatchat/ppp_auth.c gatchat/ppp_net.c
 
 udev_files = plugins/ofono.rules
 
gatchat/ppp.h +12 -0
Index: ofono/gatchat/ppp.h
===================================================================
@@ -104,11 +104,19 @@
 	GAtPPP *ppp;
 };
 
+struct ppp_net_data {
+	GAtPPP *ppp;
+	char *if_name;
+	GIOChannel *channel;
+	struct pppcp_data *ipcp;
+};
+
 struct _GAtPPP {
 	gint ref_count;
 	enum ppp_phase phase;
 	struct pppcp_data *lcp;
 	struct auth_data *auth;
+	struct ppp_net_data *net;
 	guint8 buffer[BUFFERSZ];
 	int index;
 	gint mru;
@@ -152,4 +160,8 @@
 void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method);
 struct auth_data *auth_new(GAtPPP *ppp);
 void auth_free(struct auth_data *auth);
+struct ppp_net_data *ppp_net_new(GAtPPP *ppp);
+void ppp_net_open(struct ppp_net_data *data);
+void ppp_net_free(struct ppp_net_data *data);
+void ppp_net_close(struct ppp_net_data *data);
 
gatchat/ppp_net.c new file +356 -0

356 lines not on this page · raw message

gatchat/gatppp.c +1 -0
Index: ofono/gatchat/gatppp.c
===================================================================
@@ -136,6 +136,7 @@
 	ppp->auth = auth_new(ppp);
 
 	/* intialize the network state */
+	ppp->net = ppp_net_new(ppp);
 
 	/* start listening for packets from the modem */
 	ppp->modem_watch = g_io_add_watch(modem,
gatchat/ppp.c +1 -0
Index: ofono/gatchat/ppp.c
===================================================================
@@ -381,6 +381,7 @@
 static void ppp_network(GAtPPP *ppp)
 {
 	/* bring network phase up */
+	ppp_net_open(ppp->net);
 }
 
 static void ppp_transition_phase(GAtPPP *ppp, enum ppp_phase phase)
#7 lore raw

PATCH 6/6 Allow gsmdial to use gatchat ppp support

In reply to a message not in the archive

Add option to use PPP to gsmdial.

---
 gatchat/gsmdial.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 87 insertions(+), 3 deletions(-)
gatchat/gsmdial.c +87 -3
Index: ofono/gatchat/gsmdial.c
===================================================================
@@ -29,10 +29,14 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/signalfd.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <net/if.h>
 
 #include <glib.h>
 #include <gatchat.h>
 #include <gattty.h>
+#include <gatppp.h>
 
 static const char *none_prefix[] = { NULL };
 static const char *cgreg_prefix[] = { "+CGREG:", NULL };
@@ -45,7 +49,11 @@
 static gchar *option_apn = NULL;
 static gint option_offmode = 0;
 static gboolean option_legacy = FALSE;
+static gboolean option_ppp = FALSE;
+static gchar *option_username = NULL;
+static gchar *option_password = NULL;
 
+static GAtPPP *ppp;
 static GAtChat *control;
 static GAtChat *modem;
 static GMainLoop *event_loop;
@@ -220,6 +228,76 @@
 	g_at_chat_send(modem, buf, none_prefix, NULL, NULL, NULL);
 }
 
+static void print_ip_address(const char *label, guint32 ip_addr)
+{
+	struct in_addr addr;
+	char buf[INET_ADDRSTRLEN];
+
+	addr.s_addr = ip_addr;
+
+	if (inet_ntop(AF_INET, &addr, buf, INET_ADDRSTRLEN))
+		g_print("%s: %s\n", label, buf);
+}
+
+static void ppp_connect(GAtPPP *ppp, GAtPPPConnectStatus success,
+			guint32 ip_addr, guint32 dns1, guint32 dns2,
+			gpointer user_data)
+{
+	if (success != G_AT_PPP_CONNECT_SUCCESS) {
+		g_print("Failed to create PPP interface!\n");
+		return;
+	}
+
+	/* print out the negotiated address and dns server */
+	print_ip_address("IP Address", ip_addr);
+	print_ip_address("Primary DNS Server", dns1);
+	print_ip_address("Secondary DNS Server", dns2);
+}
+
+static void ppp_disconnect(GAtPPP *ppp, gpointer user_data)
+{
+	g_print("PPP Link down\n");
+}
+
+static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	GIOChannel *channel;
+
+	if (!ok) {
+		g_print("Unable to define context\n");
+		exit(1);
+	}
+
+	if (option_ppp == FALSE)
+		return;
+
+	/* get the data IO channel */
+	channel = g_at_chat_get_channel(modem);
+
+	/*
+	 * shutdown gatchat or else it tries to take all the input
+	 * from the modem and does not let PPP get it.
+	 */
+	g_at_chat_shutdown(control);
+	g_at_chat_shutdown(modem);
+
+	/* open ppp */
+	ppp = g_at_ppp_new(channel);
+	if (!ppp) {
+		g_print("Unable to create PPP object\n");
+		return;
+	}
+	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);
+	g_at_ppp_set_disconnect_function(ppp, ppp_disconnect, NULL);
+
+	/* open the ppp connection */
+	g_at_ppp_open(ppp);
+}
+
 static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	char buf[64];
@@ -230,9 +308,9 @@
 	}
 
 	if (option_legacy == TRUE) {
-			sprintf(buf, "ATD*99***%u#", option_cid);
-			g_at_chat_send(modem, buf, none_prefix,
-					NULL, NULL, NULL);
+		sprintf(buf, "ATD*99***%u#", option_cid);
+		g_at_chat_send(modem, buf, none_prefix,
+				connect_cb, NULL, NULL);
 	} else {
 		sprintf(buf, "AT+CGACT=1,%u", option_cid);
 		g_at_chat_send(control, buf, none_prefix,
@@ -406,6 +484,12 @@
 				"Specify CFUN offmode" },
 	{ "legacy", 'l', 0, G_OPTION_ARG_NONE, &option_legacy,
 				"Use ATD*99***<cid>#" },
+	{ "ppp", 'P', 0, G_OPTION_ARG_NONE, &option_ppp,
+				"Connect using PPP" },
+	{ "username", 'u', 0, G_OPTION_ARG_STRING, &option_username,
+				"Specify PPP username" },
+	{ "password", 'w', 0, G_OPTION_ARG_STRING, &option_password,
+				"Specifiy PPP password" },
 	{ NULL },
 };
 
#8 lore raw

Re: [patch 6/6] Allow gsmdial to use gatchat ppp support

Hi Kristen,

Quoted 11 lines

Add option to use PPP to gsmdial.

---
 gatchat/gsmdial.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 87 insertions(+), 3 deletions(-)

Index: ofono/gatchat/gsmdial.c
===================================================================

gatchat/gsmdial.c line 34

Quoted 6 lines
gatchat/gsmdial.c +3 -0
@@ -29,10 +29,14 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/signalfd.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <net/if.h>

patches have to be always submitted against the latest tree.

Regards

Marcel