* [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard
@ 2013-02-15 12:09 Szymon Janc
2013-02-15 12:09 ` [PATCH v2 2/6] neard: Restrict method calls only to neard process Szymon Janc
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
plugins/neard.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index a1b385e..650ee3e 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -49,7 +49,7 @@
#define ERROR_INTERFACE "org.neard.HandoverAgent.Error"
static guint watcher_id = 0;
-static gboolean agent_registered = FALSE;
+static char *neard_service = NULL;
static gboolean agent_register_postpone = FALSE;
/* For NFC mimetype limits max OOB EIR size */
@@ -115,7 +115,7 @@ static void register_agent_cb(DBusPendingCall *call, void *user_data)
}
dbus_message_unref(reply);
- agent_registered = TRUE;
+ neard_service = g_strdup(dbus_message_get_sender(reply));
}
static void register_agent(void)
@@ -152,7 +152,8 @@ static void unregister_agent(void)
DBusMessage *message;
const char *path = AGENT_PATH;
- agent_registered = FALSE;
+ g_free(neard_service);
+ neard_service = NULL;
message = dbus_message_new_method_call(NEARD_NAME, NEARD_PATH,
NEARD_MANAGER_INTERFACE, "UnregisterHandoverAgent");
@@ -237,7 +238,7 @@ static void read_local_complete(struct btd_adapter *adapter,
DBG("");
- if (!agent_registered) {
+ if (neard_service == NULL) {
dbus_message_unref(msg);
if (agent_register_postpone) {
@@ -269,7 +270,7 @@ static void bonding_complete(struct btd_adapter *adapter,
DBG("");
- if (!agent_registered) {
+ if (neard_service == NULL) {
dbus_message_unref(msg);
if (agent_register_postpone) {
@@ -777,7 +778,9 @@ static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
{
DBG("");
- agent_registered = FALSE;
+ g_free(neard_service);
+ neard_service = NULL;
+
g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -824,8 +827,10 @@ static void neard_vanished(DBusConnection *conn, void *user_data)
DBG("");
/* neard existed without unregistering agent */
- if (agent_registered) {
- agent_registered = FALSE;
+ if (neard_service != NULL) {
+ g_free(neard_service);
+ neard_service = NULL;
+
g_dbus_unregister_interface(conn, AGENT_PATH, AGENT_INTERFACE);
}
}
@@ -850,7 +855,7 @@ static void neard_exit(void)
g_dbus_remove_watch(btd_get_dbus_connection(), watcher_id);
watcher_id = 0;
- if (agent_registered)
+ if (neard_service != NULL)
unregister_agent();
}
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/6] neard: Restrict method calls only to neard process
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
@ 2013-02-15 12:09 ` Szymon Janc
2013-02-15 12:09 ` [PATCH v2 3/6] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Disallow methods calls from processes other than registered to as
agent.
---
plugins/neard.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/plugins/neard.c b/plugins/neard.c
index 650ee3e..88a6229 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -637,6 +637,10 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
uint8_t io_cap;
int err;
+ if (neard_service == NULL ||
+ !g_str_equal(neard_service, dbus_message_get_sender(msg)))
+ return error_reply(msg, EPERM);
+
DBG("");
adapter = btd_adapter_get_default();
@@ -714,6 +718,10 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
struct btd_device *device;
int err;
+ if (neard_service == NULL ||
+ !g_str_equal(neard_service, dbus_message_get_sender(msg)))
+ return error_reply(msg, EPERM);
+
DBG("");
adapter = btd_adapter_get_default();
@@ -776,6 +784,10 @@ read_local:
static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
void *user_data)
{
+ if (neard_service == NULL ||
+ !g_str_equal(neard_service, dbus_message_get_sender(msg)))
+ return error_reply(msg, EPERM);
+
DBG("");
g_free(neard_service);
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/6] neard: Use bool instead of gboolean for agent_register_postpone
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
2013-02-15 12:09 ` [PATCH v2 2/6] neard: Restrict method calls only to neard process Szymon Janc
@ 2013-02-15 12:09 ` Szymon Janc
2013-02-15 12:09 ` [PATCH v2 4/6] neard: Update copyright information Szymon Janc
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
There is no need to use gboolean as this flag is not used with any
glib function.
---
plugins/neard.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index 88a6229..6025d89 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -50,7 +50,7 @@
static guint watcher_id = 0;
static char *neard_service = NULL;
-static gboolean agent_register_postpone = FALSE;
+static bool agent_register_postpone = false;
/* For NFC mimetype limits max OOB EIR size */
#define NFC_OOB_EIR_MAX UINT8_MAX
@@ -242,7 +242,7 @@ static void read_local_complete(struct btd_adapter *adapter,
dbus_message_unref(msg);
if (agent_register_postpone) {
- agent_register_postpone = FALSE;
+ agent_register_postpone = false;
register_agent();
}
@@ -274,7 +274,7 @@ static void bonding_complete(struct btd_adapter *adapter,
dbus_message_unref(msg);
if (agent_register_postpone) {
- agent_register_postpone = FALSE;
+ agent_register_postpone = false;
register_agent();
}
@@ -829,7 +829,7 @@ static void neard_appeared(DBusConnection *conn, void *user_data)
adapter = btd_adapter_get_default();
if (adapter && btd_adapter_check_oob_handler(adapter))
- agent_register_postpone = TRUE;
+ agent_register_postpone = true;
else
register_agent();
}
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/6] neard: Update copyright information
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
2013-02-15 12:09 ` [PATCH v2 2/6] neard: Restrict method calls only to neard process Szymon Janc
2013-02-15 12:09 ` [PATCH v2 3/6] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
@ 2013-02-15 12:09 ` Szymon Janc
2013-02-15 12:09 ` [PATCH v2 5/6] neard: Updated neard handover registration agent api calls Szymon Janc
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
plugins/neard.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index 6025d89..2e583be 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -2,7 +2,7 @@
*
* BlueZ - Bluetooth protocol stack for Linux
*
- * Copyright (C) 2012 Tieto Poland
+ * Copyright (C) 2012-2013 Tieto Poland
*
*
* This program is free software; you can redistribute it and/or modify
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/6] neard: Updated neard handover registration agent api calls.
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
` (2 preceding siblings ...)
2013-02-15 12:09 ` [PATCH v2 4/6] neard: Update copyright information Szymon Janc
@ 2013-02-15 12:09 ` Szymon Janc
2013-02-15 12:09 ` [PATCH v2 6/6] neard: Add fallback to legacy register if register failed Szymon Janc
2013-02-15 14:33 ` [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Johan Hedberg
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
From: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
neard RegisterHandoverAgent and UnregisterHandoverAgent apis
need an extra parameter of carrier type(e.g. bluetooth).
---
plugins/neard.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/plugins/neard.c b/plugins/neard.c
index 2e583be..697967a 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -46,6 +46,7 @@
#define NEARD_MANAGER_INTERFACE "org.neard.Manager"
#define AGENT_INTERFACE "org.neard.HandoverAgent"
#define AGENT_PATH "/org/bluez/neard_handover_agent"
+#define AGENT_CARRIER_TYPE "bluetooth"
#define ERROR_INTERFACE "org.neard.HandoverAgent.Error"
static guint watcher_id = 0;
@@ -123,6 +124,7 @@ static void register_agent(void)
DBusMessage *message;
DBusPendingCall *call;
const char *path = AGENT_PATH;
+ const char *carrier = AGENT_CARRIER_TYPE;
message = dbus_message_new_method_call(NEARD_NAME, NEARD_PATH,
NEARD_MANAGER_INTERFACE, "RegisterHandoverAgent");
@@ -134,6 +136,9 @@ static void register_agent(void)
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &carrier,
+ DBUS_TYPE_INVALID);
+
if (!dbus_connection_send_with_reply(btd_get_dbus_connection(),
message, &call, -1)) {
dbus_message_unref(message);
@@ -151,6 +156,7 @@ static void unregister_agent(void)
{
DBusMessage *message;
const char *path = AGENT_PATH;
+ const char *carrier = AGENT_CARRIER_TYPE;
g_free(neard_service);
neard_service = NULL;
@@ -166,6 +172,9 @@ static void unregister_agent(void)
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &carrier,
+ DBUS_TYPE_INVALID);
+
if (!g_dbus_send_message(btd_get_dbus_connection(), message))
error("D-Bus send failed");
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 6/6] neard: Add fallback to legacy register if register failed
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
` (3 preceding siblings ...)
2013-02-15 12:09 ` [PATCH v2 5/6] neard: Updated neard handover registration agent api calls Szymon Janc
@ 2013-02-15 12:09 ` Szymon Janc
2013-02-15 14:33 ` [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Johan Hedberg
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2013-02-15 12:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will allow to work with neard 0.9 which doesn't support handover
agent register with carrier type.
---
plugins/neard.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/plugins/neard.c b/plugins/neard.c
index 697967a..4075f73 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -96,30 +96,48 @@ static DBusMessage *error_reply(DBusMessage *msg, int error)
return g_dbus_create_error(msg, name , "%s", strerror(error));
}
+static void register_agent(bool append_carrier);
+
static void register_agent_cb(DBusPendingCall *call, void *user_data)
{
DBusMessage *reply;
DBusError err;
+ static bool try_fallback = true;
reply = dbus_pending_call_steal_reply(call);
dbus_error_init(&err);
if (dbus_set_error_from_message(&err, reply)) {
- error("neard manager replied with an error: %s, %s",
- err.name, err.message);
+ if (g_str_equal(DBUS_ERROR_UNKNOWN_METHOD, err.name) &&
+ try_fallback) {
+ info("Register to neard failed, trying legacy way");
+
+ register_agent(false);
+ try_fallback = false;
+ } else {
+ error("neard manager replied with an error: %s, %s",
+ err.name, err.message);
+
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ AGENT_PATH, AGENT_INTERFACE);
+ try_fallback = true;
+ }
+
dbus_error_free(&err);
dbus_message_unref(reply);
- g_dbus_unregister_interface(btd_get_dbus_connection(),
- AGENT_PATH, AGENT_INTERFACE);
return;
}
dbus_message_unref(reply);
neard_service = g_strdup(dbus_message_get_sender(reply));
+
+ try_fallback = true;
+
+ info("Registered as neard handover agent");
}
-static void register_agent(void)
+static void register_agent(bool append_carrier)
{
DBusMessage *message;
DBusPendingCall *call;
@@ -136,7 +154,8 @@ static void register_agent(void)
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- dbus_message_append_args(message, DBUS_TYPE_STRING, &carrier,
+ if (append_carrier)
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &carrier,
DBUS_TYPE_INVALID);
if (!dbus_connection_send_with_reply(btd_get_dbus_connection(),
@@ -252,7 +271,7 @@ static void read_local_complete(struct btd_adapter *adapter,
if (agent_register_postpone) {
agent_register_postpone = false;
- register_agent();
+ register_agent(true);
}
return;
@@ -284,7 +303,7 @@ static void bonding_complete(struct btd_adapter *adapter,
if (agent_register_postpone) {
agent_register_postpone = false;
- register_agent();
+ register_agent(true);
}
return;
@@ -840,7 +859,7 @@ static void neard_appeared(DBusConnection *conn, void *user_data)
if (adapter && btd_adapter_check_oob_handler(adapter))
agent_register_postpone = true;
else
- register_agent();
+ register_agent(true);
}
static void neard_vanished(DBusConnection *conn, void *user_data)
--
1.8.1.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
` (4 preceding siblings ...)
2013-02-15 12:09 ` [PATCH v2 6/6] neard: Add fallback to legacy register if register failed Szymon Janc
@ 2013-02-15 14:33 ` Johan Hedberg
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2013-02-15 14:33 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Fri, Feb 15, 2013, Szymon Janc wrote:
> ---
> plugins/neard.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-02-15 14:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-15 12:09 [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Szymon Janc
2013-02-15 12:09 ` [PATCH v2 2/6] neard: Restrict method calls only to neard process Szymon Janc
2013-02-15 12:09 ` [PATCH v2 3/6] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
2013-02-15 12:09 ` [PATCH v2 4/6] neard: Update copyright information Szymon Janc
2013-02-15 12:09 ` [PATCH v2 5/6] neard: Updated neard handover registration agent api calls Szymon Janc
2013-02-15 12:09 ` [PATCH v2 6/6] neard: Add fallback to legacy register if register failed Szymon Janc
2013-02-15 14:33 ` [PATCH v2 1/6] neard: Use service name and not boolean to track if registered to neard Johan Hedberg
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.