Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v2 4/5] device: Add btd_device_get_storage_path()
From: Frédéric Danis @ 2012-12-15  8:59 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355561991-7906-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/device.c |   15 +++++++++++++++
 src/device.h |    2 ++
 2 files changed, 17 insertions(+)

diff --git a/src/device.c b/src/device.c
index d6a6f04..0bc8a09 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2049,6 +2049,21 @@ struct btd_device *device_create(struct btd_adapter *adapter,
 	return btd_device_ref(device);
 }
 
+char *btd_device_get_storage_path(struct btd_device *device,
+				const char *filename)
+{
+	char srcaddr[18], dstaddr[18];
+
+	ba2str(adapter_get_address(device->adapter), srcaddr);
+	ba2str(&device->bdaddr, dstaddr);
+
+	if (!filename)
+		return g_strdup_printf(STORAGEDIR "/%s/%s", srcaddr, dstaddr);
+
+	return g_strdup_printf(STORAGEDIR "/%s/%s/%s", srcaddr, dstaddr,
+							filename);
+}
+
 void device_set_name(struct btd_device *device, const char *name)
 {
 	if (strncmp(name, device->name, MAX_NAME_LENGTH) == 0)
diff --git a/src/device.h b/src/device.h
index 8534117..7707bce 100644
--- a/src/device.h
+++ b/src/device.h
@@ -30,6 +30,8 @@ struct btd_device *device_create(struct btd_adapter *adapter,
 				const char *address, uint8_t bdaddr_type);
 struct btd_device *device_create_from_storage(struct btd_adapter *adapter,
 				const char *address, GKeyFile *key_file);
+char *btd_device_get_storage_path(struct btd_device *device,
+				const char *filename);
 
 void device_set_name(struct btd_device *device, const char *name);
 void device_get_name(struct btd_device *device, char *name, size_t len);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 5/5] attrib-server: Read/write CCC info from new storage
From: Frédéric Danis @ 2012-12-15  8:59 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355561991-7906-1-git-send-email-frederic.danis@linux.intel.com>

Remove no more used storage functions.
---
 src/attrib-server.c |   79 +++++++++++++++++++++++++++++++++++++---------
 src/storage.c       |   87 ---------------------------------------------------
 src/storage.h       |    6 ----
 3 files changed, 64 insertions(+), 108 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 8dc0d6a..e3715e8 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <glib.h>
+#include <sys/file.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -746,6 +747,36 @@ static uint16_t find_by_type(struct gatt_channel *channel, uint16_t start,
 	return len;
 }
 
+static int read_device_ccc(struct btd_device *device, uint16_t handle,
+				uint16_t *value)
+{
+	char *filename;
+	GKeyFile *key_file;
+	char group[6];
+	char *str;
+	unsigned int config;
+	int err = 0;
+
+	filename = btd_device_get_storage_path(device, "ccc");
+
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+	sprintf(group, "%hu", handle);
+
+	str = g_key_file_get_string(key_file, group, "Value", NULL);
+	if (!str || sscanf(str, "%04X", &config) != 1)
+		err = -ENOENT;
+	else
+		*value = config;
+
+	g_free(str);
+	g_free(filename);
+	g_key_file_free(key_file);
+
+	return err;
+}
+
 static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
 						uint8_t *pdu, size_t len)
 {
@@ -753,7 +784,6 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
 	uint8_t status;
 	GList *l;
 	uint16_t cccval;
-	uint8_t bdaddr_type;
 	guint h = handle;
 
 	l = g_list_find_custom(channel->server->database,
@@ -764,11 +794,8 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
 
 	a = l->data;
 
-	bdaddr_type = device_get_addr_type(channel->device);
-
 	if (bt_uuid_cmp(&ccc_uuid, &a->uuid) == 0 &&
-		read_device_ccc(&channel->src, &channel->dst, bdaddr_type,
-							handle, &cccval) == 0) {
+		read_device_ccc(channel->device, handle, &cccval) == 0) {
 		uint8_t config[2];
 
 		att_put_u16(cccval, config);
@@ -794,7 +821,6 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
 	uint8_t status;
 	GList *l;
 	uint16_t cccval;
-	uint8_t bdaddr_type;
 	guint h = handle;
 
 	l = g_list_find_custom(channel->server->database,
@@ -809,11 +835,8 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
 		return enc_error_resp(ATT_OP_READ_BLOB_REQ, handle,
 					ATT_ECODE_INVALID_OFFSET, pdu, len);
 
-	bdaddr_type = device_get_addr_type(channel->device);
-
 	if (bt_uuid_cmp(&ccc_uuid, &a->uuid) == 0 &&
-		read_device_ccc(&channel->src, &channel->dst, bdaddr_type,
-							handle, &cccval) == 0) {
+		read_device_ccc(channel->device, handle, &cccval) == 0) {
 		uint8_t config[2];
 
 		att_put_u16(cccval, config);
@@ -869,10 +892,31 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle,
 		}
 	} else {
 		uint16_t cccval = att_get_u16(value);
-		uint8_t bdaddr_type = device_get_addr_type(channel->device);
+		char *filename;
+		GKeyFile *key_file;
+		char group[6], value[5];
+		char *data;
+		gsize length = 0;
+
+		filename = btd_device_get_storage_path(channel->device, "ccc");
+
+		key_file = g_key_file_new();
+		g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+		sprintf(group, "%hu", handle);
+		sprintf(value, "%hhX", cccval);
+		g_key_file_set_string(key_file, group, "Value", value);
+
+		data = g_key_file_to_data(key_file, &length, NULL);
+		if (length > 0) {
+			create_file(filename,
+					S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+			g_file_set_contents(filename, data, length, NULL);
+		}
 
-		write_device_ccc(&channel->src, &channel->dst, bdaddr_type,
-								handle, cccval);
+		g_free(data);
+		g_free(filename);
+		g_key_file_free(key_file);
 	}
 
 	return enc_write_resp(pdu, len);
@@ -1089,8 +1133,13 @@ guint attrib_channel_attach(GAttrib *attrib)
 	ba2str(&channel->dst, addr);
 
 	device = adapter_find_device(server->adapter, addr);
-	if (device == NULL || device_is_bonded(device) == FALSE)
-		delete_device_ccc(&channel->src, &channel->dst);
+	if (device == NULL || device_is_bonded(device) == FALSE) {
+		char *filename;
+
+		filename = btd_device_get_storage_path(channel->device, "ccc");
+		unlink(filename);
+		g_free(filename);
+	}
 
 	if (cid != ATT_CID) {
 		channel->le = FALSE;
diff --git a/src/storage.c b/src/storage.c
index 02ac1f3..38e5897 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -272,90 +272,3 @@ int read_device_pairable(const bdaddr_t *bdaddr, gboolean *mode)
 
 	return 0;
 }
-
-static void filter_keys(char *key, char *value, void *data)
-{
-	struct match *match = data;
-
-	if (strncasecmp(key, match->pattern, strlen(match->pattern)) == 0)
-		match->keys = g_slist_append(match->keys, g_strdup(key));
-}
-
-static void delete_by_pattern(const char *filename, char *pattern)
-{
-	struct match match;
-	GSList *l;
-	int err;
-
-	memset(&match, 0, sizeof(match));
-	match.pattern = pattern;
-
-	err = textfile_foreach(filename, filter_keys, &match);
-	if (err < 0)
-		goto done;
-
-	for (l = match.keys; l; l = l->next) {
-		const char *key = l->data;
-		textfile_del(filename, key);
-	}
-
-done:
-	g_slist_free_full(match.keys, g_free);
-}
-
-int read_device_ccc(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t bdaddr_type, uint16_t handle,
-					uint16_t *value)
-{
-	char filename[PATH_MAX + 1], addr[18], key[25];
-	char *str;
-	unsigned int config;
-	int err = 0;
-
-	create_filename(filename, PATH_MAX, local, "ccc");
-
-	ba2str(peer, addr);
-	snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
-
-	str = textfile_caseget(filename, key);
-	if (str == NULL)
-		return -ENOENT;
-
-	if (sscanf(str, "%04X", &config) != 1)
-		err = -ENOENT;
-	else
-		*value = config;
-
-	free(str);
-
-	return err;
-}
-
-int write_device_ccc(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t bdaddr_type, uint16_t handle,
-					uint16_t value)
-{
-	char filename[PATH_MAX + 1], addr[18], key[25], config[5];
-
-	create_filename(filename, PATH_MAX, local, "ccc");
-
-	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-	ba2str(peer, addr);
-	snprintf(key, sizeof(key), "%17s#%hhu#%04X", addr, bdaddr_type, handle);
-
-	snprintf(config, sizeof(config), "%04X", value);
-
-	return textfile_put(filename, key, config);
-}
-
-void delete_device_ccc(const bdaddr_t *local, const bdaddr_t *peer)
-{
-	char filename[PATH_MAX + 1], addr[18];
-
-	ba2str(peer, addr);
-
-	/* Deleting all CCC values of a given address */
-	create_filename(filename, PATH_MAX, local, "ccc");
-	delete_by_pattern(filename, addr);
-}
diff --git a/src/storage.h b/src/storage.h
index 682523a..cc7f930 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -35,9 +35,3 @@ ssize_t read_pin_code(const bdaddr_t *local, const bdaddr_t *peer, char *pin);
 sdp_record_t *record_from_string(const gchar *str);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
 int read_device_pairable(const bdaddr_t *local, gboolean *mode);
-int read_device_ccc(const bdaddr_t *local, const bdaddr_t *peer,
-			uint8_t bdaddr_type, uint16_t handle, uint16_t *value);
-int write_device_ccc(const bdaddr_t *local, const bdaddr_t *peer,
-					uint8_t bdaddr_type, uint16_t handle,
-					uint16_t value);
-void delete_device_ccc(const bdaddr_t *local, const bdaddr_t *peer);
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH BlueZ 1/2] core: Fix leftover signal for UUIDs property
From: Johan Hedberg @ 2012-12-16 11:25 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth
In-Reply-To: <1355494410-24627-1-git-send-email-lucas.demarchi@profusion.mobi>

Hi Lucas,

On Fri, Dec 14, 2012, Lucas De Marchi wrote:
> ---
>  src/device.c | 28 ++++++++--------------------
>  1 file changed, 8 insertions(+), 20 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH BlueZ 1/4] obex-client: Port MAP module to use D-Bus properties interface
From: Johan Hedberg @ 2012-12-16 11:28 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355520720-11731-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Fri, Dec 14, 2012, Luiz Augusto von Dentz wrote:
> ---
>  obexd/client/map.c | 315 ++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 178 insertions(+), 137 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH v2 1/5] device : Add EndGroupHandle key in attributes storage
From: Johan Hedberg @ 2012-12-16 11:33 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1355561991-7906-1-git-send-email-frederic.danis@linux.intel.com>

Hi Frédéric,

On Sat, Dec 15, 2012, Frédéric Danis wrote:
> End group handle should also be converted/saved for each
> group in device's attributes file.
> ---
>  doc/settings-storage.txt |    8 +++++---
>  src/adapter.c            |    8 +++++---
>  src/device.c             |   10 ++++++++++
>  3 files changed, 20 insertions(+), 6 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* PSCAN and ISCAN flags in hciconfig
From: Kevin Wilson @ 2012-12-16 17:58 UTC (permalink / raw)
  To: linux-bluetooth

Hello,
I have 2 PC with Linux which once used to recognize each other by
"hcitool scan" and  to create
a PAND-based connection.

Now I fail to see each other with "hcitool scan".
My question is :
I see now only the PSCAN flag when running "hciconfig" on both of then.
Is the ISCAN flag (inquiry) mandatory so that a device will be discoverable ?

following is full output on one of them:

hci0:	Type: BR/EDR  Bus: USB
	BD Address: 00:23:4E:E5:70:3A  ACL MTU: 1021:8  SCO MTU: 64:1
	UP RUNNING PSCAN
	RX bytes:1857 acl:0 sco:0 events:65 errors:0
	TX bytes:762 acl:0 sco:0 commands:57 errors:0
	Features: 0xff 0xff 0x8f 0xfe 0x9b 0xff 0x79 0x83
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
	Link policy: RSWITCH HOLD SNIFF PARK
	Link mode: SLAVE ACCEPT
	Name: 'n-0'
	Class: 0x400100
	Service Classes: Telephony
	Device Class: Computer, Uncategorized
	HCI Version: 2.1 (0x4)  Revision: 0x5259
	LMP Version: 2.1 (0x4)  Subversion: 0x424c
	Manufacturer: Broadcom Corporation (15)

rgs,
Kevin

^ permalink raw reply

* Re: PSCAN and ISCAN flags in hciconfig
From: Frederic Danis @ 2012-12-16 21:10 UTC (permalink / raw)
  To: Kevin Wilson; +Cc: linux-bluetooth
In-Reply-To: <CAGXs5wWXOLpn1O77RMiQ-Cvp3vXEKm3KCbRvz07dN6jJwFoe-A@mail.gmail.com>

On 16/12/2012 18:58, Kevin Wilson wrote:
> Hello,
> I have 2 PC with Linux which once used to recognize each other by
> "hcitool scan" and  to create
> a PAND-based connection.
>
> Now I fail to see each other with "hcitool scan".
> My question is :
> I see now only the PSCAN flag when running "hciconfig" on both of then.
> Is the ISCAN flag (inquiry) mandatory so that a device will be discoverable ?

Yes, ISCAN means that your adapter will respond to inquiry scan, so it 
will be discoverable.

Regards

Fred

-- 
Frederic Danis                            Open Source Technology Center
frederic.danis@intel.com                              Intel Corporation


^ permalink raw reply

* Re: [PATCH v5 00/16] mSBC tests
From: Siarhei Siamashka @ 2012-12-17  0:33 UTC (permalink / raw)
  To: Frédéric Dalleau; +Cc: linux-bluetooth
In-Reply-To: <1355497417-10357-1-git-send-email-frederic.dalleau@linux.intel.com>

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

On Fri, 14 Dec 2012 16:03:21 +0100
Frédéric Dalleau  <frederic.dalleau@linux.intel.com> wrote:

> Hi,
> 
> v5 shoudl fix the few remaining issues.  I could test neon and armv6
> and raised verbosity of commit messages.

Thanks for the update. The verbose commit messages make a really big
difference.

> However, before releasing a new version of the library, I believe we should
> write some sort of automated testing and test against another implementation.
> Siarhei shared a script some time ago, it could be a good start.
> But where could we store some decent audio materials? Should we use generators
> like sine wave, or just record ambient sound??

It is a good idea to make use of autotools test framework (a simple
one, not dejagnu based):
    http://www.gnu.org/software/automake/manual/html_node/Tests.html

The tests could generate some deterministic pseudorandom data and
encode it with the sbc encoder.

Testing for potential overflows and the other bugs in the code is quite
effective with the plain uniformly distributed random data. The
checksums (CRC32 or some cryptographic hashes) can be calculated for
the encoded data and compared with the reference values. This test
ensures that the code works exactly as it used to work before (no
regressions, no improvements).

Additionally some sine waves (or more complex signals consisting
of multiple pseudorandom sine waves) can be used for one more test,
which could check the errors accumulated for the encoding/decoding
roundtrip.

And finally, an integrated benchmark would be also useful in this
sbc test framework. Compressing/decompressing white noise may not
provide relevant results, but maybe some sine waves can be selected
which represent more "realistic" audio data. Or one can be compared
to each other, and if there are no significant differences in
performance for different data, then it's easier for us.

An example of an autotools based test framework employing pseudorandom
data generation and checksums verification can be found in the pixman
library:
    http://cgit.freedesktop.org/pixman
Coincidentally, I looked into pseudorandom number generators recently
and found this one to be quite good:
    http://burtleburtle.net/bob/rand/smallprng.html

As for comparing with the reference sbc encoder/decoder (win32
binary), I used to have one more script. It is attached.

-- 
Best regards,
Siarhei Siamashka

[-- Attachment #2: sbc_encode_test.rb --]
[-- Type: application/x-ruby, Size: 3067 bytes --]

^ permalink raw reply

* Re: PSCAN and ISCAN flags in hciconfig
From: Kevin Wilson @ 2012-12-17  3:37 UTC (permalink / raw)
  To: Frederic Danis; +Cc: linux-bluetooth
In-Reply-To: <50CE38D1.8010303@linux.intel.com>

Hi,
Thanks Frederic.
Ok, so I rebooted the machine and still
hciconfig shows:
UP RUNNING PSCAN
and also after 'hciconfig hci0 reset"
It stays "UP RUNNING PSCAN".

So what sould I do to make the ISCAN flag set ?

 systemctl status bluetooth.service
shows that it is "active (running)"

rgs,
Kevin


On Sun, Dec 16, 2012 at 11:10 PM, Frederic Danis
<frederic.danis@linux.intel.com> wrote:
> On 16/12/2012 18:58, Kevin Wilson wrote:
>>
>> Hello,
>> I have 2 PC with Linux which once used to recognize each other by
>> "hcitool scan" and  to create
>> a PAND-based connection.
>>
>> Now I fail to see each other with "hcitool scan".
>> My question is :
>> I see now only the PSCAN flag when running "hciconfig" on both of then.
>> Is the ISCAN flag (inquiry) mandatory so that a device will be
>> discoverable ?
>
>
> Yes, ISCAN means that your adapter will respond to inquiry scan, so it will
> be discoverable.
>
> Regards
>
> Fred
>
> --
> Frederic Danis                            Open Source Technology Center
> frederic.danis@intel.com                              Intel Corporation
>

^ permalink raw reply

* Re: PSCAN and ISCAN flags in hciconfig
From: Andrei Emeltchenko @ 2012-12-17  9:02 UTC (permalink / raw)
  To: Kevin Wilson; +Cc: Frederic Danis, linux-bluetooth
In-Reply-To: <CAGXs5wXfwHME+XpVUq4rMmK_u=Sw2qG_snCC6iLEbKBYeZ0VTA@mail.gmail.com>

Hi Kevin

On Mon, Dec 17, 2012 at 05:37:09AM +0200, Kevin Wilson wrote:
> Hi,
> Thanks Frederic.
> Ok, so I rebooted the machine and still
> hciconfig shows:
> UP RUNNING PSCAN
> and also after 'hciconfig hci0 reset"
> It stays "UP RUNNING PSCAN".
> 
> So what sould I do to make the ISCAN flag set ?

hciconfig hciX piscan

Best regards 
Andrei Emeltchenko 

> 
>  systemctl status bluetooth.service
> shows that it is "active (running)"
> 
> rgs,
> Kevin
> 
> 
> On Sun, Dec 16, 2012 at 11:10 PM, Frederic Danis
> <frederic.danis@linux.intel.com> wrote:
> > On 16/12/2012 18:58, Kevin Wilson wrote:
> >>
> >> Hello,
> >> I have 2 PC with Linux which once used to recognize each other by
> >> "hcitool scan" and  to create
> >> a PAND-based connection.
> >>
> >> Now I fail to see each other with "hcitool scan".
> >> My question is :
> >> I see now only the PSCAN flag when running "hciconfig" on both of then.
> >> Is the ISCAN flag (inquiry) mandatory so that a device will be
> >> discoverable ?
> >
> >
> > Yes, ISCAN means that your adapter will respond to inquiry scan, so it will
> > be discoverable.
> >
> > Regards
> >
> > Fred
> >
> > --
> > Frederic Danis                            Open Source Technology Center
> > frederic.danis@intel.com                              Intel Corporation
> >
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [PATCH BlueZ] gdbus: Fix crash error when calling g_dbus_remove_all_watches
From: Tomasz Bursztyka @ 2012-12-17 11:33 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <20121128122318.GA30710@x220.ger.corp.intel.com>


Hi Johan,

this bug never hasn't hit anyone since the function 
g_dbus_remove_all_watches() is not used anywhere (but in my project)

I will resend the patch with the backtrace.

Tomasz
> It seems this patch never got applied. Is it so that no-one else has
> seen the issue. Could someone (through basic static analysis) confirm if
> the patch is correct? It'd be nice if we could also have a back trace of
> the crash in the commit message.
>
> Johan
>


^ permalink raw reply

* [PATCH BlueZ 1/5] obexd: Port session interface to use D-Bus Properties
From: Luiz Augusto von Dentz @ 2012-12-17 11:50 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 doc/obexd-api.txt   | 12 ++++--------
 obexd/src/manager.c | 50 ++++++++++++++++++--------------------------------
 2 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/doc/obexd-api.txt b/doc/obexd-api.txt
index 680febe..53e61f5 100644
--- a/doc/obexd-api.txt
+++ b/doc/obexd-api.txt
@@ -74,14 +74,10 @@ Service		org.bluez.obex
 Interface	org.bluez.obex.Session
 Object path	/session{0, 1, 2, ...}
 
-Methods
-		dict GetProperties()
-
-
-Signals		TBD
+Properties	string Target [readonly]
 
+			Target UUID
 
-Properties
-		string Address [readonly]
+		string Root [readonly]
 
-			Bluetooth device address or USB
+			Root path
diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index 02dc999..85aa965 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
@@ -255,42 +255,29 @@ static char *target2str(const uint8_t *t)
 				t[8], t[9], t[10], t[11], t[12], t[13], t[14], t[15]);
 }
 
-static DBusMessage *get_properties(DBusConnection *conn,
-				DBusMessage *msg, void *data)
+static gboolean get_target(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
 {
 	struct obex_session *os = data;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	DBusMessageIter dict;
 	char *uuid;
-	const char *root;
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
 
-	dbus_message_iter_init_append(reply, &iter);
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
-
-	/* Target */
 	uuid = target2str(os->service->target);
-	dbus_message_iter_append_dict_entry(&dict, "Target",
-					DBUS_TYPE_STRING, &uuid);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid);
 	g_free(uuid);
 
-	/* Root folder */
-	root = obex_option_root_folder();
-	dbus_message_iter_append_dict_entry(&dict, "Root",
-					DBUS_TYPE_STRING, &root);
+	return TRUE;
+}
 
-	/* FIXME: Added Remote Address or USB */
+static gboolean get_root(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct obex_session *os = data;
+	const char *root;
 
-	dbus_message_iter_close_container(&iter, &dict);
+	root = obex_option_root_folder();
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &root);
 
-	return reply;
+	return TRUE;
 }
 
 static DBusMessage *transfer_cancel(DBusConnection *connection,
@@ -339,10 +326,9 @@ static const GDBusSignalTable transfer_signals[] = {
 	{ }
 };
 
-static const GDBusMethodTable session_methods[] = {
-	{ GDBUS_METHOD("GetProperties",
-				NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-				get_properties) },
+static const GDBusPropertyTable session_properties[] = {
+	{ "Target", "s", get_target },
+	{ "Root", "s", get_root },
 	{ }
 };
 
@@ -610,8 +596,8 @@ void manager_register_session(struct obex_session *os)
 
 	if (!g_dbus_register_interface(connection, path,
 				SESSION_INTERFACE,
-				session_methods, NULL,
-				NULL, os, NULL)) {
+				NULL, NULL,
+				session_properties, os, NULL)) {
 		error("Cannot register Session interface.");
 		goto done;
 	}
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 2/5] obexd: Enable ObjectManager
From: Luiz Augusto von Dentz @ 2012-12-17 11:50 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355745007-1493-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 obexd/src/manager.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index 85aa965..034f6ab 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
@@ -350,6 +350,8 @@ gboolean manager_init(void)
 		return FALSE;
 	}
 
+	g_dbus_attach_object_manager(connection);
+
 	return g_dbus_register_interface(connection, OBEX_MANAGER_PATH,
 					OBEX_MANAGER_INTERFACE,
 					manager_methods, manager_signals, NULL,
@@ -368,6 +370,8 @@ void manager_cleanup(void)
 	if (agent)
 		agent_free(agent);
 
+	g_dbus_detach_object_manager(connection);
+
 	dbus_connection_unref(connection);
 }
 
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 3/5] obexd: Remove SessionCreated and SessionRemoved signals
From: Luiz Augusto von Dentz @ 2012-12-17 11:50 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355745007-1493-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

With ObjectManager these signals no longer are necessary.
---
 doc/obexd-api.txt   | 12 +-----------
 obexd/src/manager.c | 12 ------------
 2 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/doc/obexd-api.txt b/doc/obexd-api.txt
index 53e61f5..822157d 100644
--- a/doc/obexd-api.txt
+++ b/doc/obexd-api.txt
@@ -29,17 +29,7 @@ Methods
 
 			Possible errors: org.bluez.obex.Error.DoesNotExist
 
-Signals		SessionCreated(object session)
-
-			Signal sent when OBEX connection has been accepted.
-			(FTP only)
-
-		SessionRemoved(object session)
-
-			Sent when the transport is disconnected
-			(FTP only)
-
-		TransferStarted(object transfer)
+Signals		TransferStarted(object transfer)
 
 			Signal sent when an object push operation starts.
 			(OPP only)
diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index 034f6ab..c585aa1 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
@@ -310,8 +310,6 @@ static const GDBusSignalTable manager_signals[] = {
 	{ GDBUS_SIGNAL("TransferStarted", GDBUS_ARGS({ "transfer", "o"})) },
 	{ GDBUS_SIGNAL("TransferCompleted", GDBUS_ARGS({ "transfer", "o" },
 							{ "success", "b" })) },
-	{ GDBUS_SIGNAL("SessionCreated", GDBUS_ARGS({ "session", "o" })) },
-	{ GDBUS_SIGNAL("SessionRemoved", GDBUS_ARGS({ "session", "o" })) },
 	{ }
 };
 
@@ -606,11 +604,6 @@ void manager_register_session(struct obex_session *os)
 		goto done;
 	}
 
-	g_dbus_emit_signal(connection, OBEX_MANAGER_PATH,
-			OBEX_MANAGER_INTERFACE, "SessionCreated",
-			DBUS_TYPE_OBJECT_PATH, &path,
-			DBUS_TYPE_INVALID);
-
 done:
 	g_free(path);
 }
@@ -619,11 +612,6 @@ void manager_unregister_session(struct obex_session *os)
 {
 	char *path = g_strdup_printf("/session%u", GPOINTER_TO_UINT(os));
 
-	g_dbus_emit_signal(connection, OBEX_MANAGER_PATH,
-			OBEX_MANAGER_INTERFACE, "SessionRemoved",
-			DBUS_TYPE_OBJECT_PATH, &path,
-			DBUS_TYPE_INVALID);
-
 	g_dbus_unregister_interface(connection, path,
 				SESSION_INTERFACE);
 
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 4/5] obex-client: Enable ObjectManager
From: Luiz Augusto von Dentz @ 2012-12-17 11:50 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355745007-1493-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 obexd/client/manager.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/obexd/client/manager.c b/obexd/client/manager.c
index 7a7c33f..4929383 100644
--- a/obexd/client/manager.c
+++ b/obexd/client/manager.c
@@ -269,6 +269,8 @@ int manager_init(void)
 		return -1;
 	}
 
+	g_dbus_attach_object_manager(conn);
+
 	if (g_dbus_register_interface(conn, CLIENT_PATH, CLIENT_INTERFACE,
 						client_methods, NULL, NULL,
 							NULL, NULL) == FALSE) {
@@ -299,5 +301,6 @@ void manager_exit(void)
 		module->exit();
 
 	g_dbus_unregister_interface(conn, CLIENT_PATH, CLIENT_INTERFACE);
+	g_dbus_detach_object_manager(conn);
 	dbus_connection_unref(conn);
 }
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 5/5] TODO: Mark Convert obexd & obex-client to ObjectManager/Properties as done
From: Luiz Augusto von Dentz @ 2012-12-17 11:50 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355745007-1493-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 TODO | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO
index d9a708b..5a70e40 100644
--- a/TODO
+++ b/TODO
@@ -60,8 +60,6 @@ BlueZ 5
 Priority/Complexity omitted as all items are required before 5.0 is
 released.
 
-- Convert obexd & obex-client to ObjectManager/Properties
-
 - [pending] Convert storage to user per-remote device directories and
   ini-file format
 
@@ -87,6 +85,8 @@ Completed items:
 
 - Convert obexd to use org.bluez.Profile
 
+- Convert obexd & obex-client to ObjectManager/Properties
+
 - Remove org.bluez.Service interface (it has become unnecessary thanks
   to org.bluez.Profile). obexd needs to be converted to use the new
   interface first.
-- 
1.7.11.7


^ permalink raw reply related

* Re: [PATCH BlueZ 1/5] obexd: Port session interface to use D-Bus Properties
From: Johan Hedberg @ 2012-12-17 12:11 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355745007-1493-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, Dec 17, 2012, Luiz Augusto von Dentz wrote:
> ---
>  doc/obexd-api.txt   | 12 ++++--------
>  obexd/src/manager.c | 50 ++++++++++++++++++--------------------------------
>  2 files changed, 22 insertions(+), 40 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH BlueZ 1/2] obex-client: Make use of g_dbus_get_properties to get transfer properties
From: Luiz Augusto von Dentz @ 2012-12-17 13:25 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

In addition fix the reply generated by obc_transfer_create_dbus_reply to
not use a structure container instead use object, dict 'oa{sv}' as
indicated in the documentation.
---
 obexd/client/transfer.c | 46 ++++------------------------------------------
 1 file changed, 4 insertions(+), 42 deletions(-)

diff --git a/obexd/client/transfer.c b/obexd/client/transfer.c
index 29d61f3..fc3f87b 100644
--- a/obexd/client/transfer.c
+++ b/obexd/client/transfer.c
@@ -97,47 +97,6 @@ static void obc_transfer_append_dbus_properties(struct obc_transfer *transfer,
 						&transfer->progress);
 }
 
-static DBusMessage *obc_transfer_get_properties(DBusConnection *connection,
-					DBusMessage *message, void *user_data)
-{
-	struct obc_transfer *transfer = user_data;
-	DBusMessage *reply;
-	DBusMessageIter iter, dict;
-
-	reply = dbus_message_new_method_return(message);
-	if (!reply)
-		return NULL;
-
-	dbus_message_iter_init_append(reply, &iter);
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-						OBC_PROPERTIES_ARRAY_SIGNATURE,
-						&dict);
-
-	obc_transfer_append_dbus_properties(transfer, &dict);
-
-	dbus_message_iter_close_container(&iter, &dict);
-
-	return reply;
-}
-
-static void obc_transfer_append_dbus_data(struct obc_transfer *transfer,
-							DBusMessageIter *iter)
-{
-	const char *path = transfer->path;
-	DBusMessageIter entry, dict;
-
-	dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
-	dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH, &path);
-	dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
-						OBC_PROPERTIES_ARRAY_SIGNATURE,
-						&dict);
-
-	obc_transfer_append_dbus_properties(transfer, &dict);
-
-	dbus_message_iter_close_container(&entry, &dict);
-	dbus_message_iter_close_container(iter, &entry);
-}
-
 DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
 							DBusMessage *message)
 {
@@ -149,7 +108,10 @@ DBusMessage *obc_transfer_create_dbus_reply(struct obc_transfer *transfer,
 		return NULL;
 
 	dbus_message_iter_init_append(reply, &iter);
-	obc_transfer_append_dbus_data(transfer, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
+							&transfer->path);
+	g_dbus_get_properties(transfer->conn, transfer->path,
+						TRANSFER_INTERFACE, &iter);
 
 	return reply;
 }
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 2/2] test: Fix pbap-client to handle PullAll reply properly
From: Luiz Augusto von Dentz @ 2012-12-17 13:25 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1355750727-23222-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

PullAll reply consist in 2 parameters, the transfer object followed by
its properties not a structure containing both.
---
 test/pbap-client | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/test/pbap-client b/test/pbap-client
index fbe930c..7be8bad 100755
--- a/test/pbap-client
+++ b/test/pbap-client
@@ -33,8 +33,7 @@ class PbapClient:
 				signal_name="Error",
 				path_keyword="path")
 
-	def register(self, reply, transfer):
-		(path, properties) = reply
+	def register(self, path, properties, transfer):
 		transfer.path = path
 		transfer.filename = properties["Filename"]
 		self.props[path] = transfer
@@ -73,15 +72,15 @@ class PbapClient:
 	def pull(self, vcard, params, func):
 		req = Transfer(func)
 		self.pbap.Pull(vcard, "", params,
-				reply_handler=lambda r: self.register(r, req),
-				error_handler=self.error)
+			reply_handler=lambda o, p: self.register(o, p, req),
+			error_handler=self.error)
 		self.transfers += 1
 
 	def pull_all(self, params, func):
 		req = Transfer(func)
 		self.pbap.PullAll("", params,
-				reply_handler=lambda r: self.register(r, req),
-				error_handler=self.error)
+			reply_handler=lambda o, p: self.register(o, p, req),
+			error_handler=self.error)
 		self.transfers += 1
 
 	def flush_transfers(self, func):
-- 
1.7.11.7


^ permalink raw reply related

* Re: [PATCH BlueZ 1/2] obex-client: Make use of g_dbus_get_properties to get transfer properties
From: Johan Hedberg @ 2012-12-17 14:32 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1355750727-23222-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, Dec 17, 2012, Luiz Augusto von Dentz wrote:
> In addition fix the reply generated by obc_transfer_create_dbus_reply to
> not use a structure container instead use object, dict 'oa{sv}' as
> indicated in the documentation.
> ---
>  obexd/client/transfer.c | 46 ++++------------------------------------------
>  1 file changed, 4 insertions(+), 42 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH 01/11] adapter: Rename btd_adapter *up members to *powered
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This better describes those members purpose.
---
 src/adapter.c | 36 ++++++++++++++++++------------------
 src/adapter.h |  2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index d9b841d..f56b000 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -120,8 +120,8 @@ struct discovery {
 
 struct btd_adapter {
 	uint16_t dev_id;
-	gboolean up;
-	gboolean already_up;
+	gboolean powered;
+	gboolean already_powered;
 	char *path;			/* adapter object path */
 	bdaddr_t bdaddr;		/* adapter Bluetooth Address */
 	uint32_t dev_class;		/* Class of Device */
@@ -322,7 +322,7 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 	if (adapter->pending_mode != NULL)
 		return -EALREADY;
 
-	if (!adapter->up && new_mode != MODE_OFF) {
+	if (!adapter->powered && new_mode != MODE_OFF) {
 		err = mgmt_set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
 			return err;
@@ -330,7 +330,7 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		goto done;
 	}
 
-	if (adapter->up && new_mode == MODE_OFF) {
+	if (adapter->powered && new_mode == MODE_OFF) {
 		err = mgmt_set_powered(adapter->dev_id, FALSE);
 		if (err < 0)
 			return err;
@@ -597,7 +597,7 @@ static void stop_discovery(struct btd_adapter *adapter)
 		return;
 	}
 
-	if (adapter->up)
+	if (adapter->powered)
 		mgmt_stop_discovery(adapter->dev_id);
 	else
 		discovery_cleanup(adapter);
@@ -1022,7 +1022,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
 	const char *sender = dbus_message_get_sender(msg);
 	int err;
 
-	if (!adapter->up)
+	if (!adapter->powered)
 		return btd_error_not_ready(msg);
 
 	req = find_session(adapter->disc_sessions, sender);
@@ -1057,7 +1057,7 @@ static DBusMessage *adapter_stop_discovery(DBusConnection *conn,
 	struct session_req *req;
 	const char *sender = dbus_message_get_sender(msg);
 
-	if (!adapter->up)
+	if (!adapter->powered)
 		return btd_error_not_ready(msg);
 
 	req = find_session(adapter->disc_sessions, sender);
@@ -1132,7 +1132,7 @@ static gboolean adapter_property_get_powered(
 	struct btd_adapter *adapter = data;
 	dbus_bool_t value;
 
-	value = (adapter->up && !adapter->off_requested) ? TRUE : FALSE;
+	value = (adapter->powered && !adapter->off_requested) ? TRUE : FALSE;
 	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
 
 	return TRUE;
@@ -1740,7 +1740,7 @@ void adapter_connect_list_add(struct btd_adapter *adapter,
 	DBG("%s added to %s's connect_list", device_get_path(device),
 								adapter->name);
 
-	if (!adapter->up)
+	if (!adapter->powered)
 		return;
 
 	if (adapter->off_requested)
@@ -1778,7 +1778,7 @@ void btd_adapter_start(struct btd_adapter *adapter)
 	struct session_req *req;
 
 	adapter->off_requested = FALSE;
-	adapter->up = TRUE;
+	adapter->powered = TRUE;
 
 	if (adapter->scan_mode & SCAN_INQUIRY) {
 		adapter->mode = MODE_DISCOVERABLE;
@@ -1911,7 +1911,7 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	/* check pending requests */
 	reply_pending_requests(adapter);
 
-	adapter->up = FALSE;
+	adapter->powered = FALSE;
 
 	if (adapter->discovery) {
 		emit_discovering = true;
@@ -2781,12 +2781,12 @@ static void load_config(struct btd_adapter *adapter)
 	g_key_file_free(key_file);
 }
 
-gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
+gboolean adapter_init(struct btd_adapter *adapter, gboolean powered)
 {
 	struct agent *agent;
 
-	adapter->up = up;
-	adapter->already_up = up;
+	adapter->powered = powered;
+	adapter->already_powered = powered;
 
 	adapter->allow_name_changes = TRUE;
 
@@ -2877,7 +2877,7 @@ void adapter_remove(struct btd_adapter *adapter)
 	g_slist_free(adapter->pin_callbacks);
 
 	/* Return adapter to down state if it was not up on init */
-	if (!adapter->already_up && adapter->up)
+	if (!adapter->already_powered && adapter->powered)
 		mgmt_set_powered(adapter->dev_id, FALSE);
 }
 
@@ -3445,7 +3445,7 @@ int btd_cancel_authorization(guint id)
 
 int btd_adapter_restore_powered(struct btd_adapter *adapter)
 {
-	if (adapter->up)
+	if (adapter->powered)
 		return 0;
 
 	if (adapter->mode == MODE_OFF)
@@ -3487,7 +3487,7 @@ ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,
 int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
 							gboolean enable)
 {
-	if (!adapter->up)
+	if (!adapter->powered)
 		return -EINVAL;
 
 	return mgmt_set_fast_connectable(adapter->dev_id, enable);
@@ -3497,7 +3497,7 @@ int btd_adapter_read_clock(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
 				int which, int timeout, uint32_t *clock,
 				uint16_t *accuracy)
 {
-	if (!adapter->up)
+	if (!adapter->powered)
 		return -EINVAL;
 
 	return mgmt_read_clock(adapter->dev_id, bdaddr, which,
diff --git a/src/adapter.h b/src/adapter.h
index 5030cb0..3b2d14f 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -100,7 +100,7 @@ void adapter_remove_device(struct btd_adapter *adapter,
 						gboolean remove_storage);
 
 struct btd_adapter *adapter_create(int id);
-gboolean adapter_init(struct btd_adapter *adapter, gboolean up);
+gboolean adapter_init(struct btd_adapter *adapter, gboolean powered);
 void adapter_remove(struct btd_adapter *adapter);
 void adapter_set_allow_name_changes(struct btd_adapter *adapter,
 						gboolean allow_name_changes);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 02/11] manager: Rename btd_manager_register_adapter up parameter to powered
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Match parameter name to adapter_init parameter name.
---
 src/manager.c | 4 ++--
 src/manager.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 1f4b831..22e593d 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -156,7 +156,7 @@ GSList *manager_get_adapters(void)
 	return adapters;
 }
 
-struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
+struct btd_adapter *btd_manager_register_adapter(int id, gboolean powered)
 {
 	struct btd_adapter *adapter;
 	const char *path;
@@ -173,7 +173,7 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
 
 	adapters = g_slist_append(adapters, adapter);
 
-	if (!adapter_init(adapter, up)) {
+	if (!adapter_init(adapter, powered)) {
 		adapters = g_slist_remove(adapters, adapter);
 		btd_adapter_unref(adapter);
 		return NULL;
diff --git a/src/manager.h b/src/manager.h
index fdaabfd..a2b8c31 100644
--- a/src/manager.h
+++ b/src/manager.h
@@ -35,5 +35,5 @@ struct btd_adapter *manager_find_adapter_by_id(int id);
 struct btd_adapter *manager_get_default_adapter(void);
 void manager_foreach_adapter(adapter_cb func, gpointer user_data);
 GSList *manager_get_adapters(void);
-struct btd_adapter *btd_manager_register_adapter(int id, gboolean up);
+struct btd_adapter *btd_manager_register_adapter(int id, gboolean powered);
 int btd_manager_unregister_adapter(int id);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 03/11] adapter: Make adapter_mode_changed accept mode as bool params
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Pass connectable and discoverable as bools.
---
 src/adapter.c | 19 ++++++++++++++++++-
 src/adapter.h |  3 ++-
 src/mgmt.c    | 19 ++++---------------
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f56b000..e50e646 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3151,9 +3151,26 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 	}
 }
 
-void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode)
+static uint8_t create_mode(bool connectable, bool discoverable)
+{
+	uint8_t mode = 0;
+
+	if (connectable)
+		mode |= SCAN_PAGE;
+
+	if (discoverable)
+		mode |= SCAN_INQUIRY;
+
+	return mode;
+}
+
+void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
+							bool discoverable)
 {
 	bool emit_pairable = false;
+	uint8_t scan_mode;
+
+	scan_mode = create_mode(connectable, discoverable);
 
 	DBG("old 0x%02x new 0x%02x", adapter->scan_mode, scan_mode);
 
diff --git a/src/adapter.h b/src/adapter.h
index 3b2d14f..7c20e29 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -114,7 +114,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
 					uint8_t bdaddr_type, int8_t rssi,
 					bool confirm_name, bool legacy,
 					uint8_t *data, uint8_t data_len);
-void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
+void adapter_mode_changed(struct btd_adapter *adapter, bool connectable,
+							bool discoverable);
 int adapter_set_name(struct btd_adapter *adapter, const char *name);
 void adapter_name_changed(struct btd_adapter *adapter, const char *name);
 void adapter_service_insert(struct btd_adapter *adapter, void *rec);
diff --git a/src/mgmt.c b/src/mgmt.c
index dfcf558..cc54e8b 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -328,19 +328,6 @@ static inline int mgmt_low_energy(uint32_t settings)
 	return (settings & MGMT_SETTING_LE) != 0;
 }
 
-static uint8_t create_mode(uint32_t settings)
-{
-	uint8_t mode = 0;
-
-	if (mgmt_connectable(settings))
-		mode |= SCAN_PAGE;
-
-	if (mgmt_discoverable(settings))
-		mode |= SCAN_INQUIRY;
-
-	return mode;
-}
-
 static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 {
 	struct controller_info *info;
@@ -356,7 +343,8 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 	info = &controllers[index];
 
 	if (mgmt_powered(settings))
-		adapter_mode_changed(adapter, create_mode(settings));
+		adapter_mode_changed(adapter, mgmt_connectable(settings),
+						mgmt_discoverable(settings));
 
 	if (mgmt_pairable(settings) != pairable)
 		mgmt_set_pairable(index, pairable);
@@ -434,7 +422,8 @@ static void mgmt_new_settings(int sk, uint16_t index, void *buf, size_t len)
 	if (new_power != old_power)
 		mgmt_update_powered(adapter, info, settings);
 	else if (new_power && mode_changed(settings, info->current_settings))
-		adapter_mode_changed(adapter, create_mode(settings));
+		adapter_mode_changed(adapter, mgmt_connectable(settings),
+						mgmt_discoverable(settings));
 
 	old_pairable = mgmt_pairable(info->current_settings);
 	new_pairable = mgmt_pairable(settings);
-- 
1.8.0


^ permalink raw reply related

* [PATCH 04/11] adapter: Add btd_adapter_get_pairable function
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

Add btd_adapter_get_pairable and remove pairable argument from
btd_adapter_get_mode. Use btd_adapter_get_pairable to get pairable
state where needed.
---
 plugins/neard.c | 6 +-----
 src/adapter.c   | 9 +++++----
 src/adapter.h   | 5 +++--
 src/mgmt.c      | 6 ++++--
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index a8c12fd..e1f3583 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -593,17 +593,13 @@ static int process_params(DBusMessage *msg, struct btd_adapter *adapter,
 
 static int check_adapter(struct btd_adapter *adapter)
 {
-	gboolean pairable;
-
 	if (!adapter)
 		return -ENOENT;
 
 	if (btd_adapter_check_oob_handler(adapter))
 		return -EINPROGRESS;
 
-	btd_adapter_get_mode(adapter, NULL, NULL, &pairable);
-
-	if (!pairable || !adapter_get_agent(adapter))
+	if (!btd_adapter_get_pairable(adapter) || !adapter_get_agent(adapter))
 		return -ENONET;
 
 	if (!btd_adapter_ssp_enabled(adapter))
diff --git a/src/adapter.c b/src/adapter.c
index e50e646..8f1c229 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1694,17 +1694,18 @@ static void load_connections(struct btd_adapter *adapter)
 }
 
 void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout,
-						gboolean *pairable)
+						uint16_t *discoverable_timeout)
 {
 	if (mode)
 		*mode = adapter->mode;
 
 	if (discoverable_timeout)
 		*discoverable_timeout = adapter->discov_timeout;
+}
 
-	if (pairable)
-		*pairable = adapter->pairable;
+bool btd_adapter_get_pairable(struct btd_adapter *adapter)
+{
+	return adapter->pairable;
 }
 
 void btd_adapter_get_major_minor(struct btd_adapter *adapter, uint8_t *major,
diff --git a/src/adapter.h b/src/adapter.h
index 7c20e29..125657a 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -81,8 +81,9 @@ void btd_adapter_start(struct btd_adapter *adapter);
 int btd_adapter_stop(struct btd_adapter *adapter);
 
 void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout,
-						gboolean *pairable);
+						uint16_t *discoverable_timeout);
+
+bool btd_adapter_get_pairable(struct btd_adapter *adapter);
 
 void btd_adapter_get_major_minor(struct btd_adapter *adapter, uint8_t *major,
 							uint8_t *minor);
diff --git a/src/mgmt.c b/src/mgmt.c
index cc54e8b..feca194 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -336,7 +336,7 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 
 	DBG("new settings %x", settings);
 
-	btd_adapter_get_mode(adapter, NULL, &discoverable_timeout, &pairable);
+	btd_adapter_get_mode(adapter, NULL, &discoverable_timeout);
 
 	index = adapter_get_dev_id(adapter);
 
@@ -346,6 +346,8 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 		adapter_mode_changed(adapter, mgmt_connectable(settings),
 						mgmt_discoverable(settings));
 
+	pairable = btd_adapter_get_pairable(adapter);
+
 	if (mgmt_pairable(settings) != pairable)
 		mgmt_set_pairable(index, pairable);
 
@@ -1213,7 +1215,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	btd_adapter_get_major_minor(adapter, &major, &minor);
 	mgmt_set_dev_class(index, major, minor);
 
-	btd_adapter_get_mode(adapter, &mode, NULL, NULL);
+	btd_adapter_get_mode(adapter, &mode, NULL);
 	if (mode == MODE_OFF && mgmt_powered(info->current_settings)) {
 		mgmt_set_powered(index, FALSE);
 		return;
-- 
1.8.0


^ permalink raw reply related

* [PATCH 05/11] adapter: Remove not used parameter from btd_adapter_get_mode
From: Szymon Janc @ 2012-12-17 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1355755498-2700-1-git-send-email-szymon.janc@tieto.com>

discoverable_timeout is not used outside of adapter code.
---
 src/adapter.c | 6 +-----
 src/adapter.h | 3 +--
 src/mgmt.c    | 6 ++----
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8f1c229..915d897 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1693,14 +1693,10 @@ static void load_connections(struct btd_adapter *adapter)
 	g_slist_free_full(conns, g_free);
 }
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout)
+void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode)
 {
 	if (mode)
 		*mode = adapter->mode;
-
-	if (discoverable_timeout)
-		*discoverable_timeout = adapter->discov_timeout;
 }
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter)
diff --git a/src/adapter.h b/src/adapter.h
index 125657a..44ba56a 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -80,8 +80,7 @@ void btd_adapter_start(struct btd_adapter *adapter);
 
 int btd_adapter_stop(struct btd_adapter *adapter);
 
-void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
-						uint16_t *discoverable_timeout);
+void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode);
 
 bool btd_adapter_get_pairable(struct btd_adapter *adapter);
 
diff --git a/src/mgmt.c b/src/mgmt.c
index feca194..3c7e014 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -332,12 +332,10 @@ static void update_settings(struct btd_adapter *adapter, uint32_t settings)
 {
 	struct controller_info *info;
 	gboolean pairable;
-	uint16_t index, discoverable_timeout;
+	uint16_t index;
 
 	DBG("new settings %x", settings);
 
-	btd_adapter_get_mode(adapter, NULL, &discoverable_timeout);
-
 	index = adapter_get_dev_id(adapter);
 
 	info = &controllers[index];
@@ -1215,7 +1213,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	btd_adapter_get_major_minor(adapter, &major, &minor);
 	mgmt_set_dev_class(index, major, minor);
 
-	btd_adapter_get_mode(adapter, &mode, NULL);
+	btd_adapter_get_mode(adapter, &mode);
 	if (mode == MODE_OFF && mgmt_powered(info->current_settings)) {
 		mgmt_set_powered(index, FALSE);
 		return;
-- 
1.8.0


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox