Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH v2] gatt: Translate Characteristic names
From: Chen Ganir @ 2012-09-02  6:50 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1652968.T8pSJl1pGy@uw000953>

Szymon :

On 08/30/2012 03:43 PM, Szymon Janc wrote:
> On Thursday 30 of August 2012 15:38:04 Chen Ganir wrote:
>
>>>>    static GSList *gatt_services = NULL;
>>>>
>>>> +static const struct characteristic_info *get_char_info(const char* uuid)
>>>
>>> I would leave this function returning name directly and not whole struct characteristic_info.
>>>
>> Why ? We have this struct with characteristic information (maybe later
>> we'll add more information. Why limit ourselves to name only ?
>
> If you plan to add more data into that structure then it is OK to return whole struct.
> But if only name is to be used, then I would just call that function get_name() and
> return name.
>
For now, i believe this is the only information we have for the 
characteristic. I will send an updated patch.

BR,
Chen Ganir



^ permalink raw reply

* [PATCH -v3 2/2] rctest: add option to save received data to file
From: Gustavo Padovan @ 2012-08-31 20:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan
In-Reply-To: <1346446228-11105-1-git-send-email-gustavo@padovan.org>

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

works only for automated test option for now
---
 test/rctest.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 3 deletions(-)

diff --git a/test/rctest.c b/test/rctest.c
index 0c645b7..57d092a 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -78,6 +78,8 @@ static uint16_t uuid = 0x0000;
 static uint8_t channel = 10;
 
 static char *filename = NULL;
+static char *savefile = NULL;
+static int save_fd = -1;
 
 static int master = 0;
 static int auth = 0;
@@ -448,6 +450,25 @@ static void dump_mode(int sk)
 		syslog(LOG_INFO, "Received %d bytes", len);
 }
 
+static void save_mode(int sk)
+{
+	int len, ret;
+	char *b;
+
+	b = malloc(data_size);
+	if (!b) {
+		syslog(LOG_ERR, "Failed to open file to save recv data");
+		return;
+	}
+
+	syslog(LOG_INFO, "Receiving ...");
+	while ((len = read(sk, b, data_size)) > 0) {
+		ret = write(save_fd, b, len);
+		if (ret < 0)
+			return;
+	}
+}
+
 static void recv_mode(int sk)
 {
 	struct timeval tv_beg, tv_end, tv_diff;
@@ -603,7 +624,20 @@ static void automated_send_recv()
 	char device[18];
 
 	if (fork()) {
-		do_listen(recv_mode);
+		if (!savefile) {
+			do_listen(recv_mode);
+			return;
+		}
+
+		save_fd = open(savefile, O_CREAT | O_WRONLY,
+						S_IRUSR | S_IWUSR);
+		if (save_fd < 0)
+			syslog(LOG_ERR, "Failed to open file to save "
+								"recv data");
+
+		do_listen(save_mode);
+
+		close(save_fd);
 	} else {
 		ba2str(&bdaddr, device);
 
@@ -614,6 +648,15 @@ static void automated_send_recv()
 	}
 }
 
+static void sig_child_exit(int code)
+{
+	syslog(LOG_INFO, "Exit");
+	exit(0);
+
+	if (save_fd >= 0)
+		close(save_fd);
+}
+
 static void usage(void)
 {
 	printf("rctest - RFCOMM testing\n"
@@ -635,6 +678,7 @@ static void usage(void)
 		"\t[-L seconds] enabled SO_LINGER option\n"
 		"\t[-W seconds] enable deferred setup\n"
 		"\t[-B filename] use data packets from file\n"
+		"\t[-O filename] save received data to file\n"
 		"\t[-N num] number of frames to send\n"
 		"\t[-C num] send num frames before delay (default = 1)\n"
 		"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
@@ -654,7 +698,7 @@ int main(int argc, char *argv[])
 	bacpy(&bdaddr, BDADDR_ANY);
 	bacpy(&auto_bdaddr, BDADDR_ANY);
 
-	while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+	while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:O:N:MAESL:W:C:D:Y:T")) != EOF) {
 		switch (opt) {
 		case 'r':
 			mode = RECV;
@@ -754,6 +798,10 @@ int main(int argc, char *argv[])
 			filename = strdup(optarg);
 			break;
 
+		case 'O':
+			savefile = strdup(optarg);
+			break;
+
 		case 'N':
 			num_frames = atoi(optarg);
 			break;
@@ -791,7 +839,10 @@ int main(int argc, char *argv[])
 	}
 
 	memset(&sa, 0, sizeof(sa));
-	sa.sa_handler = SIG_IGN;
+	if (mode == AUTO)
+		sa.sa_handler = sig_child_exit;
+	else
+		sa.sa_handler = SIG_IGN;
 	sa.sa_flags   = SA_NOCLDSTOP;
 	sigaction(SIGCHLD, &sa, NULL);
 
-- 
1.7.11.2


^ permalink raw reply related

* [PATCH -v3 1/2] rctest: add automated test
From: Gustavo Padovan @ 2012-08-31 20:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

adds -a option to enable automated tests. We use the -i option to define
the receiving side and the -a define the sending side:

./rctest -i hci0 -a hci1
---
 test/rctest.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/test/rctest.c b/test/rctest.c
index f82d2cc..0c645b7 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -55,7 +55,8 @@ enum {
 	DUMP,
 	CONNECT,
 	CRECV,
-	LSEND
+	LSEND,
+	AUTO,
 };
 
 static unsigned char *buf;
@@ -72,6 +73,7 @@ static unsigned long delay = 0;
 
 /* Default addr and channel */
 static bdaddr_t bdaddr;
+static bdaddr_t auto_bdaddr;
 static uint16_t uuid = 0x0000;
 static uint8_t channel = 10;
 
@@ -162,7 +164,11 @@ static int do_connect(const char *svr)
 	/* Bind to local address */
 	memset(&addr, 0, sizeof(addr));
 	addr.rc_family = AF_BLUETOOTH;
-	bacpy(&addr.rc_bdaddr, &bdaddr);
+
+	if (bacmp(&auto_bdaddr, BDADDR_ANY))
+		bacpy(&addr.rc_bdaddr, &auto_bdaddr);
+	else
+		bacpy(&addr.rc_bdaddr, &bdaddr);
 
 	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		syslog(LOG_ERR, "Can't bind socket: %s (%d)",
@@ -591,6 +597,23 @@ static void multi_connect_mode(int argc, char *argv[])
 	}
 }
 
+static void automated_send_recv()
+{
+	int sk;
+	char device[18];
+
+	if (fork()) {
+		do_listen(recv_mode);
+	} else {
+		ba2str(&bdaddr, device);
+
+		sk = do_connect(device);
+		if (sk < 0)
+			exit(1);
+		send_mode(sk);
+	}
+}
+
 static void usage(void)
 {
 	printf("rctest - RFCOMM testing\n"
@@ -604,7 +627,8 @@ static void usage(void)
 		"\t-u connect and receive\n"
 		"\t-n connect and be silent\n"
 		"\t-c connect, disconnect, connect, ...\n"
-		"\t-m multiple connects\n");
+		"\t-m multiple connects\n"
+		"\t-a automated test (receive hcix as parameter)\n");
 
 	printf("Options:\n"
 		"\t[-b bytes] [-i device] [-P channel] [-U uuid]\n"
@@ -628,8 +652,9 @@ int main(int argc, char *argv[])
 	int opt, sk, mode = RECV, need_addr = 0;
 
 	bacpy(&bdaddr, BDADDR_ANY);
+	bacpy(&auto_bdaddr, BDADDR_ANY);
 
-	while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+	while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
 		switch (opt) {
 		case 'r':
 			mode = RECV;
@@ -668,6 +693,15 @@ int main(int argc, char *argv[])
 			need_addr = 1;
 			break;
 
+		case 'a':
+			mode = AUTO;
+
+			if (!strncasecmp(optarg, "hci", 3))
+				hci_devba(atoi(optarg + 3), &auto_bdaddr);
+			else
+				str2ba(optarg, &auto_bdaddr);
+			break;
+
 		case 'b':
 			data_size = atoi(optarg);
 			break;
@@ -804,6 +838,10 @@ int main(int argc, char *argv[])
 				exit(1);
 			dump_mode(sk);
 			break;
+
+		case AUTO:
+			automated_send_recv();
+			break;
 	}
 
 	syslog(LOG_INFO, "Exit");
-- 
1.7.11.2


^ permalink raw reply related

* Re: [PATCHv2] Bluetooth: Remove unneeded zero init
From: Gustavo Padovan @ 2012-08-31 17:55 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1346420369-11909-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

* Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com> [2012-08-31 16:39:28 +0300]:

> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> hdev is allocated with kzalloc so zero initialization is not needed.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    9 ---------
>  net/bluetooth/hci_core.c         |    2 +-
>  2 files changed, 1 insertion(+), 10 deletions(-)

Patch has been applied to bluetooth-next. Thanks.

	Gustavo

^ permalink raw reply

* Re: [PATCH] Bluetooth: Use GFP_KERNEL in read_index_list
From: Gustavo Padovan @ 2012-08-31 17:54 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1346396746-3479-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

* Szymon Janc <szymon.janc@tieto.com> [2012-08-31 09:05:46 +0200]:

> read_index_list is executed by user thread running in kernel-mode
> thus is allowed to sleep.
> 
> Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
> ---
>  net/bluetooth/mgmt.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patch has been applied to bluetooth-next. Thanks.

	Gustavo

^ permalink raw reply

* Re: [PATCHv2] Bluetooth: Remove unneeded zero init
From: Marcel Holtmann @ 2012-08-31 16:20 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1346420369-11909-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> hdev is allocated with kzalloc so zero initialization is not needed.
> 
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    9 ---------
>  net/bluetooth/hci_core.c         |    2 +-
>  2 files changed, 1 insertion(+), 10 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply

* Re: [PATCH 0/7] RFC: proximity cleanup
From: Anderson Lizardo @ 2012-08-31 16:17 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Fri, Aug 31, 2012 at 8:48 AM, Andrzej Kaczmarek
<andrzej.kaczmarek@tieto.com> wrote:
> Hi,
>
> Here are few patches to cleanup proximity profile code a bit which seem to
> keep track of some data which are redundant and has minor issue with device
> driver registration.
>
> Most cleanup is done in patch #3 which removes tracking of DBusConnection
> across whole plugin and simply uses get_dbus_connection() wherever necessary.
> This is different than other profile plugins do, but reduces code size and
> memory footprint a bit so can be done for other plugins as well if accepted.

While some cleanups here are very welcome, I'm worried that you are
cleaning up things before finishing the Proximity Reporter
implementation. Power Level characteristic for instance is currently a
stub, how do you plan to store it per adapter, without the struct
reporter_adapter?

Therefore I suggest you split the "trivial" cleanups from the removal
of struct reporter_adapter.

BTW, do you have plans to add more features to the Proximity Reporter
implementation?

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* Re: [RFC 03/15] sdp: Use helper functions instead of bt_get_unaligned macro
From: Marcel Holtmann @ 2012-08-31 16:14 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1346402185-9487-4-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

> This fix number of compilation errors on ARM similar to one below.
> 
> lib/sdp.c: In function 'sdp_uuid_extract':
> lib/sdp.c:1019:27: error: cast increases required alignment
> 	of target type [-Werror=cast-align]
> lib/sdp.c:1019:27: error: cast increases required alignment
> 	of target type [-Werror=cast-align]
> lib/sdp.c:1026:27: error: cast increases required alignment
> 	of target type [-Werror=cast-align]
> lib/sdp.c:1026:27: error: cast increases required alignment
> 	of target type [-Werror=cast-align]
> 
> Change-Id: I587fb99328d7e5b9053af81597bd48b3a4e610ad
> ---
>  lib/sdp.c |   56 ++++++++++++++++++++++++++++----------------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/lib/sdp.c b/lib/sdp.c
> index 36b4d08..d40500f 100644
> --- a/lib/sdp.c
> +++ b/lib/sdp.c
> @@ -376,27 +376,27 @@ sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value,
>  		d->unitSize += sizeof(int8_t);
>  		break;
>  	case SDP_UINT16:
> -		d->val.uint16 = bt_get_unaligned((uint16_t *) value);
> +		d->val.uint16 = bt_get_16(value);
>  		d->unitSize += sizeof(uint16_t);
>  		break;

I do not like this. Either we use be16 here and store it in the native
endian converted from the protocol endian or we leave it as it is.

I want clear get_le16 and get_be16 and not another get_16. That just
makes the code hard to read.

Regards

Marcel



^ permalink raw reply

* Re: [PATCH BlueZ] build: Use AC_USE_SYSTEM_EXTENSIONS for POSIX/C extensions
From: Lucas De Marchi @ 2012-08-31 16:11 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Anderson Lizardo, linux-bluetooth
In-Reply-To: <1346428924.23377.12.camel@aeonflux>

On Fri, Aug 31, 2012 at 1:02 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Lucas,
>
>> > On Thu, Aug 30, 2012 at 11:08 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
>> >> Hi Anderson,
>> >>
>> >>> Using this macro in configure.ac enables certain extensions that BlueZ
>> >>> currently depends on. The macro is recommended instead of defining
>> >>> _GNU_SOURCE on each C file.
>> >>
>> >> what is the advantage of this. I am actually fine with using _GNU_SOURCE
>> >> in the C files. It is according to the man pages.
>> >
>> > The only advantage I see is that we don't have to worry about
>> > reviewing these defines as the symbols get incorporated in newer
>> > standards. For instance, this patch was brought up because O_CLOEXEC
>> > does not exist on POSIX.1-2001, but was incorporated POSIX.1-2008, so
>> > for newer systems _GNU_SOURCE is not necessary for it anymore, but for
>> > some (still maintained) distros it is.
>> >
>> > Sometimes we remove code that used these extensions, and simply forget
>> > the _GNU_SOURCE there as well.
>>
>> And also forget to add it. Then 3 months later comes a patch to fix it
>> by adding the definition.
>>
>> Using the autofoo macro we stop the build-fix patches for things like this.
>>
>>
>> That is: it removes code, it's more future-proof and it has no
>> downsides. So, what's the point of not using it?
>
> unless that autoconf thing breaks and we don't get what we want. Or we
> are dealing with an outdated autoconf.

seriously? before 2.60? It's already a pre-requisite in our configure.ac


>
> I am against this. I rather get build fixes and have them recorded in
> git compared to hoping that this magically fixes everything.
>
>> Some months ago I sent a patch to also remove a lot of dumb "#include
>> config.h". It has the same reasoning behind it: remove code and be
>> more future-proof. It was for connman, but if you are interested I can
>> send it to bluez/ofono/etc too -
>> http://permalink.gmane.org/gmane.linux.network.connman/7310
>
> Same thing. I believe that boilerplate is better being explicit than
> magically having it done.

If it helps to convince you: systemd, kmod, pulseaudio, libabc, and
many others.... all of them use these macros.


Lucas De Marchi

^ permalink raw reply

* Re: [PATCH] Bluetooth: Use GFP_KERNEL in read_index_list
From: Marcel Holtmann @ 2012-08-31 16:11 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1346396746-3479-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

> read_index_list is executed by user thread running in kernel-mode
> thus is allowed to sleep.
> 
> Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
> ---
>  net/bluetooth/mgmt.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply

* Re: [PATCH 1/2] Implement broadcom patchram firmware loader
From: Marcel Holtmann @ 2012-08-31 16:11 UTC (permalink / raw)
  To: Jesse Sung; +Cc: linux-bluetooth
In-Reply-To: <1346390510-18538-2-git-send-email-jesse.sung@canonical.com>

Hi Jesse,

> From: Wen-chien Jesse Sung <jesse.sung@canonical.com>
> 
> 
> Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>

please learn on how to write commit messages. I want a full blown commit
messages with /sys/kernel/debug/usb/devices output (before and after)
and something that explains what is actually done.

> ---
>  drivers/bluetooth/btusb.c |  103 +++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 99 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 654e248..7189fed 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -23,6 +23,8 @@
>  
>  #include <linux/module.h>
>  #include <linux/usb.h>
> +#include <linux/delay.h>
> +#include <linux/firmware.h>
>  
>  #include <net/bluetooth/bluetooth.h>
>  #include <net/bluetooth/hci_core.h>
> @@ -47,6 +49,7 @@ static struct usb_driver btusb_driver;
>  #define BTUSB_BROKEN_ISOC	0x20
>  #define BTUSB_WRONG_SCO_MTU	0x40
>  #define BTUSB_ATH3012		0x80
> +#define BTUSB_BCM_PATCHRAM	0x100
>  
>  static struct usb_device_id btusb_table[] = {
>  	/* Generic Bluetooth USB device */
> @@ -96,14 +99,15 @@ static struct usb_device_id btusb_table[] = {
>  	{ USB_DEVICE(0x0c10, 0x0000) },
>  
>  	/* Broadcom BCM20702A0 */
> +	{ USB_DEVICE(0x0489, 0xe031), .driver_info = BTUSB_BCM_PATCHRAM },
>  	{ USB_DEVICE(0x0489, 0xe042) },
> -	{ USB_DEVICE(0x413c, 0x8197) },
> +	{ USB_DEVICE(0x413c, 0x8197), .driver_info = BTUSB_BCM_PATCHRAM },

These drivers did work without firmware before. So why is this change
required? Or is that Broadcom wide?
 
>  	/* Foxconn - Hon Hai */
>  	{ USB_DEVICE(0x0489, 0xe033) },
>  
>  	/*Broadcom devices with vendor specific id */
> -	{ USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
> +	{ USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01), .driver_info = BTUSB_BCM_PATCHRAM },
>  
>  	{ }	/* Terminating entry */
>  };
> @@ -197,6 +201,37 @@ static struct usb_device_id blacklist_table[] = {
>  	{ }	/* Terminating entry */
>  };
>  
> +#define PATCHRAM_TIMEOUT	1000
> +#define FW_0489_E031		"fw-0489_e031.hcd"
> +#define FW_0A5C_21D3		"fw-0a5c_21d3.hcd"
> +#define FW_0A5C_21D7		"fw-0a5c_21d7.hcd"
> +#define FW_0A5C_21E6		"fw-0a5c_21e6.hcd"
> +#define FW_0A5C_21F3		"fw-0a5c_21f3.hcd"
> +#define FW_0A5C_21F4		"fw-0a5c_21f4.hcd"
> +#define FW_413C_8197		"fw-413c_8197.hcd"
> +
> +MODULE_FIRMWARE(FW_0489_E031);
> +MODULE_FIRMWARE(FW_0A5C_21D3);
> +MODULE_FIRMWARE(FW_0A5C_21D7);
> +MODULE_FIRMWARE(FW_0A5C_21E6);
> +MODULE_FIRMWARE(FW_0A5C_21F3);
> +MODULE_FIRMWARE(FW_0A5C_21F4);
> +MODULE_FIRMWARE(FW_413C_8197);
> +
> +static struct usb_device_id patchram_table[] = {
> +	/* Dell DW1704 */
> +	{ USB_DEVICE(0x0a5c, 0x21d3), .driver_info = (kernel_ulong_t) FW_0A5C_21D3 },
> +	{ USB_DEVICE(0x0a5c, 0x21d7), .driver_info = (kernel_ulong_t) FW_0A5C_21D7 },
> +	/* Dell DW380 */
> +	{ USB_DEVICE(0x413c, 0x8197), .driver_info = (kernel_ulong_t) FW_413C_8197 },
> +	/* FoxConn Hon Hai */
> +	{ USB_DEVICE(0x0489, 0xe031), .driver_info = (kernel_ulong_t) FW_0489_E031 },
> +	/* Lenovo */
> +	{ USB_DEVICE(0x0a5c, 0x21e6), .driver_info = (kernel_ulong_t) FW_0A5C_21E6 },
> +	{ USB_DEVICE(0x0a5c, 0x21f3), .driver_info = (kernel_ulong_t) FW_0A5C_21F3 },
> +	{ USB_DEVICE(0x0a5c, 0x21f4), .driver_info = (kernel_ulong_t) FW_0A5C_21F4 },
> +};
> +

And this looks like totally wasted details to me. Either build the
firmware name from USB VID:PID or only include the ones that we are
actually supporting.

>  #define BTUSB_MAX_ISOC_FRAMES	10
>  
>  #define BTUSB_INTR_RUNNING	0
> @@ -914,6 +949,55 @@ static void btusb_waker(struct work_struct *work)
>  	usb_autopm_put_interface(data->intf);
>  }
>  
> +static inline void load_patchram_fw(struct usb_device *udev, const struct usb_device_id *id)
> +{
> +	size_t pos = 0;
> +	int err = 0;
> +	const struct firmware *fw;
> +
> +	unsigned char reset_cmd[] = { 0x03, 0x0c, 0x00 };
> +	unsigned char download_cmd[] = { 0x2e, 0xfc, 0x00 };
> +
> +	if (request_firmware(&fw, (const char *) id->driver_info, &udev->dev) < 0) {
> +		BT_INFO("can't load firmware, may not work correctly");
> +		return;
> +	}
> +
> +	if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
> +		reset_cmd, sizeof(reset_cmd), PATCHRAM_TIMEOUT) < 0) {
> +		err = -1;
> +		goto out;
> +	}
> +	msleep(300);
> +
> +	if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
> +		download_cmd, sizeof(download_cmd), PATCHRAM_TIMEOUT) < 0) {
> +		err = -1;
> +		goto out;
> +	}
> +	msleep(300);
> +
> +	while (pos < fw->size) {
> +		size_t len;
> +		len = fw->data[pos + 2] + 3;
> +		if ((pos + len > fw->size) ||
> +			(usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
> +			USB_TYPE_CLASS, 0, 0, (void *)fw->data + pos, len,
> +			PATCHRAM_TIMEOUT) < 0)) {
> +			err = -1;
> +			goto out;
> +		}
> +		pos += len;
> +	}
> +
> +	err = (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0, USB_TYPE_CLASS, 0, 0,
> +		reset_cmd, sizeof(reset_cmd), PATCHRAM_TIMEOUT) < 0);
> +out:
> +	if (err)
> +		BT_INFO("fail to load firmware, may not work correctly");
> +	release_firmware(fw);
> +}
> +
>  static int btusb_probe(struct usb_interface *intf,
>  				const struct usb_device_id *id)
>  {
> @@ -1078,15 +1162,26 @@ static int btusb_probe(struct usb_interface *intf,
>  		}
>  	}
>  
> +	usb_set_intfdata(intf, data);
> +
> +	if (id->driver_info & BTUSB_BCM_PATCHRAM) {
> +		const struct usb_device_id *match;
> +		match = usb_match_id(intf, patchram_table);
> +		if (match) {
> +			btusb_open(hdev);
> +			load_patchram_fw(interface_to_usbdev(intf), match);
> +			btusb_close(hdev);
> +		}
> +	}
> +

So we are now blocking every other USB devices on that bus here? I
actually do not like this idea very much.

Also the call of btusb_open() before hdev is actually registered is
kinda fishy to me. I am not even sure that works how you think it would.

And why can't Broadcom just change the PID once the patchram has been
loaded to something else. That way we can nicely iterate through this.

This also does not really belong in a standard driver. Quirks fine, but
a complete ROM patches procedure that is vendor specific.

As I said above, I want to see the /sys/kernel/debug/usb/devices from
before and after first. Until then NAK.

Regards

Marcel



^ permalink raw reply

* Re: [PATCH BlueZ] build: Use AC_USE_SYSTEM_EXTENSIONS for POSIX/C extensions
From: Marcel Holtmann @ 2012-08-31 16:02 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: Anderson Lizardo, linux-bluetooth
In-Reply-To: <CAMOw1v7bbYbhL59-imjzppztpC+e9+enTWx4nnWeVAT0zjW4Ag@mail.gmail.com>

Hi Lucas,

> > On Thu, Aug 30, 2012 at 11:08 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> >> Hi Anderson,
> >>
> >>> Using this macro in configure.ac enables certain extensions that BlueZ
> >>> currently depends on. The macro is recommended instead of defining
> >>> _GNU_SOURCE on each C file.
> >>
> >> what is the advantage of this. I am actually fine with using _GNU_SOURCE
> >> in the C files. It is according to the man pages.
> >
> > The only advantage I see is that we don't have to worry about
> > reviewing these defines as the symbols get incorporated in newer
> > standards. For instance, this patch was brought up because O_CLOEXEC
> > does not exist on POSIX.1-2001, but was incorporated POSIX.1-2008, so
> > for newer systems _GNU_SOURCE is not necessary for it anymore, but for
> > some (still maintained) distros it is.
> >
> > Sometimes we remove code that used these extensions, and simply forget
> > the _GNU_SOURCE there as well.
> 
> And also forget to add it. Then 3 months later comes a patch to fix it
> by adding the definition.
> 
> Using the autofoo macro we stop the build-fix patches for things like this.
> 
> 
> That is: it removes code, it's more future-proof and it has no
> downsides. So, what's the point of not using it?

unless that autoconf thing breaks and we don't get what we want. Or we
are dealing with an outdated autoconf.

I am against this. I rather get build fixes and have them recorded in
git compared to hoping that this magically fixes everything.

> Some months ago I sent a patch to also remove a lot of dumb "#include
> config.h". It has the same reasoning behind it: remove code and be
> more future-proof. It was for connman, but if you are interested I can
> send it to bluez/ofono/etc too -
> http://permalink.gmane.org/gmane.linux.network.connman/7310

Same thing. I believe that boilerplate is better being explicit than
magically having it done.

Regards

Marcel



^ permalink raw reply

* Re: [RFC v2 15/15] hciemu: Fix build errors due to unaligned memory access
From: Anderson Lizardo @ 2012-08-31 15:19 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1346416811-23484-16-git-send-email-szymon.janc@tieto.com>

Hi  Szymon,

On Fri, Aug 31, 2012 at 8:40 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> --- a/test/hciemu.c
> +++ b/test/hciemu.c
> @@ -426,8 +426,10 @@ static void num_completed_pkts(struct vhci_conn *conn)
>         np = (void *) ptr; ptr += EVT_NUM_COMP_PKTS_SIZE;
>         np->num_hndl = 1;
>
> -       *((uint16_t *) ptr) = htobs(conn->handle); ptr += 2;
> -       *((uint16_t *) ptr) = htobs(vdev.acl_cnt); ptr += 2;
> +       bt_put_be16(conn->handle, ptr);
> +       ptr += 2;
> +       bt_put_be16(vdev.acl_cnt, ptr);
> +       ptr += 2;

These should be bt_put_le16().

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* [PATCH] gatt: Fix whitespace in UUID definitions
From: Andrzej Kaczmarek @ 2012-08-31 14:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

---
 attrib/gatt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/attrib/gatt.h b/attrib/gatt.h
index a15e92f..6bb6f0f 100644
--- a/attrib/gatt.h
+++ b/attrib/gatt.h
@@ -46,8 +46,8 @@
 #define GATT_CHARAC_FMT_UUID		0x2904
 #define GATT_CHARAC_AGREG_FMT_UUID	0x2905
 #define GATT_CHARAC_VALID_RANGE_UUID	0x2906
-#define GATT_EXTERNAL_REPORT_REFERENCE  0x2907
-#define GATT_REPORT_REFERENCE           0x2908
+#define GATT_EXTERNAL_REPORT_REFERENCE	0x2907
+#define GATT_REPORT_REFERENCE		0x2908
 
 /* Client Characteristic Configuration bit field */
 #define GATT_CLIENT_CHARAC_CFG_NOTIF_BIT	0x0001
-- 
1.7.11.3


^ permalink raw reply related

* [RFC v3] adaptername: Refactor handle_inotify_cb
From: Szymon Janc @ 2012-08-31 14:29 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo, Szymon Janc
In-Reply-To: <1346416811-23484-13-git-send-email-szymon.janc@tieto.com>

Refactor handle_inotify_cb to avoid unaligned memory access.
Instead of reading whole events buffer and cast to event struct when
iterating over it, read data directly to struct inotify_event one
event at time.

This fix following build error on ARM.

  CC     plugins/bluetoothd-adaptername.o
plugins/adaptername.c: In function handle_inotify_cb:
plugins/adaptername.c:244:34: error: cast increases required alignment
	of target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [plugins/bluetoothd-adaptername.o] Error 1
make: *** [all] Error 2

---
 plugins/adaptername.c |   48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index d3341b5..588c8db 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -45,8 +45,6 @@
 #include "log.h"
 
 #include <sys/inotify.h>
-#define EVENT_SIZE  (sizeof (struct inotify_event))
-#define EVENT_BUF_LEN (1024 * (EVENT_SIZE + 16))
 
 #define MACHINE_INFO_DIR "/etc/"
 #define MACHINE_INFO_FILE "machine-info"
@@ -226,38 +224,40 @@ static int adaptername_probe(struct btd_adapter *adapter)
 static gboolean handle_inotify_cb(GIOChannel *channel, GIOCondition cond,
 								gpointer data)
 {
-	char buf[EVENT_BUF_LEN];
+	struct inotify_event event;
+	gsize len;
 	GIOStatus err;
-	gsize len, i;
-	gboolean changed;
+	char name[FILENAME_MAX + 1];
 
-	changed = FALSE;
+	while ((err = g_io_channel_read_chars(channel, (gchar *)&event,
+			sizeof(event), &len, NULL)) != G_IO_STATUS_AGAIN) {
+		if (err != G_IO_STATUS_NORMAL || len != sizeof(event) ||
+				event.len > sizeof(name))
+			goto fail;
 
-	err = g_io_channel_read_chars(channel, buf, EVENT_BUF_LEN, &len, NULL);
-	if (err != G_IO_STATUS_NORMAL) {
-		error("Error reading inotify event: %d\n", err);
-		return FALSE;
-	}
+		if (event.len == 0)
+			continue;
 
-	i = 0;
-	while (i < len) {
-		struct inotify_event *pevent = (struct inotify_event *) &buf[i];
+		err = g_io_channel_read_chars(channel, name, event.len, &len,
+									NULL);
 
-		/* check that it's ours */
-		if (pevent->len && pevent->name != NULL &&
-				strcmp(pevent->name, MACHINE_INFO_FILE) == 0)
-			changed = TRUE;
+		if (err != G_IO_STATUS_NORMAL || len != event.len)
+			goto fail;
 
-		i += EVENT_SIZE + pevent->len;
-	}
+		if (strncmp(name, MACHINE_INFO_FILE, event.len) == 0) {
+			DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
+					" changed, updating adapters' names");
 
-	if (changed != FALSE) {
-		DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
-				" changed, changing names for adapters");
-		manager_foreach_adapter((adapter_cb) adaptername_probe, NULL);
+			manager_foreach_adapter((adapter_cb) adaptername_probe,
+									NULL);
+			break;
+		}
 	}
 
 	return TRUE;
+fail:
+	error("Error reading inotify event");
+	return FALSE;
 }
 
 static void adaptername_remove(struct btd_adapter *adapter)
-- 
1.7.9.5


^ permalink raw reply related

* Re: [RFC v2 12/15] adaptername: Refactor handle_inotify_cb
From: Szymon Janc @ 2012-08-31 14:25 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CAJdJm_NNYAHHVrr-uj97h7FEL0XatL5PuLnpOri6An4c-bz=mw@mail.gmail.com>

On Friday 31 of August 2012 16:19:28 Anderson Lizardo wrote:
> Hi Szymon,

Hi Anderson,

> 
> On Fri, Aug 31, 2012 at 8:40 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> > @@ -226,35 +226,41 @@ static int adaptername_probe(struct btd_adapter *adapter)
> >  static gboolean handle_inotify_cb(GIOChannel *channel, GIOCondition cond,
> >                                                                 gpointer data)
> >  {
> > -       char buf[EVENT_BUF_LEN];
> 
> Looks like EVENT_SIZE and EVENT_BUF_LEN defines are not used anymore
> so they can be removed.

Yeap, will remove it.

> 
> > +               err = g_io_channel_read_chars(channel, name, event.len, &len,
> > +                                                                       NULL);
> 
> No need to check for event.len <= FILENAME_MAX before the
> *read_chars() call ? (I don't know inotify, so I'm not sure about the
> allowed limits here)

Well, data is a file name which can't be > FILENAME_MAX+1. We would have to receive
some invalid data from kernel for that to happen... can we trust data from kernel?:)

So I'm also not sure if we really needs to validate that data...
This is what I've found in inotify-tools code about that situation:
  // oh... no.  this can't be happening.  An incomplete event.
  // Copy what we currently have into first element, call self to
  // read remainder.
  // oh, and they BETTER NOT overlap.
  // Boy I hope this code works.
  // But I think this can never happen due to how inotify is written.
They try to recover from that but if events overlap it is fubared anyway..

> 
> Or maybe using sizeof(name) instead of event.len ?

We can receive more events at once, so with that we could read name + part of next
inotify_event.

> 
> > +               if (err != G_IO_STATUS_NORMAL) {
> > +                       error("Error reading inotify event: %d", err);
> > +                       return FALSE;
> > +               }
> 
> Is it necessary to check whether event.len == len here ?

As above, this should not happen... but I'll move error reporting code into label
(to keep loop code short) and check for those anyway...

> 
> Otherwise a short read may not have the necessary "\0" for the
> strcmp() (but see below).
> 
> >
> > -               i += EVENT_SIZE + pevent->len;
> > -       }
> > +               if (strcmp(name, MACHINE_INFO_FILE) != 0)
> > +                       continue;
> 
> What about using strncmp() just to be safe?

Will fix that.

> 
> >
> > -       if (changed != FALSE) {
> >                 DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
> >                                 " changed, changing names for adapters");
> > +
> >                 manager_foreach_adapter((adapter_cb) adaptername_probe, NULL);
> > +               break;
> 
> what about having " if (strcmp(name, MACHINE_INFO_FILE) == 0) " and
> moving the code above to inside the if() ? The "unconditional" break
> at the end of the while() looks strange IMHO.

Wanted to keep indentation low, but yes, this might look strange.

> 
> >         }
> >
> >         return TRUE;
> 
> Regards,
> 

I'll send V3 in a moment.
Thanks for comments!

-- 
BR
Szymon Janc



^ permalink raw reply

* [PATCHv2] Bluetooth: Remove unneeded zero init
From: Andrei Emeltchenko @ 2012-08-31 13:39 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1346339195.23377.8.camel@aeonflux>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

hdev is allocated with kzalloc so zero initialization is not needed.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 include/net/bluetooth/hci_core.h |    9 ---------
 net/bluetooth/hci_core.c         |    2 +-
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 7542af4..4704ca4 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -428,15 +428,6 @@ static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
 }
 
-static inline void hci_conn_hash_init(struct hci_dev *hdev)
-{
-	struct hci_conn_hash *h = &hdev->conn_hash;
-	INIT_LIST_HEAD(&h->list);
-	h->acl_num = 0;
-	h->sco_num = 0;
-	h->le_num = 0;
-}
-
 static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
 {
 	struct hci_conn_hash *h = &hdev->conn_hash;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 28bab9d..8dbbc01 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1652,6 +1652,7 @@ struct hci_dev *hci_alloc_dev(void)
 	INIT_LIST_HEAD(&hdev->link_keys);
 	INIT_LIST_HEAD(&hdev->long_term_keys);
 	INIT_LIST_HEAD(&hdev->remote_oob_data);
+	INIT_LIST_HEAD(&hdev->conn_hash.list);
 
 	INIT_WORK(&hdev->rx_work, hci_rx_work);
 	INIT_WORK(&hdev->cmd_work, hci_cmd_work);
@@ -1674,7 +1675,6 @@ struct hci_dev *hci_alloc_dev(void)
 
 	hci_init_sysfs(hdev);
 	discovery_init(hdev);
-	hci_conn_hash_init(hdev);
 
 	return hdev;
 }
-- 
1.7.9.5


^ permalink raw reply related

* Re: [RFC v2 12/15] adaptername: Refactor handle_inotify_cb
From: Anderson Lizardo @ 2012-08-31 13:19 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1346416811-23484-13-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Fri, Aug 31, 2012 at 8:40 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> @@ -226,35 +226,41 @@ static int adaptername_probe(struct btd_adapter *adapter)
>  static gboolean handle_inotify_cb(GIOChannel *channel, GIOCondition cond,
>                                                                 gpointer data)
>  {
> -       char buf[EVENT_BUF_LEN];

Looks like EVENT_SIZE and EVENT_BUF_LEN defines are not used anymore
so they can be removed.

> +               err = g_io_channel_read_chars(channel, name, event.len, &len,
> +                                                                       NULL);

No need to check for event.len <= FILENAME_MAX before the
*read_chars() call ? (I don't know inotify, so I'm not sure about the
allowed limits here)

Or maybe using sizeof(name) instead of event.len ?

> +               if (err != G_IO_STATUS_NORMAL) {
> +                       error("Error reading inotify event: %d", err);
> +                       return FALSE;
> +               }

Is it necessary to check whether event.len == len here ?

Otherwise a short read may not have the necessary "\0" for the
strcmp() (but see below).

>
> -               i += EVENT_SIZE + pevent->len;
> -       }
> +               if (strcmp(name, MACHINE_INFO_FILE) != 0)
> +                       continue;

What about using strncmp() just to be safe?

>
> -       if (changed != FALSE) {
>                 DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
>                                 " changed, changing names for adapters");
> +
>                 manager_foreach_adapter((adapter_cb) adaptername_probe, NULL);
> +               break;

what about having " if (strcmp(name, MACHINE_INFO_FILE) == 0) " and
moving the code above to inside the if() ? The "unconditional" break
at the end of the while() looks strange IMHO.

>         }
>
>         return TRUE;

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* [PATCH 7/7] proximity: Remove reporter_adapter
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

reporter_adapter holds only reference to btd_adapter so it's useless now.
---
 profiles/proximity/reporter.c | 65 +++----------------------------------------
 1 file changed, 4 insertions(+), 61 deletions(-)

diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index cf52548..c331d17 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -49,34 +49,6 @@
 #include "linkloss.h"
 #include "immalert.h"
 
-struct reporter_adapter {
-	struct btd_adapter *adapter;
-};
-
-static GSList *reporter_adapters;
-
-static int radapter_cmp(gconstpointer a, gconstpointer b)
-{
-	const struct reporter_adapter *radapter = a;
-	const struct btd_adapter *adapter = b;
-
-	if (radapter->adapter == adapter)
-		return 0;
-
-	return -1;
-}
-
-static struct reporter_adapter *
-find_reporter_adapter(struct btd_adapter *adapter)
-{
-	GSList *l = g_slist_find_custom(reporter_adapters, adapter,
-								radapter_cmp);
-	if (!l)
-		return NULL;
-
-	return l->data;
-}
-
 const char *get_alert_level_string(uint8_t level)
 {
 	switch (level) {
@@ -188,9 +160,8 @@ static const GDBusSignalTable reporter_signals[] = {
 	{ }
 };
 
-static void unregister_reporter_device(gpointer data, gpointer user_data)
+static void unregister_reporter_device(struct btd_device *device)
 {
-	struct btd_device *device = data;
 	const char *path = device_get_path(device);
 
 	DBG("unregister on device %s", path);
@@ -201,8 +172,7 @@ static void unregister_reporter_device(gpointer data, gpointer user_data)
 	btd_device_unref(device);
 }
 
-static void register_reporter_device(struct btd_device *device,
-					struct reporter_adapter *radapter)
+static void register_reporter_device(struct btd_device *device)
 {
 	const char *path = device_get_path(device);
 
@@ -218,41 +188,21 @@ static void register_reporter_device(struct btd_device *device,
 
 int reporter_device_probe(struct btd_device *device, GSList *uuids)
 {
-	struct reporter_adapter *radapter;
-	struct btd_adapter *adapter = device_get_adapter(device);
-
-	radapter = find_reporter_adapter(adapter);
-	if (!radapter)
-		return -1;
-
-	register_reporter_device(device, radapter);
+	register_reporter_device(device);
 	return 0;
 }
 
 void reporter_device_remove(struct btd_device *device)
 {
-	struct reporter_adapter *radapter;
-	struct btd_adapter *adapter = device_get_adapter(device);
-
-	radapter = find_reporter_adapter(adapter);
-	if (!radapter)
-		return;
-
-	unregister_reporter_device(device, radapter);
+	unregister_reporter_device(device);
 }
 
 int reporter_adapter_probe(struct btd_adapter *adapter)
 {
-	struct reporter_adapter *radapter;
-
-	radapter = g_new0(struct reporter_adapter, 1);
-	radapter->adapter = adapter;
-
 	link_loss_register(adapter);
 	register_tx_power(adapter);
 	imm_alert_register(adapter);
 
-	reporter_adapters = g_slist_prepend(reporter_adapters, radapter);
 	DBG("Proximity Reporter for adapter %p", adapter);
 
 	return 0;
@@ -260,13 +210,6 @@ int reporter_adapter_probe(struct btd_adapter *adapter)
 
 void reporter_adapter_remove(struct btd_adapter *adapter)
 {
-	struct reporter_adapter *radapter = find_reporter_adapter(adapter);
-	if (!radapter)
-		return;
-
 	link_loss_unregister(adapter);
 	imm_alert_unregister(adapter);
-
-	reporter_adapters = g_slist_remove(reporter_adapters, radapter);
-	g_free(radapter);
 }
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 6/7] proximity: Remove list of adapter devices
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

List of adapter devices is only used to remove them when adapter is removed.
There's no need to do this since devices will be removed before adapter is
removed anyway.
---
 profiles/proximity/reporter.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 9b430f7..cf52548 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -51,7 +51,6 @@
 
 struct reporter_adapter {
 	struct btd_adapter *adapter;
-	GSList *devices;
 };
 
 static GSList *reporter_adapters;
@@ -192,7 +191,6 @@ static const GDBusSignalTable reporter_signals[] = {
 static void unregister_reporter_device(gpointer data, gpointer user_data)
 {
 	struct btd_device *device = data;
-	struct reporter_adapter *radapter = user_data;
 	const char *path = device_get_path(device);
 
 	DBG("unregister on device %s", path);
@@ -200,7 +198,6 @@ static void unregister_reporter_device(gpointer data, gpointer user_data)
 	g_dbus_unregister_interface(get_dbus_connection(), path,
 					PROXIMITY_REPORTER_INTERFACE);
 
-	radapter->devices = g_slist_remove(radapter->devices, device);
 	btd_device_unref(device);
 }
 
@@ -217,7 +214,6 @@ static void register_reporter_device(struct btd_device *device,
 					NULL, device, NULL);
 
 	btd_device_ref(device);
-	radapter->devices = g_slist_prepend(radapter->devices, device);
 }
 
 int reporter_device_probe(struct btd_device *device, GSList *uuids)
@@ -268,9 +264,6 @@ void reporter_adapter_remove(struct btd_adapter *adapter)
 	if (!radapter)
 		return;
 
-	g_slist_foreach(radapter->devices, unregister_reporter_device,
-								radapter);
-
 	link_loss_unregister(adapter);
 	imm_alert_unregister(adapter);
 
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 5/7] proximity: Remove unnecessary check for GATT enabled
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

Proximity plugin won't be loaded if GATT is disabled so there's no point in
checking this once more when adapter is probed.
---
 profiles/proximity/reporter.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index c221fae..9b430f7 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -249,11 +249,6 @@ int reporter_adapter_probe(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter;
 
-	if (!main_opts.gatt_enabled) {
-		DBG("GATT is disabled");
-		return -ENOTSUP;
-	}
-
 	radapter = g_new0(struct reporter_adapter, 1);
 	radapter->adapter = adapter;
 
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 4/7] proximity: Move reporter device driver registration to manager
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

Device driver for reporter is registered each time new adapter is probed
so in case multiple adapters are used it will be registered multiple
times for no reason.

This patch moves reporter device driver registration to manager so it
is registered only once, when plugin is loaded.
---
 profiles/proximity/manager.c  | 21 +++++++++++++++++++--
 profiles/proximity/reporter.c | 16 ++--------------
 profiles/proximity/reporter.h |  3 +++
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index 97e9795..4998a9e 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -85,6 +85,15 @@ static struct btd_device_driver monitor_driver = {
 	.remove = attio_device_remove,
 };
 
+
+/* device driver for tracking remote GATT client devices */
+static struct btd_device_driver reporter_device_driver = {
+	.name = "Proximity GATT Reporter Device Tracker Driver",
+	.uuids = BTD_UUIDS(GATT_UUID),
+	.probe = reporter_device_probe,
+	.remove = reporter_device_remove,
+};
+
 static struct btd_adapter_driver reporter_server_driver = {
 	.name = "Proximity GATT Reporter Driver",
 	.probe = reporter_adapter_probe,
@@ -123,13 +132,20 @@ int proximity_manager_init(GKeyFile *config)
 	if (ret < 0)
 		goto fail_monitor;
 
+	ret = btd_register_device_driver(&reporter_device_driver);
+	if (ret < 0)
+		goto fail_reporter_device;
+
 	ret = btd_register_adapter_driver(&reporter_server_driver);
 	if (ret < 0)
-		goto fail_reporter;
+		goto fail_reporter_server;
 
 	return 0;
 
-fail_reporter:
+fail_reporter_server:
+	btd_unregister_device_driver(&reporter_device_driver);
+
+fail_reporter_device:
 	btd_unregister_device_driver(&monitor_driver);
 
 fail_monitor:
@@ -139,5 +155,6 @@ fail_monitor:
 void proximity_manager_exit(void)
 {
 	btd_unregister_device_driver(&monitor_driver);
+	btd_unregister_device_driver(&reporter_device_driver);
 	btd_unregister_adapter_driver(&reporter_server_driver);
 }
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index ff9fd0c..c221fae 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -220,7 +220,7 @@ static void register_reporter_device(struct btd_device *device,
 	radapter->devices = g_slist_prepend(radapter->devices, device);
 }
 
-static int reporter_device_probe(struct btd_device *device, GSList *uuids)
+int reporter_device_probe(struct btd_device *device, GSList *uuids)
 {
 	struct reporter_adapter *radapter;
 	struct btd_adapter *adapter = device_get_adapter(device);
@@ -233,7 +233,7 @@ static int reporter_device_probe(struct btd_device *device, GSList *uuids)
 	return 0;
 }
 
-static void reporter_device_remove(struct btd_device *device)
+void reporter_device_remove(struct btd_device *device)
 {
 	struct reporter_adapter *radapter;
 	struct btd_adapter *adapter = device_get_adapter(device);
@@ -245,14 +245,6 @@ static void reporter_device_remove(struct btd_device *device)
 	unregister_reporter_device(device, radapter);
 }
 
-/* device driver for tracking remote GATT client devices */
-static struct btd_device_driver reporter_device_driver = {
-	.name = "Proximity GATT Reporter Device Tracker Driver",
-	.uuids = BTD_UUIDS(GATT_UUID),
-	.probe = reporter_device_probe,
-	.remove = reporter_device_remove,
-};
-
 int reporter_adapter_probe(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter;
@@ -269,8 +261,6 @@ int reporter_adapter_probe(struct btd_adapter *adapter)
 	register_tx_power(adapter);
 	imm_alert_register(adapter);
 
-	btd_register_device_driver(&reporter_device_driver);
-
 	reporter_adapters = g_slist_prepend(reporter_adapters, radapter);
 	DBG("Proximity Reporter for adapter %p", adapter);
 
@@ -283,8 +273,6 @@ void reporter_adapter_remove(struct btd_adapter *adapter)
 	if (!radapter)
 		return;
 
-	btd_unregister_device_driver(&reporter_device_driver);
-
 	g_slist_foreach(radapter->devices, unregister_reporter_device,
 								radapter);
 
diff --git a/profiles/proximity/reporter.h b/profiles/proximity/reporter.h
index ae5ddf6..c77c3af 100644
--- a/profiles/proximity/reporter.h
+++ b/profiles/proximity/reporter.h
@@ -36,6 +36,9 @@ enum {
 	HIGH_ALERT = 0x02,
 };
 
+int reporter_device_probe(struct btd_device *device, GSList *uuids);
+void reporter_device_remove(struct btd_device *device);
+
 int reporter_adapter_probe(struct btd_adapter *adapter);
 void reporter_adapter_remove(struct btd_adapter *adapter);
 
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 3/7] proximity: Simplify DBusConnection object usage
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

DBusConnection object can be obtained at any time by get_dbus_connection() call
so there is no need to pass and store it across profile code. Also there's no
need to ref/unref this object as by design it will live for entire lifetime of
plugin.
---
 profiles/proximity/immalert.c |  9 ++-------
 profiles/proximity/immalert.h |  2 +-
 profiles/proximity/linkloss.c |  8 ++------
 profiles/proximity/linkloss.h |  2 +-
 profiles/proximity/main.c     | 10 +---------
 profiles/proximity/manager.c  | 13 +++----------
 profiles/proximity/manager.h  |  2 +-
 profiles/proximity/monitor.c  | 20 +++++++++-----------
 profiles/proximity/monitor.h  |  8 ++++----
 profiles/proximity/reporter.c | 16 ++++------------
 10 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/profiles/proximity/immalert.c b/profiles/proximity/immalert.c
index 1540b61..f4061bc 100644
--- a/profiles/proximity/immalert.c
+++ b/profiles/proximity/immalert.c
@@ -46,7 +46,6 @@
 
 struct imm_alert_adapter {
 	struct btd_adapter *adapter;
-	DBusConnection *conn;
 	GSList *connected_devices;
 };
 
@@ -125,19 +124,17 @@ const char *imm_alert_get_level(struct btd_device *device)
 static void imm_alert_emit_alert_signal(struct connected_device *condev,
 							uint8_t alert_level)
 {
-	struct imm_alert_adapter *adapter;
 	const char *path, *alert_level_str;
 
 	if (!condev)
 		return;
 
-	adapter = condev->adapter;
 	path = device_get_path(condev->device);
 	alert_level_str = get_alert_level_string(alert_level);
 
 	DBG("alert %s remote %s", alert_level_str, path);
 
-	emit_property_changed(adapter->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 			PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel",
 			DBUS_TYPE_STRING, &alert_level_str);
 }
@@ -233,7 +230,7 @@ set_error:
 	return ATT_ECODE_IO;
 }
 
-void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn)
+void imm_alert_register(struct btd_adapter *adapter)
 {
 	gboolean svc_added;
 	bt_uuid_t uuid;
@@ -243,7 +240,6 @@ void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn)
 
 	imadapter = g_new0(struct imm_alert_adapter, 1);
 	imadapter->adapter = adapter;
-	imadapter->conn = dbus_connection_ref(conn);
 
 	imm_alert_adapters = g_slist_append(imm_alert_adapters, imadapter);
 
@@ -283,7 +279,6 @@ void imm_alert_unregister(struct btd_adapter *adapter)
 
 	g_slist_foreach(imadapter->connected_devices, remove_condev_list_item,
 									NULL);
-	dbus_connection_unref(imadapter->conn);
 
 	imm_alert_adapters = g_slist_remove(imm_alert_adapters, imadapter);
 	g_free(imadapter);
diff --git a/profiles/proximity/immalert.h b/profiles/proximity/immalert.h
index dd28eaa..1a09fa9 100644
--- a/profiles/proximity/immalert.h
+++ b/profiles/proximity/immalert.h
@@ -21,6 +21,6 @@
  *
  */
 
-void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn);
+void imm_alert_register(struct btd_adapter *adapter);
 void imm_alert_unregister(struct btd_adapter *adapter);
 const char *imm_alert_get_level(struct btd_device *device);
diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 6ed568c..b6d01a6 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -47,7 +47,6 @@
 struct link_loss_adapter {
 	struct btd_adapter *adapter;
 	uint16_t alert_lvl_value_handle;
-	DBusConnection *conn;
 	GSList *connected_devices;
 };
 
@@ -126,7 +125,6 @@ const char *link_loss_get_alert_level(struct btd_device *device)
 
 static void link_loss_emit_alert_signal(struct connected_device *condev)
 {
-	struct link_loss_adapter *adapter = condev->adapter;
 	const char *alert_level_str, *path;
 
 	if (!condev->device)
@@ -137,7 +135,7 @@ static void link_loss_emit_alert_signal(struct connected_device *condev)
 
 	DBG("alert %s remote %s", alert_level_str, path);
 
-	emit_property_changed(adapter->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 			PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel",
 			DBUS_TYPE_STRING, &alert_level_str);
 }
@@ -273,7 +271,7 @@ set_error:
 	return ATT_ECODE_IO;
 }
 
-void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn)
+void link_loss_register(struct btd_adapter *adapter)
 {
 	gboolean svc_added;
 	bt_uuid_t uuid;
@@ -283,7 +281,6 @@ void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn)
 
 	lladapter = g_new0(struct link_loss_adapter, 1);
 	lladapter->adapter = adapter;
-	lladapter->conn = dbus_connection_ref(conn);
 
 	link_loss_adapters = g_slist_append(link_loss_adapters, lladapter);
 
@@ -329,7 +326,6 @@ void link_loss_unregister(struct btd_adapter *adapter)
 
 	g_slist_foreach(lladapter->connected_devices, remove_condev_list_item,
 			NULL);
-	dbus_connection_unref(lladapter->conn);
 
 	link_loss_adapters = g_slist_remove(link_loss_adapters, lladapter);
 	g_free(lladapter);
diff --git a/profiles/proximity/linkloss.h b/profiles/proximity/linkloss.h
index a7d83d0..0447def 100644
--- a/profiles/proximity/linkloss.h
+++ b/profiles/proximity/linkloss.h
@@ -21,6 +21,6 @@
  *
  */
 
-void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn);
+void link_loss_register(struct btd_adapter *adapter);
 void link_loss_unregister(struct btd_adapter *adapter);
 const char *link_loss_get_alert_level(struct btd_device *device);
diff --git a/profiles/proximity/main.c b/profiles/proximity/main.c
index 3d5d9b2..0f57511 100644
--- a/profiles/proximity/main.c
+++ b/profiles/proximity/main.c
@@ -36,7 +36,6 @@
 #include "manager.h"
 #include "hcid.h"
 
-static DBusConnection *connection = NULL;
 static GKeyFile *config = NULL;
 
 static GKeyFile *open_config_file(const char *file)
@@ -65,16 +64,10 @@ static int proximity_init(void)
 		return -ENOTSUP;
 	}
 
-	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-	if (connection == NULL)
-		return -EIO;
-
 	config = open_config_file(CONFIGDIR "/proximity.conf");
 
-	if (proximity_manager_init(connection, config) < 0) {
-		dbus_connection_unref(connection);
+	if (proximity_manager_init(config) < 0)
 		return -EIO;
-	}
 
 	return 0;
 }
@@ -88,7 +81,6 @@ static void proximity_exit(void)
 		g_key_file_free(config);
 
 	proximity_manager_exit();
-	dbus_connection_unref(connection);
 }
 
 BLUETOOTH_PLUGIN_DEFINE(proximity, VERSION,
diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index e382be1..97e9795 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -39,8 +39,6 @@
 #include "reporter.h"
 #include "manager.h"
 
-static DBusConnection *connection = NULL;
-
 static struct enabled enabled  = {
 	.linkloss = TRUE,
 	.pathloss = TRUE,
@@ -72,13 +70,12 @@ static int attio_device_probe(struct btd_device *device, GSList *uuids)
 	l = g_slist_find_custom(primaries, LINK_LOSS_UUID, primary_uuid_cmp);
 	linkloss = (l ? l->data : NULL);
 
-	return monitor_register(connection, device, linkloss, txpower,
-							immediate, &enabled);
+	return monitor_register(device, linkloss, txpower, immediate, &enabled);
 }
 
 static void attio_device_remove(struct btd_device *device)
 {
-	monitor_unregister(connection, device);
+	monitor_unregister(device);
 }
 
 static struct btd_device_driver monitor_driver = {
@@ -116,14 +113,12 @@ static void load_config_file(GKeyFile *config)
 	g_strfreev(list);
 }
 
-int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
+int proximity_manager_init(GKeyFile *config)
 {
 	int ret;
 
 	load_config_file(config);
 
-	connection = dbus_connection_ref(conn);
-
 	ret = btd_register_device_driver(&monitor_driver);
 	if (ret < 0)
 		goto fail_monitor;
@@ -138,7 +133,6 @@ fail_reporter:
 	btd_unregister_device_driver(&monitor_driver);
 
 fail_monitor:
-	dbus_connection_unref(connection);
 	return ret;
 }
 
@@ -146,5 +140,4 @@ void proximity_manager_exit(void)
 {
 	btd_unregister_device_driver(&monitor_driver);
 	btd_unregister_adapter_driver(&reporter_server_driver);
-	dbus_connection_unref(connection);
 }
diff --git a/profiles/proximity/manager.h b/profiles/proximity/manager.h
index b0fe7c8..e65c31d 100644
--- a/profiles/proximity/manager.h
+++ b/profiles/proximity/manager.h
@@ -22,5 +22,5 @@
  *
  */
 
-int proximity_manager_init(DBusConnection *conn, GKeyFile *conf);
+int proximity_manager_init(GKeyFile *conf);
 void proximity_manager_exit(void);
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index f22d6f4..ac9dae7 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -66,7 +66,6 @@ enum {
 struct monitor {
 	struct btd_device *device;
 	GAttrib *attrib;
-	DBusConnection *conn;
 	struct att_range *linkloss;
 	struct att_range *txpower;
 	struct att_range *immediate;
@@ -160,7 +159,7 @@ static void linkloss_written(guint8 status, const guint8 *pdu, guint16 plen,
 
 	DBG("Link Loss Alert Level written");
 
-	emit_property_changed(monitor->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 				PROXIMITY_INTERFACE, "LinkLossAlertLevel",
 				DBUS_TYPE_STRING, &monitor->linklosslevel);
 }
@@ -289,7 +288,7 @@ static gboolean immediate_timeout(gpointer user_data)
 
 	g_free(monitor->immediatelevel);
 	monitor->immediatelevel = g_strdup("none");
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 					"ImmediateAlertLevel", DBUS_TYPE_STRING,
 					&monitor->immediatelevel);
 
@@ -304,7 +303,7 @@ static void immediate_written(gpointer user_data)
 	g_free(monitor->fallbacklevel);
 	monitor->fallbacklevel = NULL;
 
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 				"ImmediateAlertLevel",
 				DBUS_TYPE_STRING, &monitor->immediatelevel);
 
@@ -390,7 +389,7 @@ static void attio_disconnected_cb(gpointer user_data)
 
 	g_free(monitor->immediatelevel);
 	monitor->immediatelevel = g_strdup("none");
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 					"ImmediateAlertLevel", DBUS_TYPE_STRING,
 					&monitor->immediatelevel);
 }
@@ -577,7 +576,6 @@ static void monitor_destroy(gpointer user_data)
 	if (monitor->attrib)
 		g_attrib_unref(monitor->attrib);
 
-	dbus_connection_unref(monitor->conn);
 	btd_device_unref(monitor->device);
 	g_free(monitor->linkloss);
 	g_free(monitor->immediate);
@@ -588,7 +586,7 @@ static void monitor_destroy(gpointer user_data)
 	g_free(monitor);
 }
 
-int monitor_register(DBusConnection *conn, struct btd_device *device,
+int monitor_register(struct btd_device *device,
 		struct gatt_primary *linkloss, struct gatt_primary *txpower,
 		struct gatt_primary *immediate, struct enabled *enabled)
 {
@@ -604,12 +602,11 @@ int monitor_register(DBusConnection *conn, struct btd_device *device,
 
 	monitor = g_new0(struct monitor, 1);
 	monitor->device = btd_device_ref(device);
-	monitor->conn = dbus_connection_ref(conn);
 	monitor->linklosslevel = (level ? : g_strdup("high"));
 	monitor->signallevel = g_strdup("unknown");
 	monitor->immediatelevel = g_strdup("none");
 
-	if (g_dbus_register_interface(conn, path,
+	if (g_dbus_register_interface(get_dbus_connection(), path,
 				PROXIMITY_INTERFACE,
 				monitor_methods, monitor_signals,
 				NULL, monitor, monitor_destroy) == FALSE) {
@@ -661,9 +658,10 @@ int monitor_register(DBusConnection *conn, struct btd_device *device,
 	return 0;
 }
 
-void monitor_unregister(DBusConnection *conn, struct btd_device *device)
+void monitor_unregister(struct btd_device *device)
 {
 	const char *path = device_get_path(device);
 
-	g_dbus_unregister_interface(conn, path, PROXIMITY_INTERFACE);
+	g_dbus_unregister_interface(get_dbus_connection(), path,
+							PROXIMITY_INTERFACE);
 }
diff --git a/profiles/proximity/monitor.h b/profiles/proximity/monitor.h
index b71363d..191b562 100644
--- a/profiles/proximity/monitor.h
+++ b/profiles/proximity/monitor.h
@@ -28,7 +28,7 @@ struct enabled {
 	gboolean findme;
 };
 
-int monitor_register(DBusConnection *conn, struct btd_device *device,
-		struct gatt_primary *linkloss, struct gatt_primary *txpower,
-		struct gatt_primary *immediate, struct enabled *enabled);
-void monitor_unregister(DBusConnection *conn, struct btd_device *device);
+int monitor_register(struct btd_device *device, struct gatt_primary *linkloss,
+		struct gatt_primary *txpower, struct gatt_primary *immediate,
+		struct enabled *enabled);
+void monitor_unregister(struct btd_device *device);
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index de3770a..ff9fd0c 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -50,7 +50,6 @@
 #include "immalert.h"
 
 struct reporter_adapter {
-	DBusConnection *conn;
 	struct btd_adapter *adapter;
 	GSList *devices;
 };
@@ -198,7 +197,7 @@ static void unregister_reporter_device(gpointer data, gpointer user_data)
 
 	DBG("unregister on device %s", path);
 
-	g_dbus_unregister_interface(radapter->conn, path,
+	g_dbus_unregister_interface(get_dbus_connection(), path,
 					PROXIMITY_REPORTER_INTERFACE);
 
 	radapter->devices = g_slist_remove(radapter->devices, device);
@@ -212,7 +211,7 @@ static void register_reporter_device(struct btd_device *device,
 
 	DBG("register on device %s", path);
 
-	g_dbus_register_interface(radapter->conn, path,
+	g_dbus_register_interface(get_dbus_connection(), path,
 					PROXIMITY_REPORTER_INTERFACE,
 					reporter_methods, reporter_signals,
 					NULL, device, NULL);
@@ -257,24 +256,18 @@ static struct btd_device_driver reporter_device_driver = {
 int reporter_adapter_probe(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter;
-	DBusConnection *conn;
 
 	if (!main_opts.gatt_enabled) {
 		DBG("GATT is disabled");
 		return -ENOTSUP;
 	}
 
-	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-	if (!conn)
-		return -1;
-
 	radapter = g_new0(struct reporter_adapter, 1);
 	radapter->adapter = adapter;
-	radapter->conn = conn;
 
-	link_loss_register(adapter, radapter->conn);
+	link_loss_register(adapter);
 	register_tx_power(adapter);
-	imm_alert_register(adapter, radapter->conn);
+	imm_alert_register(adapter);
 
 	btd_register_device_driver(&reporter_device_driver);
 
@@ -297,7 +290,6 @@ void reporter_adapter_remove(struct btd_adapter *adapter)
 
 	link_loss_unregister(adapter);
 	imm_alert_unregister(adapter);
-	dbus_connection_unref(radapter->conn);
 
 	reporter_adapters = g_slist_remove(reporter_adapters, radapter);
 	g_free(radapter);
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 2/7] proximity: Remove unused definitions
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

---
 profiles/proximity/linkloss.c | 2 --
 profiles/proximity/reporter.c | 2 --
 2 files changed, 4 deletions(-)

diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 14403cb..6ed568c 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -44,8 +44,6 @@
 #include "reporter.h"
 #include "linkloss.h"
 
-#define BLUEZ_SERVICE "org.bluez"
-
 struct link_loss_adapter {
 	struct btd_adapter *adapter;
 	uint16_t alert_lvl_value_handle;
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index a3a8c8a..de3770a 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -49,8 +49,6 @@
 #include "linkloss.h"
 #include "immalert.h"
 
-#define BLUEZ_SERVICE "org.bluez"
-
 struct reporter_adapter {
 	DBusConnection *conn;
 	struct btd_adapter *adapter;
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH 1/7] proximity: Change adapter driver function names
From: Andrzej Kaczmarek @ 2012-08-31 12:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1346417314-25109-1-git-send-email-andrzej.kaczmarek@tieto.com>

probe and remove suffixes better describe what these functions actually do.
---
 profiles/proximity/manager.c  | 4 ++--
 profiles/proximity/reporter.c | 4 ++--
 profiles/proximity/reporter.h | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index f2e49a6..e382be1 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -90,8 +90,8 @@ static struct btd_device_driver monitor_driver = {
 
 static struct btd_adapter_driver reporter_server_driver = {
 	.name = "Proximity GATT Reporter Driver",
-	.probe = reporter_init,
-	.remove = reporter_exit,
+	.probe = reporter_adapter_probe,
+	.remove = reporter_adapter_remove,
 };
 
 static void load_config_file(GKeyFile *config)
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 607de2b..a3a8c8a 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -256,7 +256,7 @@ static struct btd_device_driver reporter_device_driver = {
 	.remove = reporter_device_remove,
 };
 
-int reporter_init(struct btd_adapter *adapter)
+int reporter_adapter_probe(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter;
 	DBusConnection *conn;
@@ -286,7 +286,7 @@ int reporter_init(struct btd_adapter *adapter)
 	return 0;
 }
 
-void reporter_exit(struct btd_adapter *adapter)
+void reporter_adapter_remove(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter = find_reporter_adapter(adapter);
 	if (!radapter)
diff --git a/profiles/proximity/reporter.h b/profiles/proximity/reporter.h
index 5ae0eb2..ae5ddf6 100644
--- a/profiles/proximity/reporter.h
+++ b/profiles/proximity/reporter.h
@@ -36,7 +36,7 @@ enum {
 	HIGH_ALERT = 0x02,
 };
 
-int reporter_init(struct btd_adapter *adapter);
-void reporter_exit(struct btd_adapter *adapter);
+int reporter_adapter_probe(struct btd_adapter *adapter);
+void reporter_adapter_remove(struct btd_adapter *adapter);
 
 const char *get_alert_level_string(uint8_t level);
-- 
1.7.11.3


^ 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