[patch 1/6] Add PPP protocol support with HDLC framing

2010-03-11 Thread kristen
This patch implements the basic PPP protocol.  LCP, NCP etc. are handled in a
different patch.

Index: ofono/Makefile.am
===
--- ofono.orig/Makefile.am  2010-03-10 16:58:09.915955860 -0800
+++ ofono/Makefile.am   2010-03-10 16:58:12.039961039 -0800
@@ -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/gatppp_internal.h
 
 udev_files = plugins/ofono.rules
 
Index: ofono/gatchat/gatppp_internal.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ ofono/gatchat/gatppp_internal.h 2010-03-10 16:58:12.039961039 -0800
@@ -0,0 +1,97 @@
+/*
+ *
+ *  PPP library with GLib integration
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __G_AT_PPP_INTERNAL_H
+#define __G_AT_PPP_INTERNAL_H
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+#define DEFAULT_MRU1500
+#define BUFFERSZ   DEFAULT_MRU*2
+#define DEFAULT_ACCM   0x
+#define PPP_ESC0x7d
+#define PPP_FLAG_SEQ   0x7e
+#define PPP_ADDR_FIELD 0xff
+#define PPP_CTRL   0x03
+#define LCP_PROTOCOL   0xc021
+#define CHAP_PROTOCOL  0xc223
+#define PPP_HEADROOM   2
+#define HDLC_HEADROOM  3
+#define HDLC_TAIL  3
+#define MD55
+
+enum PPP_PHASE {
+   DEAD = 0,
+   ESTABLISHMENT,
+   AUTHENTICATION,
+   NETWORK,
+   TERMINATION,
+};
+
+enum PPP_EVENTS {
+   PPP_UP = 1,
+   PPP_OPENED,
+   PPP_SUCCESS,
+   PPP_NONE,
+   PPP_CLOSING,
+   PPP_FAIL,
+   PPP_DOWN
+};
+
+struct ppp_packet_handler {
+   guint16 proto;
+   void (*handler)(gpointer priv, guint8 *packet);
+   gpointer priv;
+};
+
+#define ppp_generate_event(l, e) \
+   __ppp_generate_event(l, e)
+
+#define ppp_transmit(l, p, i) \
+   __ppp_transmit(l, p, i)
+
+#define ppp_register_packet_handler(h) \
+   __ppp_register_packet_handler(h)
+
+#define ppp_info(packet) \
+   (packet+4)
+
+#define ppp_proto(packet) \
+   (ntohs(*((guint16*)(packet+2
+
+void __ppp_generate_event(struct ppp_link *link, guint event);
+void __ppp_register_packet_handler(struct ppp_packet_handler *handler);
+void __ppp_transmit(struct ppp_link *link, guint8 *packet, guint infolen);
+void __ppp_set_auth(struct ppp_link *link, guint8 *auth_data);
+void __ppp_set_recv_accm(struct ppp_link *link, guint32 accm);
+guint32 __ppp_get_xmit_accm(struct ppp_link *link);
+void __ppp_set_pfc(struct ppp_link *link, gboolean pfc);
+gboolean __ppp_get_pfc(struct ppp_link *link);
+void __ppp_set_acfc(struct ppp_link *link, gboolean acfc);
+gboolean __ppp_get_acfc(struct ppp_link *link);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_AT_PPP_INTERNAL_H */
+
Index: ofono/gatchat/gatppp.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ ofono/gatchat/gatppp.c  2010-03-10 16:58:12.039961039 -0800
@@ -0,0 +1,557 @@
+/*
+ *
+ *  PPP library with GLib integration
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include stdio.h
+#include fcntl.h
+#include unistd.h
+#include string.h

[patch 4/6] CHAP with MD5 authentication

2010-03-11 Thread kristen
Implement authentication support with CHAP and MD5 digest
Index: ofono/Makefile.am
===
--- ofono.orig/Makefile.am  2010-03-10 17:01:56.687955124 -0800
+++ ofono/Makefile.am   2010-03-10 17:03:01.695955140 -0800
@@ -58,7 +58,8 @@
gatchat/gatserver.h gatchat/gatserver.c \
gatchat/gatppp_internal.h gatchat/gatpppcp.c \
gatchat/gatpppcp.h gatchat/gatppp.c \
-   gatchat/gatppplcp.c gatchat/gatppp.h
+   gatchat/gatppplcp.c gatchat/gatpppauth.c \
+   gatchat/gatppp.h
 
 udev_files = plugins/ofono.rules
 
Index: ofono/gatchat/gatppp.c
===
--- ofono.orig/gatchat/gatppp.c 2010-03-10 17:01:56.687955124 -0800
+++ ofono/gatchat/gatppp.c  2010-03-10 17:03:01.696955547 -0800
@@ -390,6 +390,7 @@
 static void ppp_network(struct ppp_link *link)
 {
/* bring network phase up */
+   net_open(link-net);
 }
 
 static void ppp_transition_phase(struct ppp_link *link, guint phase)
@@ -492,6 +493,9 @@
 
/* remove lcp */
lcp_free(link-lcp);
+
+   /* remove auth */
+   auth_free(link-auth);
 }
 
 void g_at_ppp_ref(struct ppp_link *link)
@@ -510,6 +514,12 @@
}
 }
 
+void g_at_ppp_set_credentials(struct ppp_link *link, gchar *username,
+   gchar *passwd)
+{
+   auth_set_credentials(link-auth, username, passwd);
+}
+
 void __ppp_set_auth(struct ppp_link *link, guint8* auth_data)
 {
guint16 proto = ntohs(*(guint16 *)auth_data);
@@ -517,6 +527,7 @@
switch(proto) {
case CHAP_PROTOCOL:
/* get the algorithm */
+   auth_set_proto(link-auth, proto, auth_data[2]);
break;
default:
g_printerr(unknown authentication proto\n);
@@ -594,9 +605,10 @@
link-lcp = lcp_new(link);
 
/* initialize the autentication state */
-
+   link-auth = auth_new(link);
 
/* intialize the network state */
+   link-net = net_new(link);
 
/* start listening for packets from the modem */
signal_source = g_io_add_watch(modem,
Index: ofono/gatchat/gatppp.h
===
--- ofono.orig/gatchat/gatppp.h 2010-03-10 17:01:56.688955112 -0800
+++ ofono/gatchat/gatppp.h  2010-03-10 17:03:01.696955547 -0800
@@ -27,6 +27,7 @@
 #endif
 
 struct ppp_link;
+struct auth_data;
 
 enum PPP_CONNECT_STATUS {
PPP_CONNECT_SUCCESS,
@@ -44,6 +45,7 @@
gint ref_count;
guint phase;
struct pppcp_data *lcp;
+   struct auth_data *auth;
guint8 *buffer;
int index;
gint mru;
@@ -74,6 +76,8 @@
 void g_at_ppp_shutdown(struct ppp_link *link);
 void g_at_ppp_ref(struct ppp_link *link);
 void g_at_ppp_unref(struct ppp_link *link);
+void g_at_ppp_set_credentials(struct ppp_link *link, gchar *username,
+   gchar *passwd);
 #ifdef __cplusplus
 }
 #endif
Index: ofono/gatchat/gatppp_internal.h
===
--- ofono.orig/gatchat/gatppp_internal.h2010-03-10 17:01:56.688955112 
-0800
+++ ofono/gatchat/gatppp_internal.h 2010-03-10 17:03:01.697955395 -0800
@@ -66,6 +66,15 @@
gpointer priv;
 };
 
+struct auth_data {
+   guint16 proto;
+   gpointer proto_data;
+   void (*process_packet)(struct auth_data *data, guint8 *packet);
+   struct ppp_link *link;
+   gchar *username;
+   gchar *passwd;
+};
+
 #define ppp_generate_event(l, e) \
__ppp_generate_event(l, e)
 
@@ -97,6 +106,11 @@
 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, gchar *username,
+   gchar *passwd);
+void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method);
+struct auth_data *auth_new(struct ppp_link *link);
+void auth_free(struct auth_data *auth);
 #ifdef __cplusplus
 }
 #endif
Index: ofono/gatchat/gatpppauth.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ ofono/gatchat/gatpppauth.c  2010-03-10 17:03:01.697955395 -0800
@@ -0,0 +1,219 @@
+/*
+ *
+ *  PPP library with GLib integration
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A 

[patch 3/6] LCP support

2010-03-11 Thread kristen
Implement LCP support for the PPP protocol

Index: ofono/Makefile.am
===
--- ofono.orig/Makefile.am  2010-03-10 17:00:34.037087986 -0800
+++ ofono/Makefile.am   2010-03-10 17:01:56.687955124 -0800
@@ -56,9 +56,9 @@
gatchat/gatutil.h gatchat/gatutil.c \
gatchat/gat.h \
gatchat/gatserver.h gatchat/gatserver.c \
-   gatchat/gatppp.c gatchat/gatppp.h \
-   gatchat/gatppp_internal.h gatchat/gatpppcp.c
-   gatchat/gatpppcp.h
+   gatchat/gatppp_internal.h gatchat/gatpppcp.c \
+   gatchat/gatpppcp.h gatchat/gatppp.c \
+   gatchat/gatppplcp.c gatchat/gatppp.h
 
 udev_files = plugins/ofono.rules
 
Index: ofono/gatchat/gatppp.c
===
--- ofono.orig/gatchat/gatppp.c 2010-03-10 16:58:12.039961039 -0800
+++ ofono/gatchat/gatppp.c  2010-03-10 17:01:56.687955124 -0800
@@ -352,22 +352,26 @@
 static void ppp_close(struct ppp_link *link)
 {
/* send a CLOSE event to the lcp layer */
+   lcp_close(link-lcp);
 }
 
 /* Administrative Open */
 void g_at_ppp_open(struct ppp_link *link)
 {
/* send an OPEN event to the lcp layer */
+   lcp_open(link-lcp);
 }
 
 static void ppp_link_establishment(struct ppp_link *link)
 {
/* signal UP event to LCP */
+   lcp_establish(link-lcp);
 }
 
 static void ppp_terminate(struct ppp_link *link)
 {
/* signal DOWN event to LCP */
+   lcp_terminate(link-lcp);
 }
 
 static void ppp_authenticate(struct ppp_link *link)
@@ -485,6 +489,9 @@
/* cleanup modem channel */
g_source_remove(link-modem_watch);
g_io_channel_unref(link-modem);
+
+   /* remove lcp */
+   lcp_free(link-lcp);
 }
 
 void g_at_ppp_ref(struct ppp_link *link)
@@ -503,6 +510,50 @@
}
 }
 
+void __ppp_set_auth(struct ppp_link *link, guint8* auth_data)
+{
+   guint16 proto = ntohs(*(guint16 *)auth_data);
+
+   switch(proto) {
+   case CHAP_PROTOCOL:
+   /* get the algorithm */
+   break;
+   default:
+   g_printerr(unknown authentication proto\n);
+   break;
+   }
+}
+
+void __ppp_set_recv_accm(struct ppp_link *link, guint32 accm)
+{
+   link-recv_accm = accm;
+}
+
+guint32 __ppp_get_xmit_accm(struct ppp_link *link)
+{
+   return link-xmit_accm[0];
+}
+
+void __ppp_set_pfc(struct ppp_link *link, gboolean pfc)
+{
+   link-pfc = pfc;
+}
+
+gboolean __ppp_get_pfc(struct ppp_link *link)
+{
+   return link-pfc;
+}
+
+void __ppp_set_acfc(struct ppp_link *link, gboolean acfc)
+{
+   link-acfc = acfc;
+}
+
+gboolean __ppp_get_acfc(struct ppp_link *link)
+{
+   return link-acfc;
+}
+
 struct ppp_link * g_at_ppp_new(GIOChannel *modem)
 {
struct ppp_link *link;
@@ -540,7 +591,7 @@
g_io_channel_set_buffered(modem, FALSE);
 
/* initialize the lcp state */
-
+   link-lcp = lcp_new(link);
 
/* initialize the autentication state */
 
Index: ofono/gatchat/gatppp.h
===
--- ofono.orig/gatchat/gatppp.h 2010-03-10 16:58:12.040979395 -0800
+++ ofono/gatchat/gatppp.h  2010-03-10 17:01:56.688955112 -0800
@@ -43,6 +43,7 @@
 struct ppp_link {
gint ref_count;
guint phase;
+   struct pppcp_data *lcp;
guint8 *buffer;
int index;
gint mru;
Index: ofono/gatchat/gatppp_internal.h
===
--- ofono.orig/gatchat/gatppp_internal.h2010-03-10 17:00:34.040101010 
-0800
+++ ofono/gatchat/gatppp_internal.h 2010-03-10 17:01:56.688955112 -0800
@@ -91,6 +91,12 @@
 gboolean __ppp_get_pfc(struct ppp_link *link);
 void __ppp_set_acfc(struct ppp_link *link, gboolean acfc);
 gboolean __ppp_get_acfc(struct ppp_link *link);
+struct pppcp_data * lcp_new(struct ppp_link *link);
+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);
 #ifdef __cplusplus
 }
 #endif
Index: ofono/gatchat/gatppplcp.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ ofono/gatchat/gatppplcp.c   2010-03-10 17:01:56.688955112 -0800
@@ -0,0 +1,225 @@
+/*
+ *
+ *  AT chat library with GLib integration
+ *
+ *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in 

[patch 5/6] IP support for PPP

2010-03-11 Thread kristen
Implement IPCP support.  Creates a tun interface to pass IP traffic.

Index: ofono/Makefile.am
===
--- ofono.orig/Makefile.am  2010-03-10 17:03:01.695955140 -0800
+++ ofono/Makefile.am   2010-03-10 17:04:30.034088637 -0800
@@ -59,7 +59,7 @@
gatchat/gatppp_internal.h gatchat/gatpppcp.c \
gatchat/gatpppcp.h gatchat/gatppp.c \
gatchat/gatppplcp.c gatchat/gatpppauth.c \
-   gatchat/gatppp.h
+   gatchat/gatpppnet.c gatchat/gatppp.h
 
 udev_files = plugins/ofono.rules
 
Index: ofono/gatchat/gatppp_internal.h
===
--- ofono.orig/gatchat/gatppp_internal.h2010-03-10 17:03:01.697955395 
-0800
+++ ofono/gatchat/gatppp_internal.h 2010-03-10 17:04:30.034088637 -0800
@@ -66,6 +66,13 @@
gpointer priv;
 };
 
+struct net_data {
+   struct ppp_link *link;
+   char *if_name;
+   GIOChannel *channel;
+   struct pppcp_data *ipcp;
+};
+
 struct auth_data {
guint16 proto;
gpointer proto_data;
@@ -111,6 +118,10 @@
 void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method);
 struct auth_data *auth_new(struct ppp_link *link);
 void auth_free(struct auth_data *auth);
+struct net_data *net_new(struct ppp_link *link);
+void net_open(struct net_data *data);
+void net_free(struct net_data *data);
+void net_close(struct net_data *data);
 #ifdef __cplusplus
 }
 #endif
Index: ofono/gatchat/gatpppnet.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ ofono/gatchat/gatpppnet.c   2010-03-10 17:04:30.034088637 -0800
@@ -0,0 +1,355 @@
+/*
+ *
+ *  AT chat library with GLib integration
+ *
+ *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include stdio.h
+#include fcntl.h
+#include unistd.h
+#include string.h
+#include termios.h
+#include arpa/inet.h
+#include net/if.h
+#include linux/if_tun.h
+#include sys/ioctl.h
+#include glib.h
+
+#include gatppp.h
+#include gatppp_internal.h
+
+static void ipcp_free(struct pppcp_data *data);
+
+/* XXX should be maximum IP Packet size */
+#define MAX_PACKET 1500
+#define PPP_IP_PROTO   0x0021
+
+struct ipcp_data {
+   guint8 ip_address[4];
+   guint8 primary_dns[4];
+   guint8 secondary_dns[4];
+   struct pppcp_data *pppcp;
+};
+
+static struct pppcp_data * ipcp_new(struct ppp_link *link);
+static void ipcp_option_process(gpointer data, gpointer user);
+static guint ipcp_option_scan(struct ppp_option *option, gpointer user);
+
+static void ip_process_packet(gpointer priv, guint8 *packet)
+{
+   struct net_data *data = (struct net_data *)priv;
+   GError *error = NULL;
+GIOStatus status;
+gsize bytes_written;
+   guint16 len;
+
+   /*
+* since net_open can fail, we need to make sure
+* channel is valid
+*/
+   if (data-channel == NULL)
+   return;
+
+   /* find the length of the packet to transmit */
+   len = ntohs(*(guint16 *)packet[2]);
+   status = g_io_channel_write_chars(data-channel, (gchar *) packet,
+  len, bytes_written, error);
+}
+
+/*
+ * packets received by the tun interface need to be written to
+ * the modem.  So, just read a packet, write out to the modem
+ *
+ * TBD - how do we know we have a full packet?  Do we care?
+ */
+static gboolean net_callback(GIOChannel *channel, GIOCondition cond,
+   gpointer userdata)
+{
+   GIOStatus status;
+   gchar buf[MAX_PACKET+2];
+   gsize bytes_read;
+   GError *error = NULL;
+   guint16 *proto = (guint16 *)buf;
+   struct net_data *data = (struct net_data *) userdata;
+
+   if (cond  G_IO_IN) {
+   /* leave space to add PPP protocol field */
+   status = g_io_channel_read_chars(channel, buf+2, MAX_PACKET,
+   bytes_read, error);
+   if (bytes_read  0) {
+   /* I assume we are pointing to the protocol? */
+  

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

2010-03-11 Thread kristen
Add option to use PPP to gsmdial.

Index: ofono/gatchat/gsmdial.c
===
--- ofono.orig/gatchat/gsmdial.c2010-03-10 16:58:09.773080389 -0800
+++ ofono/gatchat/gsmdial.c 2010-03-10 17:06:45.071975512 -0800
@@ -33,6 +33,9 @@
 #include glib.h
 #include gatchat.h
 #include gattty.h
+#include arpa/inet.h
+#include net/if.h
+#include gatppp.h
 
 static const char *none_prefix[] = { NULL };
 static const char *cgreg_prefix[] = { +CGREG:, NULL };
@@ -45,10 +48,14 @@
 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_passwd = NULL;
 
 static GAtChat *control;
 static GAtChat *modem;
 static GMainLoop *event_loop;
+static struct ppp_link *ppp;
 
 enum state {
STATE_NONE = 0,
@@ -220,6 +227,70 @@
g_at_chat_send(modem, buf, none_prefix, NULL, NULL, NULL);
 }
 
+static void print_ip_address(guint32 ip_addr)
+{
+   struct in_addr addr;
+   addr.s_addr = ip_addr;
+   g_print(%s\n, inet_ntoa(addr));
+}
+
+static void ppp_connect(struct ppp_link *link, gint success, guint32 ip_addr,
+guint32 dns1, guint32 dns2, gpointer user_data)
+{
+   if (success == PPP_CONNECT_SUCCESS) {
+   /* print out the negotiated address and dns server */
+   g_print(Negotiated IP Address: );
+   print_ip_address(ip_addr);
+
+   g_print(Primary DNS Server: );
+   print_ip_address(dns1);
+
+   g_print(Secondary DNS Server: );
+   print_ip_address(dns2);
+   } else {
+   g_print(Failed to create PPP interface!\n);
+   }
+}
+
+static void ppp_disconnect(struct ppp_link *link, 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);
+   }
+
+   /* get the data IO channel */
+   channel = g_at_chat_get_channel(modem);
+   channel = g_io_channel_ref(channel);
+
+   /* shutdown gatchat */
+   g_at_chat_unref(control);
+   g_at_chat_unref(modem);
+
+   /* open ppp */
+   ppp = g_at_ppp_new(channel);
+   if (ppp) {
+   g_print(Setting PPP Credentials to %s, %s\n, option_username,
+   option_passwd);
+   g_at_ppp_set_credentials(ppp, option_username,
+   option_passwd);
+
+   /* 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];
@@ -231,8 +302,14 @@
 
if (option_legacy == TRUE) {
sprintf(buf, ATD*99***%u#, option_cid);
-   g_at_chat_send(modem, buf, none_prefix,
-   NULL, NULL, NULL);
+   if (option_ppp == TRUE) {
+   g_print(Option PPP enabled\n);
+   g_at_chat_send(modem, buf, none_prefix,
+   connect_cb, NULL, NULL);
+   }
+   else
+   g_at_chat_send(modem, buf, none_prefix,
+   NULL, NULL, NULL);
} else {
sprintf(buf, AT+CGACT=1,%u, option_cid);
g_at_chat_send(control, buf, none_prefix,
@@ -406,6 +483,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_passwd,
+   Specifiy PPP Password },
{ NULL },
 };
 

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[patch 0/6] Initial patches for gatchat PPP support

2010-03-11 Thread kristen
These patches implement PPP support for gatchat.  They're not complete, but 
are useful enough to play with if anyone wants to.  I included a patch to
gsmdial which allows you to invoke the PPP routines after the CONNECT
callback.  This patch will create a TUN interface, which you will then
have to manually configure using the IP Address and DNS information that
is output by gsmdial to stdout.  There are many items yet to be done, 
mostly they fall into these categories: 
* clean exit and Link Loss path
* Cleanup and deallocate memory properly
* Implement Error path (Configure-Reject etc).
 
I tested this on the ATT sierra modem, but not with any other modem.
I appreciate your feedback.
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [patch 1/6] Add PPP protocol support with HDLC framing

2010-03-11 Thread Denis Kenzior
Hi Kristen,

 This patch implements the basic PPP protocol.  LCP, NCP etc. are handled in
  a different patch.
 
 Index: ofono/Makefile.am
 
===
 --- ofono.orig/Makefile.am2010-03-10 16:58:09.915955860 -0800
 +++ ofono/Makefile.am 2010-03-10 16:58:12.039961039 -0800
 @@ -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/gatppp_internal.h
 
  udev_files = plugins/ofono.rules
 
 Index: ofono/gatchat/gatppp_internal.h
 
===
 --- /dev/null 1970-01-01 00:00:00.0 +
 +++ ofono/gatchat/gatppp_internal.h   2010-03-10 16:58:12.039961039 -0800
 @@ -0,0 +1,97 @@
 +/*
 + *
 + *  PPP library with GLib integration
 + *
 + *  Copyright (C) 2010  Intel Corporation. All rights reserved.
 + *
 + *  This program is free software; you can redistribute it and/or modify
 + *  it under the terms of the GNU General Public License version 2 as
 + *  published by the Free Software Foundation.
 + *
 + *  This program is distributed in the hope that it will be useful,
 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *  GNU General Public License for more details.
 + *
 + *  You should have received a copy of the GNU General Public License
 + *  along with this program; if not, write to the Free Software
 + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
  USA + *
 + */
 +
 +#ifndef __G_AT_PPP_INTERNAL_H
 +#define __G_AT_PPP_INTERNAL_H
 +
 +#ifdef __cplusplus
 +extern C {
 +#endif
 +
 +#define DEFAULT_MRU  1500
 +#define BUFFERSZ DEFAULT_MRU*2
 +#define DEFAULT_ACCM 0x
 +#define PPP_ESC  0x7d
 +#define PPP_FLAG_SEQ 0x7e
 +#define PPP_ADDR_FIELD   0xff
 +#define PPP_CTRL 0x03
 +#define LCP_PROTOCOL 0xc021
 +#define CHAP_PROTOCOL0xc223
 +#define PPP_HEADROOM 2
 +#define HDLC_HEADROOM3
 +#define HDLC_TAIL3
 +#define MD5  5
 +
 +enum PPP_PHASE {
 + DEAD = 0,
 + ESTABLISHMENT,
 + AUTHENTICATION,
 + NETWORK,
 + TERMINATION,
 +};
 +
 +enum PPP_EVENTS {
 + PPP_UP = 1,
 + PPP_OPENED,
 + PPP_SUCCESS,
 + PPP_NONE,
 + PPP_CLOSING,
 + PPP_FAIL,
 + PPP_DOWN
 +};
 +
 +struct ppp_packet_handler {
 + guint16 proto;
 + void (*handler)(gpointer priv, guint8 *packet);
 + gpointer priv;
 +};
 +
 +#define ppp_generate_event(l, e) \
 + __ppp_generate_event(l, e)

Why do we need this define?

 +
 +#define ppp_transmit(l, p, i) \
 + __ppp_transmit(l, p, i)
 +

and this?

 +#define ppp_register_packet_handler(h) \
 + __ppp_register_packet_handler(h)

or this?

 +
 +#define ppp_info(packet) \
 + (packet+4)
 +
 +#define ppp_proto(packet) \
 + (ntohs(*((guint16*)(packet+2
 +
 +void __ppp_generate_event(struct ppp_link *link, guint event);
 +void __ppp_register_packet_handler(struct ppp_packet_handler *handler);
 +void __ppp_transmit(struct ppp_link *link, guint8 *packet, guint infolen);
 +void __ppp_set_auth(struct ppp_link *link, guint8 *auth_data);
 +void __ppp_set_recv_accm(struct ppp_link *link, guint32 accm);
 +guint32 __ppp_get_xmit_accm(struct ppp_link *link);
 +void __ppp_set_pfc(struct ppp_link *link, gboolean pfc);
 +gboolean __ppp_get_pfc(struct ppp_link *link);
 +void __ppp_set_acfc(struct ppp_link *link, gboolean acfc);
 +gboolean __ppp_get_acfc(struct ppp_link *link);
 +#ifdef __cplusplus
 +}
 +#endif
 +
 +#endif /* __G_AT_PPP_INTERNAL_H */
 +
 Index: ofono/gatchat/gatppp.c
 
===
 --- /dev/null 1970-01-01 00:00:00.0 +
 +++ ofono/gatchat/gatppp.c2010-03-10 16:58:12.039961039 -0800
 @@ -0,0 +1,557 @@
 +/*
 + *
 + *  PPP library with GLib integration
 + *
 + *  Copyright (C) 2010  Intel Corporation. All rights reserved.
 + *
 + *  This program is free software; you can redistribute it and/or modify
 + *  it under the terms of the GNU General Public License version 2 as
 + *  published by the Free Software Foundation.
 + *
 + *  This program is distributed in the hope that it will be useful,
 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *  GNU General Public License for more details.
 + *
 + *  You should have received a copy of the GNU General Public License
 + *  along with this program; if not, write to the Free Software
 + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  

Re: [patch 1/6] Add PPP protocol support with HDLC framing

2010-03-11 Thread Denis Kenzior
Hi Kristen,

 +struct ppp_link * g_at_ppp_new(GIOChannel *modem);
 +void g_at_ppp_open(struct ppp_link *link);
 +void g_at_ppp_set_connect_function(struct ppp_link *link,
 +GAtPPPConnectFunc callback, gpointer user_data);
 +void g_at_ppp_set_disconnect_function(struct ppp_link *link,
 +   GAtPPPDisconnectFunc callback,
 +   gpointer user_data);
 +void g_at_ppp_shutdown(struct ppp_link *link);
 +void g_at_ppp_ref(struct ppp_link *link);
 +void g_at_ppp_unref(struct ppp_link *link);

Almost forgot, let us not use struct ppp_link here, but instead use GAtPpp 
*ppp as the parameter.  Again, mostly for consistency with how glib / gatchat 
does this.

Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [patch 1/6] Add PPP protocol support with HDLC framing

2010-03-11 Thread Marcel Holtmann
Hi Denis,

  +struct ppp_link * g_at_ppp_new(GIOChannel *modem);
  +void g_at_ppp_open(struct ppp_link *link);
  +void g_at_ppp_set_connect_function(struct ppp_link *link,
  +  GAtPPPConnectFunc callback, gpointer user_data);
  +void g_at_ppp_set_disconnect_function(struct ppp_link *link,
  + GAtPPPDisconnectFunc callback,
  + gpointer user_data);
  +void g_at_ppp_shutdown(struct ppp_link *link);
  +void g_at_ppp_ref(struct ppp_link *link);
  +void g_at_ppp_unref(struct ppp_link *link);
 
 Almost forgot, let us not use struct ppp_link here, but instead use GAtPpp 
 *ppp as the parameter.  Again, mostly for consistency with how glib / gatchat 
 does this.

I am actually okay with GAtPPP since it looks much nicer. True camel
case is making it harder to read.

Regards

Marcel


___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono