From: Zhenhua Zhang <zhenhua.zh...@intel.com> DUN server is probed when modem state changes to online. It registers DUN record to Bluetooth adapter and wait for incoming DUN connection. --- Makefile.am | 3 + plugins/dun_gw.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 0 deletions(-) create mode 100644 plugins/dun_gw.c
diff --git a/Makefile.am b/Makefile.am index 5dcf253..58bf6c4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -291,6 +291,9 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h builtin_modules += hfp builtin_sources += plugins/hfp.c plugins/bluetooth.h +builtin_modules += dun_gw +builtin_sources += $(btio_sources) plugins/dun_gw.c plugins/bluetooth.h + builtin_modules += palmpre builtin_sources += plugins/palmpre.c diff --git a/plugins/dun_gw.c b/plugins/dun_gw.c new file mode 100644 index 0000000..803ae32 --- /dev/null +++ b/plugins/dun_gw.c @@ -0,0 +1,115 @@ +/* + * oFono - Open Source Telephony + * + * 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 <string.h> +#include <errno.h> +#include <glib.h> +#include <ofono.h> + +#define OFONO_API_SUBJECT_TO_CHANGE +#include <ofono/plugin.h> +#include <ofono/log.h> +#include <ofono/modem.h> +#include <gdbus.h> + +#include "bluetooth.h" + +#define DUN_GW_CHANNEL 1 + +static struct server *server; + +static void dun_gw_connect_cb(GIOChannel *io, GError *err, gpointer user_data) +{ + struct ofono_emulator *emulator = user_data; + + DBG(""); + + if (err) { + DBG("%s", err->message); + goto failed; + } + + if (ofono_emulator_enable(emulator, io) < 0) + goto failed; + + return; + +failed: + g_io_channel_shutdown(io, TRUE, NULL); + ofono_emulator_remove(emulator); + bluetooth_unregister_server(server); + server = NULL; +} + +static int dun_gw_probe(struct ofono_emulator *emulator, + struct ofono_modem *modem) +{ + struct ofono_atom *gprs; + + if (server) + return -1; + + DBG(""); + + gprs = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_GPRS); + /* Make sure the modem has GPRS atom */ + if (!gprs) + return -1; + + server = bluetooth_register_server(DUN_GW, "Dial-Up Networking", + DUN_GW_CHANNEL, dun_gw_connect_cb, emulator); + + return 0; +} + +static void dun_gw_remove() +{ + if (server == NULL) + return; + + DBG(""); + + bluetooth_unregister_server(server); + server = NULL; +} + +static struct ofono_emulator_driver emulator_driver = { + .name = "Dial-Up Networking", + .type = OFONO_ATOM_TYPE_EMULATOR_DUN, + .probe = dun_gw_probe, + .remove = dun_gw_remove, +}; + +static int dun_gw_init() +{ + return ofono_emulator_driver_register(&emulator_driver); +} + +static void dun_gw_exit() +{ + ofono_emulator_driver_unregister(&emulator_driver); +} + +OFONO_PLUGIN_DEFINE(dun_gw, "Dial-up Networking Profile Plugins", VERSION, + OFONO_PLUGIN_PRIORITY_DEFAULT, dun_gw_init, dun_gw_exit) -- 1.7.1 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. _______________________________________________ ofono mailing list ofono@ofono.org http://lists.ofono.org/listinfo/ofono