All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/14] neard plugin update
@ 2013-02-07  8:13 Szymon Janc
  2013-02-07  8:13 ` [PATCH 01/14] neard: Adjust errors to latest API changes Szymon Janc
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

This set adds some new features to neard plugin to match it with
recent changes in neard daemon:
- support for carrier power state hint (already merged)
- update register API [with fallback to legacy support] (pending review)

Power state hint could be use to improve IOP e.g. delay or retry pairing when
remote device in activating or incative state.

Other than that bugfixes, small improvements and some code refactoring to
make it better prepared for future feature addition e.g. to perform more
action on PushOOB than only pairing.

There are still some open points regarding how to properly map adapter
state (powered/pairable/connectable) to carrier power state but those
could be discussed separately later on.

Comments are welcome.

BR
Szymon Janc

Ravi kumar Veeramally (1):
  neard: Updated neard handover registration agent api calls.

Szymon Janc (13):
  neard: Adjust errors to latest API changes
  neard: Refactor message processing
  neard: Add ability to parse 'State' field
  neard: Move pairable check from check_adapter
  adapter: Add btd_adapter_get_powered function
  neard: Check if adapter is powered in PushOOB
  adapter: Add btd_adapter_get_connectable function
  neard: Add support for setting power state in RequestOOB reply
  neard: Use path instead of boolean to track if registered to neard
  neard: Restrict method calls only to neard process
  neard: Use bool instead of gboolean for agent_register_postpone
  neard: Update copyright information
  neard: Add fallback to legacy register if register failed

 plugins/neard.c | 562 ++++++++++++++++++++++++++++++++++----------------------
 src/adapter.c   |  16 ++
 src/adapter.h   |   2 +
 3 files changed, 361 insertions(+), 219 deletions(-)

-- 
1.8.1.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/14] neard: Adjust errors to latest API changes
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 02/14] neard: Refactor message processing Szymon Janc
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

neard Handover API was stripped of not really usefull error codes.
---
 plugins/neard.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index b0150e9..6272144 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -57,27 +57,14 @@ static gboolean agent_register_postpone = FALSE;
 
 static DBusMessage *error_reply(DBusMessage *msg, int error)
 {
-	switch (error) {
-	case ENOTSUP:
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".NotSupported",
-						"Operation is not supported");
+	const char *name;
 
-	case ENOENT:
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".NoSuchDevice",
-							"No such device");
-
-	case EINPROGRESS:
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
-						"Operation already in progress");
-
-	case ENONET:
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".Disabled",
-							"Device disabled");
+	if (error == EINPROGRESS)
+		name = ERROR_INTERFACE ".InProgress";
+	else
+		name = ERROR_INTERFACE ".Failed";
 
-	default:
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
-							"%s", strerror(error));
-	}
+	return g_dbus_create_error(msg, name , "%s", strerror(error));
 }
 
 static void register_agent_cb(DBusPendingCall *call, void *user_data)
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/14] neard: Refactor message processing
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
  2013-02-07  8:13 ` [PATCH 01/14] neard: Adjust errors to latest API changes Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 03/14] neard: Add ability to parse 'State' field Szymon Janc
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

This refactor code for message processing for future feature addition.
nokia.com:bt and EIR processing is now separated from performing
actions based on received data.
---
 plugins/neard.c | 308 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 157 insertions(+), 151 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 6272144..7df4544 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -55,6 +55,26 @@ static gboolean agent_register_postpone = FALSE;
 /* For NFC mimetype limits max OOB EIR size */
 #define NFC_OOB_EIR_MAX UINT8_MAX
 
+struct oob_params {
+	bdaddr_t address;
+	uint32_t class;
+	char *name;
+	GSList *services;
+	uint8_t *hash;
+	uint8_t *randomizer;
+	uint8_t *pin;
+	int pin_len;
+};
+
+static void free_oob_params(struct oob_params *params)
+{
+	g_slist_free_full(params->services, g_free);
+	g_free(params->name);
+	g_free(params->hash);
+	g_free(params->randomizer);
+	g_free(params->pin);
+}
+
 static DBusMessage *error_reply(DBusMessage *msg, int error)
 {
 	const char *name;
@@ -268,14 +288,9 @@ static int check_device(struct btd_device *device)
 	return 0;
 }
 
-/* returns 1 if action (pairing or reading local data) is not needed */
-static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
-							bdaddr_t *remote)
+static int process_eir(uint8_t *eir, size_t size, struct oob_params *remote)
 {
 	struct eir_data eir_data;
-	char remote_address[18];
-	struct btd_device *device;
-	int err;
 
 	DBG("size %zu", size);
 
@@ -284,48 +299,25 @@ static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
 	if (eir_parse_oob(&eir_data, eir, size) < 0)
 		return -EINVAL;
 
-	ba2str(&eir_data.addr, remote_address);
-
-	DBG("hci%u remote:%s", btd_adapter_get_index(adapter), remote_address);
-
-	device = adapter_get_device(adapter, &eir_data.addr, BDADDR_BREDR);
-
-	err = check_device(device);
-	if (err < 0) {
-		eir_data_free(&eir_data);
-		return err;
-	}
+	bacpy(&remote->address, &eir_data.addr);
 
-	/* store OOB data */
-	if (eir_data.class != 0)
-		device_set_class(device, eir_data.class);
+	remote->class = eir_data.class;
 
-	/* TODO handle incomplete name? */
-	if (eir_data.name) {
-		adapter_store_cached_name(adapter_get_address(adapter),
-					&eir_data.addr, eir_data.name);
-		device_set_name(device, eir_data.name);
-	}
+	remote->name = eir_data.name;
+	eir_data.name = NULL;
 
-	if (eir_data.hash)
-		btd_adapter_add_remote_oob_data(adapter, &eir_data.addr,
-					eir_data.hash, eir_data.randomizer);
+	remote->services = eir_data.services;
+	eir_data.services = NULL;
 
-	/* TODO handle UUIDs? */
+	remote->hash = eir_data.hash;
+	eir_data.hash = NULL;
 
-	if (remote)
-		bacpy(remote, &eir_data.addr);
-
-	/*
-	 * In RequestOOB reply append local hash and randomizer only if
-	 * received EIR also contained it.
-	 */
-	if (!remote && !eir_data.hash)
-		err = -EALREADY;
+	remote->randomizer = eir_data.randomizer;
+	eir_data.randomizer = NULL;
 
 	eir_data_free(&eir_data);
 
-	return err;
+	return 0;
 }
 
 /*
@@ -350,16 +342,8 @@ static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
  * N bytes - name
  */
 
-struct nokia_com_bt {
-	bdaddr_t address;
-	uint32_t cod;
-	uint8_t pin[16];
-	int pin_len;
-	char *name;
-};
-
 static int process_nokia_long (void *data, size_t size, uint8_t marker,
-						struct nokia_com_bt *nokia)
+						struct oob_params *remote)
 {
 	struct {
 		bdaddr_t address;
@@ -373,26 +357,26 @@ static int process_nokia_long (void *data, size_t size, uint8_t marker,
 		return -EINVAL;
 
 	/* address is not reverted */
-	baswap(&nokia->address, &n->address);
+	baswap(&remote->address, &n->address);
 
-	nokia->cod = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
+	remote->class = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
 
 	if (n->name_len > 0)
-		nokia->name = g_strndup((char *)n->name, n->name_len);
+		remote->name = g_strndup((char *)n->name, n->name_len);
 
 	if (marker == 0x01) {
-		memcpy(nokia->pin, n->authentication, 4);
-		nokia->pin_len = 4;
+		remote->pin = g_memdup(n->authentication, 4);
+		remote->pin_len = 4;
 	} else if (marker == 0x02) {
-		memcpy(nokia->pin, n->authentication, 16);
-		nokia->pin_len = 16;
+		remote->pin = g_memdup(n->authentication, 16);
+		remote->pin_len = 16;
 	}
 
 	return 0;
 }
 
 static int process_nokia_short (void *data, size_t size,
-						struct nokia_com_bt *nokia)
+						struct oob_params *remote)
 {
 	struct {
 		bdaddr_t address;
@@ -406,21 +390,21 @@ static int process_nokia_short (void *data, size_t size,
 		return -EINVAL;
 
 	/* address is not reverted */
-	baswap(&nokia->address, &n->address);
+	baswap(&remote->address, &n->address);
 
-	nokia->cod = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
+	remote->class = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
 
 	if (n->name_len > 0)
-		nokia->name = g_strndup((char *)n->name, n->name_len);
+		remote->name = g_strndup((char *)n->name, n->name_len);
 
-	memcpy(nokia->pin, n->authentication, 4);
-	nokia->pin_len = 4;
+	remote->pin = g_memdup(n->authentication, 4);
+	remote->pin_len = 4;
 
 	return 0;
 }
 
 static int process_nokia_extra_short (void *data, size_t size,
-						struct nokia_com_bt *nokia)
+						struct oob_params *remote)
 {
 	struct {
 		bdaddr_t address;
@@ -432,95 +416,42 @@ static int process_nokia_extra_short (void *data, size_t size,
 	if (size != sizeof(*n) + n->name_len)
 		return -EINVAL;
 
-	bacpy(&nokia->address, &n->address);
+	bacpy(&remote->address, &n->address);
 
-	nokia->cod = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
+	remote->class = n->class[0] | (n->class[1] << 8) | (n->class[2] << 16);
 
 	if (n->name_len > 0)
-		nokia->name = g_strndup((char *)n->name, n->name_len);
+		remote->name = g_strndup((char *)n->name, n->name_len);
 
 	return 0;
 }
 
-/* returns 1 if pairing is not needed */
-static int process_nokia_com_bt(struct btd_adapter *adapter, void *data,
-						size_t size, bdaddr_t *remote)
+static int process_nokia_com_bt(uint8_t *data, size_t size,
+						struct oob_params *remote)
 {
-	uint8_t *marker;
-	struct nokia_com_bt nokia;
-	struct btd_device *device;
-	int ret;
-	char remote_address[18];
-
-	/* Support this only for PushOOB */
-	if (!remote)
-		return -EOPNOTSUPP;
+	uint8_t marker;
 
-	marker = data++;
-	size --;
+	marker = *data++;
+	size--;
 
-	DBG("marker: 0x%.2x  size: %zu", *marker, size);
+	DBG("marker: 0x%.2x  size: %zu", marker, size);
 
-	memset(&nokia, 0, sizeof(nokia));
-
-	switch (*marker) {
+	switch (marker) {
 	case 0x00:
 	case 0x01:
 	case 0x02:
-		ret = process_nokia_long(data, size, *marker, &nokia);
-		break;
+		return process_nokia_long(data, size, marker, remote);
 	case 0x10:
-		ret = process_nokia_extra_short(data, size, &nokia);
-		break;
+		return process_nokia_extra_short(data, size, remote);
 	case 0x24:
-		ret = process_nokia_short(data, size, &nokia);
-		break;
+		return process_nokia_short(data, size, remote);
 	default:
-		info("Not supported Nokia NFC extension (0x%.2x)", *marker);
-		ret = -EPROTONOSUPPORT;
-		break;
-	}
-
-	if (ret < 0)
-		return ret;
-
-	ba2str(&nokia.address, remote_address);
-	DBG("hci%u remote:%s", btd_adapter_get_index(adapter), remote_address);
-
-	device = adapter_get_device(adapter, &nokia.address, BDADDR_BREDR);
-
-	ret = check_device(device);
-	if (ret != 0) {
-		g_free(nokia.name);
-		return ret;
-	}
-
-	DBG("hci%u remote:%s", btd_adapter_get_index(adapter), remote_address);
-
-	if (nokia.name) {
-		adapter_store_cached_name(adapter_get_address(adapter), remote,
-								nokia.name);
-		device_set_name(device, nokia.name);
-		g_free(nokia.name);
+		info("Not supported Nokia NFC extension (0x%.2x)", marker);
+		return -EPROTONOSUPPORT;
 	}
-
-	if (nokia.cod != 0)
-		device_set_class(device, nokia.cod);
-
-	if (nokia.pin_len > 0) {
-		/* TODO
-		 * Handle PIN, for now only discovery mode and 'common' PINs
-		 * that might be provided by agent will work correctly.
-		 */
-	}
-
-	bacpy(remote, &nokia.address);
-
-	return 0;
 }
 
-static int process_params(DBusMessage *msg, struct btd_adapter *adapter,
-							bdaddr_t *remote)
+static int process_message(DBusMessage *msg, struct oob_params *remote)
 {
 	DBusMessageIter iter;
 	DBusMessageIter dict;
@@ -538,8 +469,8 @@ static int process_params(DBusMessage *msg, struct btd_adapter *adapter,
 
 	type = dbus_message_iter_get_arg_type(&dict);
 	if (type != DBUS_TYPE_DICT_ENTRY) {
-		if (!remote && type == DBUS_TYPE_INVALID)
-			return -EALREADY;
+		if (type == DBUS_TYPE_INVALID)
+			return -ENOENT;
 
 		return -EINVAL;
 	}
@@ -566,7 +497,7 @@ static int process_params(DBusMessage *msg, struct btd_adapter *adapter,
 		dbus_message_iter_recurse(&value, &array);
 		dbus_message_iter_get_fixed_array(&array, &eir, &size);
 
-		return process_eir(adapter, eir, size, remote);
+		return process_eir(eir, size, remote);
 	} else if (strcasecmp(key, "nokia.com:bt") == 0) {
 		DBusMessageIter array;
 		uint8_t *data;
@@ -575,7 +506,7 @@ static int process_params(DBusMessage *msg, struct btd_adapter *adapter,
 		dbus_message_iter_recurse(&value, &array);
 		dbus_message_iter_get_fixed_array(&array, &data, &size);
 
-		return process_nokia_com_bt(adapter, data, size, remote);
+		return process_nokia_com_bt(data, size, remote);
 	}
 
 	return -EINVAL;
@@ -598,12 +529,39 @@ static int check_adapter(struct btd_adapter *adapter)
 	return 0;
 }
 
+static void store_params(struct btd_adapter *adapter, struct btd_device *device,
+						struct oob_params *params)
+{
+	if (params->class != 0)
+		device_set_class(device, params->class);
+
+	if (params->name) {
+		adapter_store_cached_name(adapter_get_address(adapter),
+						&params->address, params->name);
+		device_set_name(device, params->name);
+	}
+
+	/* TODO handle UUIDs? */
+
+	if (params->hash) {
+		btd_adapter_add_remote_oob_data(adapter, &params->address,
+							params->hash,
+							params->randomizer);
+	} else if (params->pin_len) {
+		/* TODO
+		 * Handle PIN, for now only discovery mode and 'common' PINs
+		 * that might be provided by agent will work correctly.
+		 */
+	}
+}
+
 static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 {
 	struct btd_adapter *adapter;
 	struct agent *agent;
 	struct oob_handler *handler;
-	bdaddr_t remote;
+	struct oob_params remote;
+	struct btd_device *device;
 	uint8_t io_cap;
 	int err;
 
@@ -615,15 +573,6 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 	if (err < 0)
 		return error_reply(msg, -err);
 
-	err = process_params(msg, adapter, &remote);
-
-	/* already paired, reply immediately */
-	if (err == -EALREADY)
-		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-
-	if (err < 0)
-		return error_reply(msg, -err);
-
 	agent = adapter_get_agent(adapter);
 	if (!agent)
 		return error_reply(msg, ENONET);
@@ -631,13 +580,43 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 	io_cap = agent_get_io_capability(agent);
 	agent_unref(agent);
 
-	err = adapter_create_bonding(adapter, &remote, BDADDR_BREDR, io_cap);
+	memset(&remote, 0, sizeof(remote));
+
+	err = process_message(msg, &remote);
+	if (err < 0)
+		return error_reply(msg, -err);
+
+	if (bacmp(&remote.address, BDADDR_ANY) == 0) {
+		free_oob_params(&remote);
+
+		return error_reply(msg, EINVAL);
+	}
+
+	device = adapter_get_device(adapter, &remote.address, BDADDR_BREDR);
+
+	err = check_device(device);
+	if (err < 0) {
+		free_oob_params(&remote);
+
+		/* already paired, reply immediately */
+		if (err == -EALREADY)
+			return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+		return error_reply(msg, -err);
+	}
+
+	store_params(adapter, device, &remote);
+
+	free_oob_params(&remote);
+
+	err = adapter_create_bonding(adapter, device_get_address(device),
+							BDADDR_BREDR, io_cap);
 	if (err < 0)
 		return error_reply(msg, -err);
 
 	handler = g_new0(struct oob_handler, 1);
 	handler->bonding_cb = bonding_complete;
-	bacpy(&handler->remote_addr, &remote);
+	bacpy(&handler->remote_addr, device_get_address(device));
 	handler->user_data = dbus_message_ref(msg);
 
 	btd_adapter_set_oob_handler(adapter, handler);
@@ -650,6 +629,8 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
 {
 	struct btd_adapter *adapter;
 	struct oob_handler *handler;
+	struct oob_params remote;
+	struct btd_device *device;
 	int err;
 
 	DBG("");
@@ -660,13 +641,38 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
 	if (err < 0)
 		return error_reply(msg, -err);
 
-	err = process_params(msg, adapter, NULL);
-	if (err == -EALREADY)
-		return create_request_oob_reply(adapter, NULL, NULL, msg);
+	memset(&remote, 0, sizeof(remote));
 
+	err = process_message(msg, &remote);
 	if (err < 0)
 		return error_reply(msg, -err);
 
+	if (bacmp(&remote.address, BDADDR_ANY) == 0)
+		goto read_local;
+
+	device = adapter_get_device(adapter, &remote.address, BDADDR_BREDR);
+
+	err = check_device(device);
+	if (err < 0) {
+		free_oob_params(&remote);
+
+		if (err == -EALREADY)
+			return create_request_oob_reply(adapter, NULL, NULL,
+									msg);
+
+		return error_reply(msg, -err);
+	}
+
+	store_params(adapter, device, &remote);
+
+	if (!remote.hash) {
+		free_oob_params(&remote);
+		return create_request_oob_reply(adapter, NULL, NULL, msg);
+	}
+
+read_local:
+	free_oob_params(&remote);
+
 	err = btd_adapter_read_local_oob_data(adapter);
 	if (err < 0)
 		return error_reply(msg, -err);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/14] neard: Add ability to parse 'State' field
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
  2013-02-07  8:13 ` [PATCH 01/14] neard: Adjust errors to latest API changes Szymon Janc
  2013-02-07  8:13 ` [PATCH 02/14] neard: Refactor message processing Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 04/14] neard: Move pairable check from check_adapter Szymon Janc
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

This contains hint for power state of remote device Bluetooth adapter.
---
 plugins/neard.c | 125 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 92 insertions(+), 33 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 7df4544..668c46f 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -55,6 +55,13 @@ static gboolean agent_register_postpone = FALSE;
 /* For NFC mimetype limits max OOB EIR size */
 #define NFC_OOB_EIR_MAX UINT8_MAX
 
+enum cps {
+	CPS_ACTIVE,
+	CPS_INACTIVE,
+	CPS_ACTIVATING,
+	CPS_UNKNOWN,
+};
+
 struct oob_params {
 	bdaddr_t address;
 	uint32_t class;
@@ -64,6 +71,7 @@ struct oob_params {
 	uint8_t *randomizer;
 	uint8_t *pin;
 	int pin_len;
+	enum cps power_state;
 };
 
 static void free_oob_params(struct oob_params *params)
@@ -451,14 +459,24 @@ static int process_nokia_com_bt(uint8_t *data, size_t size,
 	}
 }
 
+static enum cps process_state(const char *state)
+{
+	if (strcasecmp(state, "active") == 0)
+		return CPS_ACTIVE;
+
+	if (strcasecmp(state, "activating") == 0)
+		return CPS_ACTIVATING;
+
+	if (strcasecmp(state, "inactive") == 0)
+		return CPS_INACTIVE;
+
+	return CPS_UNKNOWN;
+}
+
 static int process_message(DBusMessage *msg, struct oob_params *remote)
 {
 	DBusMessageIter iter;
 	DBusMessageIter dict;
-	DBusMessageIter value;
-	DBusMessageIter entry;
-	const char *key;
-	int type;
 
 	dbus_message_iter_init(msg, &iter);
 
@@ -467,46 +485,87 @@ static int process_message(DBusMessage *msg, struct oob_params *remote)
 
 	dbus_message_iter_recurse(&iter, &dict);
 
-	type = dbus_message_iter_get_arg_type(&dict);
-	if (type != DBUS_TYPE_DICT_ENTRY) {
-		if (type == DBUS_TYPE_INVALID)
-			return -ENOENT;
+	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter value;
+		DBusMessageIter entry;
+		const char *key;
 
-		return -EINVAL;
-	}
+		dbus_message_iter_recurse(&dict, &entry);
 
-	dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			goto error;
 
-	if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
-		return -EINVAL;
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
 
-	dbus_message_iter_get_basic(&entry, &key);
-	dbus_message_iter_next(&entry);
+		dbus_message_iter_recurse(&entry, &value);
 
-	dbus_message_iter_recurse(&entry, &value);
+		if (strcasecmp(key, "EIR") == 0) {
+			DBusMessageIter array;
+			uint8_t *eir;
+			int size;
 
-	/* All keys have byte array type values */
-	if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_ARRAY)
-		return -EINVAL;
+			/* nokia.com:bt and EIR should not be passed together */
+			if (bacmp(&remote->address, BDADDR_ANY) != 0)
+				goto error;
+
+			if (dbus_message_iter_get_arg_type(&value) !=
+					DBUS_TYPE_ARRAY)
+				goto error;
 
-	if (strcasecmp(key, "EIR") == 0) {
-		DBusMessageIter array;
-		uint8_t *eir;
-		int size;
+			dbus_message_iter_recurse(&value, &array);
+			dbus_message_iter_get_fixed_array(&array, &eir, &size);
 
-		dbus_message_iter_recurse(&value, &array);
-		dbus_message_iter_get_fixed_array(&array, &eir, &size);
+			if (process_eir(eir, size, remote) < 0)
+				goto error;
+		} else if (strcasecmp(key, "nokia.com:bt") == 0) {
+			DBusMessageIter array;
+			uint8_t *data;
+			int size;
 
-		return process_eir(eir, size, remote);
-	} else if (strcasecmp(key, "nokia.com:bt") == 0) {
-		DBusMessageIter array;
-		uint8_t *data;
-		int size;
+			/* nokia.com:bt and EIR should not be passed together */
+			if (bacmp(&remote->address, BDADDR_ANY) != 0)
+				goto error;
 
-		dbus_message_iter_recurse(&value, &array);
-		dbus_message_iter_get_fixed_array(&array, &data, &size);
+			if (dbus_message_iter_get_arg_type(&value) !=
+					DBUS_TYPE_ARRAY)
+				goto error;
+
+			dbus_message_iter_recurse(&value, &array);
+			dbus_message_iter_get_fixed_array(&array, &data, &size);
+
+			if (process_nokia_com_bt(data, size, remote))
+				goto error;
+		} else if (strcasecmp(key, "State") == 0) {
+			DBusMessageIter array;
+			const char *state;
+
+			if (dbus_message_iter_get_arg_type(&value) !=
+					DBUS_TYPE_STRING)
+				goto error;
+
+			dbus_message_iter_recurse(&value, &array);
+			dbus_message_iter_get_basic(&value, &state);
+
+			remote->power_state = process_state(state);
+			if (remote->power_state == CPS_UNKNOWN)
+				goto error;
+		}
+
+		dbus_message_iter_next(&dict);
+	}
+
+	/* Check if 'State' was passed along with one of other fields */
+	if (remote->power_state != CPS_UNKNOWN
+			&& bacmp(&remote->address, BDADDR_ANY) == 0)
+		return -EINVAL;
+
+	return 0;
 
-		return process_nokia_com_bt(data, size, remote);
+error:
+	if (bacmp(&remote->address, BDADDR_ANY) != 0) {
+		free_oob_params(remote);
+		memset(remote, 0, sizeof(*remote));
 	}
 
 	return -EINVAL;
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/14] neard: Move pairable check from check_adapter
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (2 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 03/14] neard: Add ability to parse 'State' field Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 05/14] adapter: Add btd_adapter_get_powered function Szymon Janc
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

If device is already paired there is no need to fail with handover
if adapter is not pairable.
---
 plugins/neard.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 668c46f..131e8bd 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -579,9 +579,6 @@ static int check_adapter(struct btd_adapter *adapter)
 	if (btd_adapter_check_oob_handler(adapter))
 		return -EINPROGRESS;
 
-	if (!btd_adapter_get_pairable(adapter))
-		return -ENONET;
-
 	if (!btd_adapter_ssp_enabled(adapter))
 		return -ENOTSUP;
 
@@ -664,6 +661,12 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 		return error_reply(msg, -err);
 	}
 
+	if (!btd_adapter_get_pairable(adapter)) {
+		free_oob_params(&remote);
+
+		return error_reply(msg, ENONET);
+	}
+
 	store_params(adapter, device, &remote);
 
 	free_oob_params(&remote);
@@ -722,6 +725,12 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
 		return error_reply(msg, -err);
 	}
 
+	if (!btd_adapter_get_pairable(adapter)) {
+		free_oob_params(&remote);
+
+		return error_reply(msg, ENONET);
+	}
+
 	store_params(adapter, device, &remote);
 
 	if (!remote.hash) {
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/14] adapter: Add btd_adapter_get_powered function
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (3 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 04/14] neard: Move pairable check from check_adapter Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 06/14] neard: Check if adapter is powered in PushOOB Szymon Janc
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

---
 src/adapter.c | 8 ++++++++
 src/adapter.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 9ddd2fc..cd104a1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2764,6 +2764,14 @@ bool btd_adapter_get_pairable(struct btd_adapter *adapter)
 	return false;
 }
 
+bool btd_adapter_get_powered(struct btd_adapter *adapter)
+{
+	if (adapter->current_settings & MGMT_SETTING_POWERED)
+		return true;
+
+	return false;
+}
+
 uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
 {
 	return adapter->dev_class;
diff --git a/src/adapter.h b/src/adapter.h
index 2787631..2610479 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -86,6 +86,7 @@ struct btd_adapter *adapter_get_default(void);
 void adapter_foreach(adapter_cb func, gpointer user_data);
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter);
+bool btd_adapter_get_powered(struct btd_adapter *adapter);
 
 uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
 const char *btd_adapter_get_name(struct btd_adapter *adapter);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/14] neard: Check if adapter is powered in PushOOB
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (4 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 05/14] adapter: Add btd_adapter_get_powered function Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 07/14] adapter: Add btd_adapter_get_connectable function Szymon Janc
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

For PushOOB adapter needs to be powered as bluetoothd daemon is
expected to perform action on success.
---
 plugins/neard.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/plugins/neard.c b/plugins/neard.c
index 131e8bd..0418430 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -629,6 +629,9 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 	if (err < 0)
 		return error_reply(msg, -err);
 
+	if (!btd_adapter_get_powered(adapter))
+		return error_reply(msg, ENONET);
+
 	agent = adapter_get_agent(adapter);
 	if (!agent)
 		return error_reply(msg, ENONET);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/14] adapter: Add btd_adapter_get_connectable function
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (5 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 06/14] neard: Check if adapter is powered in PushOOB Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 08/14] neard: Add support for setting power state in RequestOOB reply Szymon Janc
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

---
 src/adapter.c | 8 ++++++++
 src/adapter.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index cd104a1..2338e60 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2772,6 +2772,14 @@ bool btd_adapter_get_powered(struct btd_adapter *adapter)
 	return false;
 }
 
+bool btd_adapter_get_connectable(struct btd_adapter *adapter)
+{
+	if (adapter->current_settings & MGMT_SETTING_CONNECTABLE)
+		return true;
+
+	return false;
+}
+
 uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
 {
 	return adapter->dev_class;
diff --git a/src/adapter.h b/src/adapter.h
index 2610479..8d23a64 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -87,6 +87,7 @@ void adapter_foreach(adapter_cb func, gpointer user_data);
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter);
 bool btd_adapter_get_powered(struct btd_adapter *adapter);
+bool btd_adapter_get_connectable(struct btd_adapter *adapter);
 
 uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
 const char *btd_adapter_get_name(struct btd_adapter *adapter);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/14] neard: Add support for setting power state in RequestOOB reply
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (6 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 07/14] adapter: Add btd_adapter_get_connectable function Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-07  8:13 ` [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard Szymon Janc
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

This allows neard to properly set Bluetooth carrier power state in
handover message.
---
 plugins/neard.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/plugins/neard.c b/plugins/neard.c
index 0418430..0bd376b 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -173,6 +173,19 @@ unregister:
 							AGENT_INTERFACE);
 }
 
+static void add_power_state(DBusMessageIter *dict, struct btd_adapter *adapter)
+{
+	const char *state;
+
+	if (btd_adapter_get_powered(adapter) &&
+			btd_adapter_get_connectable(adapter))
+		state = "active";
+	else
+		state = "inactive";
+
+	dict_append_entry(dict, "State", DBUS_TYPE_STRING, &state);
+}
+
 static DBusMessage *create_request_oob_reply(struct btd_adapter *adapter,
 						const uint8_t *hash,
 						const uint8_t *randomizer,
@@ -208,6 +221,8 @@ static DBusMessage *create_request_oob_reply(struct btd_adapter *adapter,
 
 	dict_append_array(&dict, "EIR", DBUS_TYPE_BYTE, &peir, len);
 
+	add_power_state(&dict, adapter);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (7 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 08/14] neard: Add support for setting power state in RequestOOB reply Szymon Janc
@ 2013-02-07  8:13 ` Szymon Janc
  2013-02-15  8:46   ` Johan Hedberg
  2013-02-07  8:14 ` [PATCH 10/14] neard: Restrict method calls only to neard process Szymon Janc
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

---
 plugins/neard.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 0bd376b..20cfe03 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_path = 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_path = 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_path);
+	neard_path = 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_path == 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_path == 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_path);
+	neard_path = 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_path != NULL) {
+		g_free(neard_path);
+		neard_path = 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_path != NULL)
 		unregister_agent();
 }
 
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/14] neard: Restrict method calls only to neard process
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (8 preceding siblings ...)
  2013-02-07  8:13 ` [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard Szymon Janc
@ 2013-02-07  8:14 ` Szymon Janc
  2013-02-07  8:14 ` [PATCH 11/14] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, 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 20cfe03..9351ac5 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_path == NULL ||
+			!g_str_equal(neard_path, 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_path == NULL ||
+			!g_str_equal(neard_path, 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_path == NULL ||
+			!g_str_equal(neard_path, dbus_message_get_sender(msg)))
+		return error_reply(msg, EPERM);
+
 	DBG("");
 
 	g_free(neard_path);
-- 
1.8.1.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/14] neard: Use bool instead of gboolean for agent_register_postpone
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (9 preceding siblings ...)
  2013-02-07  8:14 ` [PATCH 10/14] neard: Restrict method calls only to neard process Szymon Janc
@ 2013-02-07  8:14 ` Szymon Janc
  2013-02-07  8:14 ` [PATCH 12/14] neard: Update copyright information Szymon Janc
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, 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 9351ac5..b3ba2b0 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -50,7 +50,7 @@
 
 static guint watcher_id = 0;
 static char *neard_path = 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] 17+ messages in thread

* [PATCH 12/14] neard: Update copyright information
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (10 preceding siblings ...)
  2013-02-07  8:14 ` [PATCH 11/14] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
@ 2013-02-07  8:14 ` Szymon Janc
  2013-02-07  8:14 ` [PATCH 13/14] neard: Updated neard handover registration agent api calls Szymon Janc
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, Szymon Janc

---
 plugins/neard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index b3ba2b0..ab51057 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] 17+ messages in thread

* [PATCH 13/14] neard: Updated neard handover registration agent api calls.
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (11 preceding siblings ...)
  2013-02-07  8:14 ` [PATCH 12/14] neard: Update copyright information Szymon Janc
@ 2013-02-07  8:14 ` Szymon Janc
  2013-02-07  8:14 ` [PATCH 14/14] neard: Add fallback to legacy register if register failed Szymon Janc
  2013-02-11  9:52 ` [PATCH 00/14] neard plugin update Szymon Janc
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:14 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 ab51057..9a4a924 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_path);
 	neard_path = 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] 17+ messages in thread

* [PATCH 14/14] neard: Add fallback to legacy register if register failed
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (12 preceding siblings ...)
  2013-02-07  8:14 ` [PATCH 13/14] neard: Updated neard handover registration agent api calls Szymon Janc
@ 2013-02-07  8:14 ` Szymon Janc
  2013-02-11  9:52 ` [PATCH 00/14] neard plugin update Szymon Janc
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-07  8:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally, 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 9a4a924..97bf225 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_path = 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] 17+ messages in thread

* Re: [PATCH 00/14] neard plugin update
  2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
                   ` (13 preceding siblings ...)
  2013-02-07  8:14 ` [PATCH 14/14] neard: Add fallback to legacy register if register failed Szymon Janc
@ 2013-02-11  9:52 ` Szymon Janc
  14 siblings, 0 replies; 17+ messages in thread
From: Szymon Janc @ 2013-02-11  9:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

Hi All,

On Thursday 07 of February 2013 10:13:50 Janc Szymon wrote:
> This set adds some new features to neard plugin to match it with
> recent changes in neard daemon:
> - support for carrier power state hint (already merged)
> - update register API [with fallback to legacy support] (pending review)

Just to notify that register API changes were just merged into neard.git so all
code needed is now present in neard daemon.

> 
> Power state hint could be use to improve IOP e.g. delay or retry pairing when
> remote device in activating or incative state.
> 
> Other than that bugfixes, small improvements and some code refactoring to
> make it better prepared for future feature addition e.g. to perform more
> action on PushOOB than only pairing.
> 
> There are still some open points regarding how to properly map adapter
> state (powered/pairable/connectable) to carrier power state but those
> could be discussed separately later on.
> 
> Comments are welcome.
> 
> BR
> Szymon Janc
> 
> Ravi kumar Veeramally (1):
>   neard: Updated neard handover registration agent api calls.
> 
> Szymon Janc (13):
>   neard: Adjust errors to latest API changes
>   neard: Refactor message processing
>   neard: Add ability to parse 'State' field
>   neard: Move pairable check from check_adapter
>   adapter: Add btd_adapter_get_powered function
>   neard: Check if adapter is powered in PushOOB
>   adapter: Add btd_adapter_get_connectable function
>   neard: Add support for setting power state in RequestOOB reply
>   neard: Use path instead of boolean to track if registered to neard
>   neard: Restrict method calls only to neard process
>   neard: Use bool instead of gboolean for agent_register_postpone
>   neard: Update copyright information
>   neard: Add fallback to legacy register if register failed
> 
>  plugins/neard.c | 562 ++++++++++++++++++++++++++++++++++----------------------
>  src/adapter.c   |  16 ++
>  src/adapter.h   |   2 +
>  3 files changed, 361 insertions(+), 219 deletions(-)
> 
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard
  2013-02-07  8:13 ` [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard Szymon Janc
@ 2013-02-15  8:46   ` Johan Hedberg
  0 siblings, 0 replies; 17+ messages in thread
From: Johan Hedberg @ 2013-02-15  8:46 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth, Ravi kumar Veeramally

Hi Szymon,

On Thu, Feb 07, 2013, Szymon Janc wrote:
> ---
>  plugins/neard.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)

Patches 1-8 have been applied but this one had something that imo needs
fixing:

> -static gboolean agent_registered = FALSE;
> +static char *neard_path = 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_path = g_strdup(dbus_message_get_sender(reply));

If you're going to store the neard D-Bus name in this variable then
please don't call it "path". That's just confusing. Use neard_name or
neard_service instead.

Johan

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-02-15  8:46 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-07  8:13 [PATCH 00/14] neard plugin update Szymon Janc
2013-02-07  8:13 ` [PATCH 01/14] neard: Adjust errors to latest API changes Szymon Janc
2013-02-07  8:13 ` [PATCH 02/14] neard: Refactor message processing Szymon Janc
2013-02-07  8:13 ` [PATCH 03/14] neard: Add ability to parse 'State' field Szymon Janc
2013-02-07  8:13 ` [PATCH 04/14] neard: Move pairable check from check_adapter Szymon Janc
2013-02-07  8:13 ` [PATCH 05/14] adapter: Add btd_adapter_get_powered function Szymon Janc
2013-02-07  8:13 ` [PATCH 06/14] neard: Check if adapter is powered in PushOOB Szymon Janc
2013-02-07  8:13 ` [PATCH 07/14] adapter: Add btd_adapter_get_connectable function Szymon Janc
2013-02-07  8:13 ` [PATCH 08/14] neard: Add support for setting power state in RequestOOB reply Szymon Janc
2013-02-07  8:13 ` [PATCH 09/14] neard: Use path instead of boolean to track if registered to neard Szymon Janc
2013-02-15  8:46   ` Johan Hedberg
2013-02-07  8:14 ` [PATCH 10/14] neard: Restrict method calls only to neard process Szymon Janc
2013-02-07  8:14 ` [PATCH 11/14] neard: Use bool instead of gboolean for agent_register_postpone Szymon Janc
2013-02-07  8:14 ` [PATCH 12/14] neard: Update copyright information Szymon Janc
2013-02-07  8:14 ` [PATCH 13/14] neard: Updated neard handover registration agent api calls Szymon Janc
2013-02-07  8:14 ` [PATCH 14/14] neard: Add fallback to legacy register if register failed Szymon Janc
2013-02-11  9:52 ` [PATCH 00/14] neard plugin update Szymon Janc

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.