Open Source Telephony
 help / color / mirror / Atom feed
From: Guillaume Zajac <guillaume.zajac@linux.intel.com>
To: ofono@ofono.org
Subject: Re: [PATCH -v2 6/7] emulator: Implement dialing up for DUN
Date: Tue, 08 Feb 2011 14:53:39 +0100	[thread overview]
Message-ID: <4D514AE3.3090903@linux.intel.com> (raw)
In-Reply-To: <1296855983-24868-6-git-send-email-padovan@profusion.mobi>

[-- Attachment #1: Type: text/plain, Size: 4718 bytes --]

Hi Gustavo,

On 04/02/2011 22:46, Gustavo F. Padovan wrote:
> It handles client ATD*99# request and then initiate the PPP negotiation.
> IP forward through the new ppp interface is not done yet.
>
> Initially based on patches from Zhenhua Zhang<zhenhua.zhang@intel.com>
> ---
>   src/emulator.c |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 files changed, 123 insertions(+), 0 deletions(-)
>
> diff --git a/src/emulator.c b/src/emulator.c
> index 49b129b..f1a079d 100644
> --- a/src/emulator.c
> +++ b/src/emulator.c
> @@ -32,11 +32,18 @@
>   #include "ofono.h"
>   #include "common.h"
>   #include "gatserver.h"
> +#include "gatppp.h"
> +
> +#define DUN_SERVER_ADDRESS	"192.168.1.1"
> +#define DUN_PEER_ADDRESS	"192.168.1.2"
> +#define DUN_DNS_SERVER_1	"10.10.10.10"
> +#define DUN_DNS_SERVER_2	"10.10.10.11"
>
>   struct ofono_emulator {
>   	struct ofono_modem *modem;
>   	struct ofono_atom *atom;
>   	GAtServer *server;
> +	GAtPPP *ppp;
>   	struct ofono_emulator_driver *driver;
>   };
>
> @@ -55,10 +62,124 @@ void ofono_emulator_remove(struct ofono_emulator *emulator)
>   	__ofono_atom_free(emulator->atom);
>   }
>
> +static void ppp_connect(const char *iface, const char *local,
> +			const char *remote,
> +			const char *dns1, const char *dns2,
> +			gpointer user_data)
> +{
> +	DBG("Network Device: %s\n", iface);
> +	DBG("IP Address: %s\n", local);
> +	DBG("Remote IP Address: %s\n", remote);
> +	DBG("Primary DNS Server: %s\n", dns1);
> +	DBG("Secondary DNS Server: %s\n", dns2);
> +}
> +
> +static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
> +{
> +	struct ofono_emulator *e = user_data;
> +
> +	DBG("");
> +
> +	g_at_ppp_unref(e->ppp);
> +	e->ppp = NULL;
> +
> +	if (e->server == NULL)
> +		return;
> +
> +	g_at_server_resume(e->server);
> +
> +	g_at_server_send_final(e->server, G_AT_SERVER_RESULT_NO_CARRIER);
> +}
> +
> +static gboolean setup_ppp(gpointer user_data)
> +{
> +	struct ofono_emulator *e = user_data;
> +	GAtServer *server = e->server;
> +	GAtIO *io;
> +
> +	DBG("");
> +
> +	io = g_at_server_get_io(server);
> +
> +	g_at_server_suspend(server);
> +
> +	e->ppp = g_at_ppp_server_new_from_io(io, DUN_SERVER_ADDRESS);
> +	if (e->ppp == NULL) {
> +		g_at_server_resume(server);
> +		return FALSE;
> +	}
> +
> +	g_at_ppp_set_server_info(e->ppp, DUN_PEER_ADDRESS,
> +					DUN_DNS_SERVER_1, DUN_DNS_SERVER_2);
> +
> +	g_at_ppp_set_credentials(e->ppp, "", "");
> +	g_at_ppp_set_debug(e->ppp, ofono_emulator_debug, "PPP");
> +
> +	g_at_ppp_set_connect_function(e->ppp, ppp_connect, e);
> +	g_at_ppp_set_disconnect_function(e->ppp, ppp_disconnect, e);
> +
> +	return FALSE;
> +}
> +
> +static gboolean dial_call(struct ofono_emulator *e, const char *dial_str)
> +{
> +	char c = *dial_str;
> +
> +	DBG("dial call %s", dial_str);
> +
> +	if (c == '*' || c == '#' || c == 'T' || c == 't') {
> +
> +		g_at_server_send_intermediate(e->server, "CONNECT");
> +		g_idle_add(setup_ppp, e);
> +	}
> +
> +	return TRUE;
> +}
> +
> +static void dial_cb(GAtServerRequestType type, GAtResult *result,
> +					gpointer user_data)
> +{
> +	struct ofono_emulator *e = user_data;
> +	GAtServer *server = e->server;
> +	GAtResultIter iter;
> +	const char *dial_str;
> +
> +	DBG("");
> +
> +	if (type != G_AT_SERVER_REQUEST_TYPE_SET)
> +		goto error;
> +
> +	g_at_result_iter_init(&iter, result);
> +
> +	if (!g_at_result_iter_next(&iter, "D"))
> +		goto error;
> +
> +	dial_str = g_at_result_iter_raw_line(&iter);
> +	if (!dial_str)
> +		goto error;
> +
> +	if (e->ppp)
> +		goto error;
> +
> +	if (!dial_call(e, dial_str))
> +		goto error;
> +
> +	return;
> +
> +error:
> +	g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
> +}
> +

Shouldn't we register a generic dial_cb() and separate it in 2 cases:
     OFONO_ATOM_TYPE_DUN_EMULATOR, we do a dun_dial() that would look 
like the dial_cb() you have implemented.
     OFONO_ATOM_TYPE_HFP_AG, we do a hfp_dial() e.g. dial a number for a 
voice call.

>   static void emulator_disable(struct ofono_emulator *e)
>   {
>   	DBG("");
>
> +	if (e->ppp) {
> +		g_at_ppp_shutdown(e->ppp);
> +		g_at_ppp_unref(e->ppp);
> +		e->ppp = NULL;
> +	}
> +
>   	g_at_server_shutdown(e->server);
>   	g_at_server_unref(e->server);
>   	e->server = NULL;
> @@ -93,6 +214,8 @@ int ofono_emulator_enable(struct ofono_emulator *e, int fd)
>   	g_at_server_set_disconnect_function(e->server,
>   						emulator_disconnect_cb, e);
>
> +	g_at_server_register(e->server, "D", dial_cb, e, NULL);
> +
>   	return 0;
>   }
>
Kind regards,
Guillaume

  parent reply	other threads:[~2011-02-08 13:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-04 21:46 [PATCH -v2 1/7] bluetooth: Add bluetooth server support Gustavo F. Padovan
2011-02-04 21:46 ` [PATCH -v2 2/7] bluetooth: Add Bluetooth service authorization support Gustavo F. Padovan
2011-02-04 21:46   ` [PATCH -v2 3/7] include: add public headed to emulator atom Gustavo F. Padovan
2011-02-04 21:46     ` [PATCH -v2 4/7] emulator: Add emulator atom in oFono Gustavo F. Padovan
2011-02-04 21:46       ` [PATCH -v2 5/7] dun_gw: Add DUN server plugin for oFono Gustavo F. Padovan
2011-02-04 21:46         ` [PATCH -v2 6/7] emulator: Implement dialing up for DUN Gustavo F. Padovan
2011-02-04 21:46           ` [PATCH -v2 7/7] gsmdial: add option for Bluetooth DUN dialing Gustavo F. Padovan
2011-02-08 13:53           ` Guillaume Zajac [this message]
2011-02-08 18:46             ` [PATCH -v2 6/7] emulator: Implement dialing up for DUN Gustavo F. Padovan
2011-02-07  9:21         ` [PATCH -v2 5/7] dun_gw: Add DUN server plugin for oFono Guillaume Zajac
2011-02-07 18:19           ` Gustavo F. Padovan
2011-02-08  9:16             ` Guillaume Zajac

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=4D514AE3.3090903@linux.intel.com \
    --to=guillaume.zajac@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox