linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Use reference counting of the device object while discovering services
@ 2010-11-10 21:55 Claudio Takahasi
  2010-11-10 21:56 ` [PATCH] Fix possible memory leak of the GIOChannel in the attribute server Claudio Takahasi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Claudio Takahasi @ 2010-11-10 21:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 attrib/client.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/attrib/client.c b/attrib/client.c
index 1f2c217..955e623 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -158,6 +158,7 @@ static void gatt_service_free(void *user_data)
 	g_slist_free(gatt->primary);
 	g_attrib_unref(gatt->attrib);
 	g_free(gatt->path);
+	btd_device_unref(gatt->dev);
 	g_free(gatt);
 }
 
@@ -1335,7 +1336,7 @@ int attrib_client_register(struct btd_device *device, int psm)
 	device_get_address(device, &dba);
 
 	gatt = g_new0(struct gatt_service, 1);
-	gatt->dev = device;
+	gatt->dev = btd_device_ref(device);
 	gatt->listen = FALSE;
 	gatt->path = g_strdup(path);
 	bacpy(&gatt->sba, &sba);
-- 
1.7.3.2


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

* [PATCH] Fix possible memory leak of the GIOChannel in the attribute server
  2010-11-10 21:55 [PATCH] Use reference counting of the device object while discovering services Claudio Takahasi
@ 2010-11-10 21:56 ` Claudio Takahasi
  2010-11-11 10:09   ` Johan Hedberg
  2010-11-10 21:56 ` [PATCH] Add a new configuration option to disable Low Energy support Claudio Takahasi
  2010-11-11 10:08 ` [PATCH] Use reference counting of the device object while discovering services Johan Hedberg
  2 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2010-11-10 21:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/attrib-server.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 1fc1c18..f644091 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -609,6 +609,20 @@ int attrib_server_init(void)
 		return -1;
 	}
 
+	record = server_record_new();
+	if (record == NULL) {
+		error("Unable to create GATT service record");
+		goto failed;
+	}
+
+	if (add_record_to_server(BDADDR_ANY, record) < 0) {
+		error("Failed to register GATT service record");
+		sdp_record_free(record);
+		goto failed;
+	}
+
+	sdp_handle = record->handle;
+
 	/* LE socket */
 	le_io = bt_io_listen(BT_IO_L2CAP, NULL, confirm_event,
 					NULL, NULL, &gerr,
@@ -623,21 +637,13 @@ int attrib_server_init(void)
 		/* Doesn't have LE support, continue */
 	}
 
-	record = server_record_new();
-	if (record == NULL) {
-		error("Unable to create GATT service record");
-		return -1;
-	}
-
-	if (add_record_to_server(BDADDR_ANY, record) < 0) {
-		error("Failed to register GATT service record");
-		sdp_record_free(record);
-		return -1;
-	}
+	return 0;
 
-	sdp_handle = record->handle;
+failed:
+	g_io_channel_unref(l2cap_io);
+	l2cap_io = NULL;
 
-	return 0;
+	return -1;
 }
 
 void attrib_server_exit(void)
-- 
1.7.3.2


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

* [PATCH] Add a new configuration option to disable Low Energy support
  2010-11-10 21:55 [PATCH] Use reference counting of the device object while discovering services Claudio Takahasi
  2010-11-10 21:56 ` [PATCH] Fix possible memory leak of the GIOChannel in the attribute server Claudio Takahasi
@ 2010-11-10 21:56 ` Claudio Takahasi
  2010-11-11  9:18   ` Johan Hedberg
  2010-11-11 10:08 ` [PATCH] Use reference counting of the device object while discovering services Johan Hedberg
  2 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2010-11-10 21:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Disable LE interleave discovery and attribute server over LE link.
Option required to force disabling Low energy support for LE capable
adapters.
---
 src/adapter.c       |    2 +-
 src/attrib-server.c |    4 ++++
 src/hcid.h          |    1 +
 src/main.c          |    7 +++++++
 src/main.conf       |    7 ++++++-
 5 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 31014e5..0741550 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2082,7 +2082,7 @@ static int adapter_setup(struct btd_adapter *adapter, const char *mode)
 	if (dev->features[7] & LMP_INQ_TX_PWR)
 		adapter_ops->read_inq_tx_pwr(adapter->dev_id);
 
-	if (dev->features[4] & LMP_LE) {
+	if (dev->features[4] & LMP_LE && main_opts.le) {
 		uint8_t simul = (dev->features[6] & LMP_LE_BREDR) ? 0x01 : 0x00;
 		err = adapter_ops->write_le_host(adapter->dev_id, 0x01, simul);
 		if (err < 0) {
diff --git a/src/attrib-server.c b/src/attrib-server.c
index f644091..375b731 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -40,6 +40,7 @@
 #include "glib-helper.h"
 #include "btio.h"
 #include "sdpd.h"
+#include "hcid.h"
 #include "att.h"
 #include "gattrib.h"
 
@@ -623,6 +624,9 @@ int attrib_server_init(void)
 
 	sdp_handle = record->handle;
 
+	if (!main_opts.le)
+		return 0;
+
 	/* LE socket */
 	le_io = bt_io_listen(BT_IO_L2CAP, NULL, confirm_event,
 					NULL, NULL, &gerr,
diff --git a/src/hcid.h b/src/hcid.h
index 48d489a..a9484a6 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -56,6 +56,7 @@ struct main_opts {
 	gboolean	name_resolv;
 	gboolean	debug_keys;
 	gboolean	attrib_server;
+	gboolean	le;
 
 	uint8_t		scan;
 	uint8_t		mode;
diff --git a/src/main.c b/src/main.c
index adbb374..9abdd60 100644
--- a/src/main.c
+++ b/src/main.c
@@ -222,6 +222,13 @@ static void parse_config(GKeyFile *config)
 	else
 		main_opts.attrib_server = boolean;
 
+	boolean = g_key_file_get_boolean(config, "General",
+						"EnableLE", &err);
+	if (err)
+		g_clear_error(&err);
+	else
+		main_opts.le = boolean;
+
 	main_opts.link_mode = HCI_LM_ACCEPT;
 
 	main_opts.link_policy = HCI_LP_RSWITCH | HCI_LP_SNIFF |
diff --git a/src/main.conf b/src/main.conf
index f92bf42..c03f135 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -56,6 +56,11 @@ NameResolving = true
 # that they were created for.
 DebugKeys = false
 
+# Enable Low Energy support if the dongle supports. Default is false.
+# Enable/Disable interleave discovery and attribute server over LE.
+EnableLE = false
+
 # Enable the GATT Attribute Server. Default is false, because it is only
-# useful for testing.
+# useful for testing. Attribute server is not enabled over LE if EnableLE
+# is false.
 AttributeServer = false
-- 
1.7.3.2


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

* Re: [PATCH] Add a new configuration option to disable Low Energy support
  2010-11-10 21:56 ` [PATCH] Add a new configuration option to disable Low Energy support Claudio Takahasi
@ 2010-11-11  9:18   ` Johan Hedberg
  2010-11-11 13:20     ` Claudio Takahasi
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Hedberg @ 2010-11-11  9:18 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Nov 10, 2010, Claudio Takahasi wrote:
> @@ -623,6 +624,9 @@ int attrib_server_init(void)
>  
>  	sdp_handle = record->handle;
>  
> +	if (!main_opts.le)
> +		return 0;
> +

If the option is called "le" it shouldn't affect GATT over BR/EDR, so I
think the check in attrib_server_init should only affect the LE socket
(or then rename the option to e.g. main.opts.attrib).

Johan

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

* Re: [PATCH] Use reference counting of the device object while discovering services
  2010-11-10 21:55 [PATCH] Use reference counting of the device object while discovering services Claudio Takahasi
  2010-11-10 21:56 ` [PATCH] Fix possible memory leak of the GIOChannel in the attribute server Claudio Takahasi
  2010-11-10 21:56 ` [PATCH] Add a new configuration option to disable Low Energy support Claudio Takahasi
@ 2010-11-11 10:08 ` Johan Hedberg
  2 siblings, 0 replies; 8+ messages in thread
From: Johan Hedberg @ 2010-11-11 10:08 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Nov 10, 2010, Claudio Takahasi wrote:
> ---
>  attrib/client.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)

Pushed upstream. Thanks.

Johan

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

* Re: [PATCH] Fix possible memory leak of the GIOChannel in the attribute server
  2010-11-10 21:56 ` [PATCH] Fix possible memory leak of the GIOChannel in the attribute server Claudio Takahasi
@ 2010-11-11 10:09   ` Johan Hedberg
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hedberg @ 2010-11-11 10:09 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, Nov 10, 2010, Claudio Takahasi wrote:
> ---
>  src/attrib-server.c |   32 +++++++++++++++++++-------------
>  1 files changed, 19 insertions(+), 13 deletions(-)

Pushed upstream. Thanks.

Johan

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

* Re: [PATCH] Add a new configuration option to disable Low Energy support
  2010-11-11  9:18   ` Johan Hedberg
@ 2010-11-11 13:20     ` Claudio Takahasi
  2010-11-11 13:30       ` Johan Hedberg
  0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2010-11-11 13:20 UTC (permalink / raw)
  To: Claudio Takahasi, linux-bluetooth

Hi Johan,

On Thu, Nov 11, 2010 at 7:18 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Claudio,
>
> On Wed, Nov 10, 2010, Claudio Takahasi wrote:
>> @@ -623,6 +624,9 @@ int attrib_server_init(void)
>>
>>       sdp_handle = record->handle;
>>
>> +     if (!main_opts.le)
>> +             return 0;
>> +
>
> If the option is called "le" it shouldn't affect GATT over BR/EDR, so I
> think the check in attrib_server_init should only affect the LE socket
> (or then rename the option to e.g. main.opts.attrib).
>
> Johan
>


It is not affecting GATT over BR/EDR. bt_io_listen for BR/EDR is above
this checking.

My patch "[PATCH] Fix possible memory leak of the GIOChannel in the
attribute server" switched the order of the bt_io_listen calls between
BR/EDR and LE. I forgot to send these patches as patch sequence.

Claudio.

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

* Re: [PATCH] Add a new configuration option to disable Low Energy support
  2010-11-11 13:20     ` Claudio Takahasi
@ 2010-11-11 13:30       ` Johan Hedberg
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hedberg @ 2010-11-11 13:30 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

> > If the option is called "le" it shouldn't affect GATT over BR/EDR, so I
> > think the check in attrib_server_init should only affect the LE socket
> > (or then rename the option to e.g. main.opts.attrib).
> 
> It is not affecting GATT over BR/EDR. bt_io_listen for BR/EDR is above
> this checking.
> 
> My patch "[PATCH] Fix possible memory leak of the GIOChannel in the
> attribute server" switched the order of the bt_io_listen calls between
> BR/EDR and LE. I forgot to send these patches as patch sequence.

Ok, then it's fine. The patch is now pushed upstram.

Johan

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

end of thread, other threads:[~2010-11-11 13:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-10 21:55 [PATCH] Use reference counting of the device object while discovering services Claudio Takahasi
2010-11-10 21:56 ` [PATCH] Fix possible memory leak of the GIOChannel in the attribute server Claudio Takahasi
2010-11-11 10:09   ` Johan Hedberg
2010-11-10 21:56 ` [PATCH] Add a new configuration option to disable Low Energy support Claudio Takahasi
2010-11-11  9:18   ` Johan Hedberg
2010-11-11 13:20     ` Claudio Takahasi
2010-11-11 13:30       ` Johan Hedberg
2010-11-11 10:08 ` [PATCH] Use reference counting of the device object while discovering services Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).