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 |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 plugins/dun_gw.c

diff --git a/Makefile.am b/Makefile.am
index c509050..9ef6858 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -264,6 +264,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..4e33d75
--- /dev/null
+++ b/plugins/dun_gw.c
@@ -0,0 +1,113 @@
+/*
+ *  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);
+}
+
+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.0.4

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

Reply via email to