All of lore.kernel.org
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [RFC v6 12/12] dun_gw: Update to org.bluez.Telephony interface
Date: Wed, 01 Aug 2012 12:09:47 +0200	[thread overview]
Message-ID: <1343815787-22670-13-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1343815787-22670-1-git-send-email-frederic.danis@linux.intel.com>

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

Bluez moves agent registration from a per device interface to
a per adapter interface.
Update dun_gw modem emulator to reflect this change.
---
 plugins/dun_gw.c |  119 ++++++++++++++++++++++++------------------------------
 1 file changed, 52 insertions(+), 67 deletions(-)

diff --git a/plugins/dun_gw.c b/plugins/dun_gw.c
index 75b62eb..5cc839e 100644
--- a/plugins/dun_gw.c
+++ b/plugins/dun_gw.c
@@ -35,77 +35,65 @@
 
 #include "bluetooth.h"
 
-#define DUN_GW_CHANNEL	1
+#define AGENT_PATH	"/dun_gw"
+#define VERSION_1_0	0x0100
+
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
 
-static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
 
-static const gchar *dun_record =
-"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
-"<record>\n"
-"  <attribute id=\"0x0001\">\n"
-"    <sequence>\n"
-"      <uuid value=\"0x1103\"/>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0004\">\n"
-"    <sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x0100\"/>\n"
-"      </sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x0003\"/>\n"
-"        <uint8 value=\"1\" name=\"channel\"/>\n"
-"      </sequence>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0009\">\n"
-"    <sequence>\n"
-"      <sequence>\n"
-"        <uuid value=\"0x1103\"/>\n"
-"        <uint16 value=\"0x0100\" name=\"version\"/>\n"
-"      </sequence>\n"
-"    </sequence>\n"
-"  </attribute>\n"
-"\n"
-"  <attribute id=\"0x0100\">\n"
-"    <text value=\"Dial-up Networking\" name=\"name\"/>\n"
-"  </attribute>\n"
-"</record>\n";
-
-static void dun_gw_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+static DBusMessage *dun_gw_agent_new_connection(DBusConnection *conn,
+						DBusMessage *msg, void *data)
 {
-	struct ofono_emulator *em = user_data;
-	struct ofono_modem *modem;
 	int fd;
+	const char *device;
+	guint16 version = 0;
+	struct ofono_emulator *em;
+	struct ofono_modem *modem;
 
-	DBG("");
+	fd = bluetooth_parse_newconnection_message(msg, &device, &version, NULL,
+							NULL);
+	if (fd < 0)
+		return __ofono_error_invalid_args(msg);
 
-	if (err) {
-		DBG("%s", err->message);
-		g_io_channel_shutdown(io, TRUE, NULL);
-		return;
-	}
+	DBG("New connection for %s (version 0x%04X)", device, version);
 
 	/* Pick the first powered modem */
 	modem = modems->data;
+	if (modem == NULL)
+		return __ofono_error_failed(msg);
+
 	DBG("Picked modem %p for emulator", modem);
 
 	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_DUN);
-	if (em == NULL) {
-		g_io_channel_shutdown(io, TRUE, NULL);
-		return;
-	}
-
-	fd = g_io_channel_unix_get_fd(io);
-	g_io_channel_set_close_on_unref(io, FALSE);
+	if (em == NULL)
+		return __ofono_error_failed(msg);
 
 	ofono_emulator_register(em, fd);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *dun_gw_agent_release(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBG("");
+
+	return dbus_message_new_method_return(msg);
 }
 
+static const GDBusMethodTable agent_methods[] = {
+	{ GDBUS_ASYNC_METHOD("NewConnection",
+				GDBUS_ARGS({ "fd", "h" },
+						{ "property", "a{sv}" }),
+				NULL, dun_gw_agent_new_connection) },
+	{ GDBUS_METHOD("Release", NULL, NULL, dun_gw_agent_release) },
+	{ }
+};
+
 static void gprs_watch(struct ofono_atom *atom,
 				enum ofono_atom_watch_condition cond,
 				void *data)
@@ -115,17 +103,16 @@ static void gprs_watch(struct ofono_atom *atom,
 	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
 		modems = g_list_append(modems, modem);
 
-		if (modems->next == NULL)
-			server = bluetooth_register_server(DUN_GW_CHANNEL,
-					dun_record,
-					dun_gw_connect_cb,
-					NULL);
+		if (modems->next != NULL)
+			return;
+
+		bluetooth_register_telephony_agent(AGENT_PATH, DUN_GW_UUID,
+						   VERSION_1_0, 0,
+						   agent_methods, NULL, NULL);
 	} else {
 		modems = g_list_remove(modems, modem);
-		if (modems == NULL && server != NULL) {
-			bluetooth_unregister_server(server);
-			server = NULL;
-		}
+		if (modems == NULL)
+			bluetooth_unregister_telephony_agent(AGENT_PATH);
 	}
 }
 
@@ -149,6 +136,9 @@ static int dun_gw_init(void)
 {
 	DBG("");
 
+	if (DBUS_TYPE_UNIX_FD < 0)
+		return -EBADF;
+
 	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
 	__ofono_modem_foreach(call_modemwatch, NULL);
@@ -160,11 +150,6 @@ static void dun_gw_exit(void)
 {
 	__ofono_modemwatch_remove(modemwatch_id);
 	g_list_free(modems);
-
-	if (server) {
-		bluetooth_unregister_server(server);
-		server = NULL;
-	}
 }
 
 OFONO_PLUGIN_DEFINE(dun_gw, "Dial-up Networking Profile Plugins", VERSION,
-- 
1.7.9.5


      parent reply	other threads:[~2012-08-01 10:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-01 10:09 [RFC v6 00/12] Add org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 01/12] bluetooth: Add org.bluez.Telephony helpers =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 02/12] hfp_hf: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 03/12] hfp_ag: " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 04/12] bluetooth: Add define for MediaTransport interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 05/12] include: Add set/get data APIs to emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 06/12] emulator: Add set/get data APIs =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 07/12] hfp_ag: Add AT+NREC support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 08/12] hfp_ag: Add +BSIR support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 09/12] hfp_ag: Add AT+VGM support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 10/12] hfp_ag: Add AT+VGS support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 11/12] emulator: Update supported features =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]

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=1343815787-22670-13-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@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.