From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 6/6] Add PPP option to gsmdial
Date: Mon, 22 Mar 2010 17:06:01 -0700 [thread overview]
Message-ID: <1269302761-20125-7-git-send-email-kristen@linux.intel.com> (raw)
In-Reply-To: <1269302761-20125-1-git-send-email-kristen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3996 bytes --]
Implement new options for gsmdial to use PPP and set the user name and
password for authentication if needed.
---
gatchat/gsmdial.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/gatchat/gsmdial.c b/gatchat/gsmdial.c
index 2087e70..aee9eea 100644
--- a/gatchat/gsmdial.c
+++ b/gatchat/gsmdial.c
@@ -36,6 +36,7 @@
#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 };
@@ -48,7 +49,11 @@ static gint option_cid = 0;
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;
@@ -223,6 +228,76 @@ static void at_cgact_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
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];
@@ -233,9 +308,9 @@ static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
}
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,
@@ -452,6 +527,12 @@ static GOptionEntry options[] = {
"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 },
};
--
1.6.6.1
next prev parent reply other threads:[~2010-03-23 0:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-23 0:05 [PATCH 0/6] PPP Patches v3 Kristen Carlson Accardi
2010-03-23 0:05 ` [PATCH 1/6] Basic PPP protocol support Kristen Carlson Accardi
2010-03-23 0:05 ` [PATCH 2/6] Generic PPP control " Kristen Carlson Accardi
2010-03-23 0:05 ` [PATCH 3/6] PPP LCP support Kristen Carlson Accardi
2010-03-23 0:05 ` [PATCH 4/6] CHAP with MD5 authentication support Kristen Carlson Accardi
2010-03-23 0:06 ` [PATCH 5/6] IP support for PPP Kristen Carlson Accardi
2010-03-23 0:06 ` Kristen Carlson Accardi [this message]
2010-03-23 5:30 ` [PATCH 6/6] Add PPP option to gsmdial Gustavo F. Padovan
2010-03-23 6:30 ` Marcel Holtmann
2010-03-23 0:32 ` [PATCH 0/6] PPP Patches v3 Marcel Holtmann
2010-03-23 2:22 ` Marcel Holtmann
2010-03-23 3:22 ` Kristen Carlson Accardi
2010-03-23 3:47 ` Marcel Holtmann
2010-03-23 4:07 ` Kristen Carlson Accardi
2010-03-23 4:51 ` Marcel Holtmann
2010-03-23 6:14 ` Kristen Carlson Accardi
2010-03-23 6:45 ` Marcel Holtmann
2010-03-23 17:16 ` Kristen Carlson Accardi
2010-03-23 17:34 ` Kristen Carlson Accardi
2010-03-23 17:56 ` Marcel Holtmann
2010-03-23 18:26 ` Kristen Carlson Accardi
2010-03-23 18:37 ` Denis Kenzior
2010-03-23 19:07 ` Marcel Holtmann
2010-03-23 3:56 ` Kristen Carlson Accardi
2010-03-23 12:34 ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
2010-03-23 12:49 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269302761-20125-7-git-send-email-kristen@linux.intel.com \
--to=kristen@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.