Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH v6] Add ST-Ericsson CG2900 driver
From: Linus Walleij @ 2011-05-15 17:59 UTC (permalink / raw)
  To: Greg KH
  Cc: Par-Gunnar Hjalmdahl, devel, Mathieu Poirier,
	Par-Gunnar Hjalmdahl, Arnd Bergmann, Vitaly Wool, Marcel Holtmann,
	Greg Kroah-Hartman, linux-kernel, Lukasz Rymanowski,
	linux-bluetooth, Pavan Savoy, Lee Jones, Alan Cox
In-Reply-To: <20110515173644.GA18241@kroah.com>

2011/5/15 Greg KH <greg@kroah.com>:
> On Sun, May 15, 2011 at 07:29:04PM +0200, Linus Walleij wrote:
>> It was my recommendation to put it into staging, by doing this
>> people can talk about the architecture by submitting *patches*
>> to show how they want it instead of these fruitless discussions.
>>
>> So this should be a case where staging really helps, at least in
>> my dreams.
>
> Yes, that is where staging should help, hopefully we can get these build
> dependancies worked out to get this merged properly. =A0Perhaps for the
> .41 merge window?

Since one of the build dependencies is the GPIO rework that already
needed to be pushed from 2.6.40 to 2.6.41 due to shortage of
review power for drivers/gpio, and since I cannot merge the updates
to the current GPIO driver in arch/arm/plat-nomadik/gpio.c due to
the current ban on anything that grows arch/arm/* we will likely
have to postpone its merging to staging to 2.6.42.

Basically this driver has ended up in cross-subsystem dependency
hell :-)

But worse things have happened, and these are special times,
so let's let it rest for a while.

Linus Walleij

^ permalink raw reply

* Re: [PATCH v6] Add ST-Ericsson CG2900 driver
From: Greg KH @ 2011-05-15 17:36 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Par-Gunnar Hjalmdahl, devel, Mathieu Poirier,
	Par-Gunnar Hjalmdahl, Arnd Bergmann, Vitaly Wool, Marcel Holtmann,
	Greg Kroah-Hartman, linux-kernel, Lukasz Rymanowski,
	linux-bluetooth, Pavan Savoy, Lee Jones, Alan Cox
In-Reply-To: <BANLkTi=hN6NeLdXAjzeeYwcZR7+BoJ1BQg@mail.gmail.com>

On Sun, May 15, 2011 at 07:29:04PM +0200, Linus Walleij wrote:
> It was my recommendation to put it into staging, by doing this
> people can talk about the architecture by submitting *patches*
> to show how they want it instead of these fruitless discussions.
> 
> So this should be a case where staging really helps, at least in
> my dreams.

Yes, that is where staging should help, hopefully we can get these build
dependancies worked out to get this merged properly.  Perhaps for the
.41 merge window?

thanks,

greg k-h

^ permalink raw reply

* Re: [PATCH v6] Add ST-Ericsson CG2900 driver
From: Linus Walleij @ 2011-05-15 17:29 UTC (permalink / raw)
  To: Greg KH
  Cc: Par-Gunnar Hjalmdahl, devel, Mathieu Poirier,
	Par-Gunnar Hjalmdahl, Arnd Bergmann, Vitaly Wool, Marcel Holtmann,
	Greg Kroah-Hartman, linux-kernel, Lukasz Rymanowski,
	linux-bluetooth, Pavan Savoy, Lee Jones, Alan Cox
In-Reply-To: <20110515163257.GE1315@kroah.com>

2011/5/15 Greg KH <greg@kroah.com>:

> That's why you should only use staging as a last resort, not as your
> primary way of getting code into the kernel, especially for stuff with
> a constantly changing in-kernel interface like you have pointed out
> here.

Agree 100%

Trust me, we tried this already.

> Just do the "real work" first and get it merged the real way if at all
> possible.

This driver development has gone into statis due to conflicts and
endless discussions pertaining to the HCI transport layer
beneath it.

It was my recommendation to put it into staging, by doing this
people can talk about the architecture by submitting *patches*
to show how they want it instead of these fruitless discussions.

So this should be a case where staging really helps, at least in
my dreams.

Linus Walleij

^ permalink raw reply

* Re: [PATCH v6] Add ST-Ericsson CG2900 driver
From: Greg KH @ 2011-05-15 16:32 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Par-Gunnar Hjalmdahl, devel, Mathieu Poirier,
	Par-Gunnar Hjalmdahl, Arnd Bergmann, Vitaly Wool, Marcel Holtmann,
	Greg Kroah-Hartman, linux-kernel, Lukasz Rymanowski,
	linux-bluetooth, Pavan Savoy, Lee Jones, Alan Cox
In-Reply-To: <BANLkTinAtUQ8H1DQpqXxX_U4mLO617L3Eg@mail.gmail.com>

On Sun, May 15, 2011 at 12:20:51PM +0200, Linus Walleij wrote:
> 2011/5/10 Par-Gunnar Hjalmdahl <par-gunnar.p.hjalmdahl@stericsson.com>:
> 
> > Patch created on next-20110510.
> > Compared to v5 this patch has the following update:
> >  - Updated driver after changes to MFD interfaces in linux-next (from mfd_data
> >   to platform_data).
> >  - Changed platform specific file dependencies (included correct nomadik file).
> 
> Sorry I don't know if all this will work, it's due to all the churn created by
> the current push to get stuff out of the ARM tree so not much to do.
> 
> The Nomadik GPIO file was moved in next but I will take that code move
> out today, because the GPIO maintainer has told me he couldn't
> provide feedback on these patches in time for me to finalize the change
> for kernel 2.6.40. Thus it won't go into 2.6.40 and I must remove it
> from next.
> 
> The MFD changes will *probably* happen, if you're thinking about the
> PRCMU movement etc.
> 
> To merge into the staging tree right now, you need to base it off
> Gregs staging tree, which is where it'll be merged:
> http://git.kernel.org/?p=linux/kernel/git/gregkh/staging-2.6.git;a=summary
> 
> Sorry about all the confusion, I think it's actually nobodys fault,
> it's just reflecting the fact that embedded drivers with deep
> platform dependencies are *really* *hard* to manage in staging.

That's why you should only use staging as a last resort, not as your
primary way of getting code into the kernel, especially for stuff with
a constantly changing in-kernel interface like you have pointed out
here.

Just do the "real work" first and get it merged the real way if at all
possible.

best of luck,

greg k-h

^ permalink raw reply

* Re: [PATCH v2] Fix endian conversion for appparams in pbap client
From: Johan Hedberg @ 2011-05-15 11:49 UTC (permalink / raw)
  To: Bartosz Szatkowski; +Cc: linux-bluetooth
In-Reply-To: <1305455861-26395-1-git-send-email-bulislaw@linux.com>

Hi Bartosz,

On Sun, May 15, 2011, Bartosz Szatkowski wrote:
> ---
>  client/pbap.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/client/pbap.c b/client/pbap.c
> index 837419c..589b1ca 100644
> --- a/client/pbap.c
> +++ b/client/pbap.c
> @@ -312,7 +312,7 @@ static void read_return_apparam(struct session_data *session,
>  			if (hdr->len == PHONEBOOKSIZE_LEN) {
>  				guint16 val;
>  				memcpy(&val, hdr->val, sizeof(val));
> -				*phone_book_size = val;
> +				*phone_book_size = get_be16(&val);
>  			}
>  			break;
>  		case NEWMISSEDCALLS_TAG:

Pushed upstream. Thanks.

Johan

^ permalink raw reply

* [PATCH v2] Fix endian conversion for appparams in pbap client
From: Bartosz Szatkowski @ 2011-05-15 10:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bartosz Szatkowski

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

diff --git a/client/pbap.c b/client/pbap.c
index 837419c..589b1ca 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -312,7 +312,7 @@ static void read_return_apparam(struct session_data *session,
 			if (hdr->len == PHONEBOOKSIZE_LEN) {
 				guint16 val;
 				memcpy(&val, hdr->val, sizeof(val));
-				*phone_book_size = val;
+				*phone_book_size = get_be16(&val);
 			}
 			break;
 		case NEWMISSEDCALLS_TAG:
-- 
1.7.5.rc3


^ permalink raw reply related

* Re: [PATCH v6] Add ST-Ericsson CG2900 driver
From: Linus Walleij @ 2011-05-15 10:20 UTC (permalink / raw)
  To: Par-Gunnar Hjalmdahl
  Cc: Greg Kroah-Hartman, devel, linux-kernel, linux-bluetooth,
	Pavan Savoy, Vitaly Wool, Alan Cox, Arnd Bergmann,
	Marcel Holtmann, Lukasz Rymanowski, Par-Gunnar Hjalmdahl,
	Lee Jones, Mathieu Poirier
In-Reply-To: <1305040215-712-1-git-send-email-par-gunnar.p.hjalmdahl@stericsson.com>

2011/5/10 Par-Gunnar Hjalmdahl <par-gunnar.p.hjalmdahl@stericsson.com>:

> Patch created on next-20110510.
> Compared to v5 this patch has the following update:
> =A0- Updated driver after changes to MFD interfaces in linux-next (from m=
fd_data
> =A0 to platform_data).
> =A0- Changed platform specific file dependencies (included correct nomadi=
k file).

Sorry I don't know if all this will work, it's due to all the churn created=
 by
the current push to get stuff out of the ARM tree so not much to do.

The Nomadik GPIO file was moved in next but I will take that code move
out today, because the GPIO maintainer has told me he couldn't
provide feedback on these patches in time for me to finalize the change
for kernel 2.6.40. Thus it won't go into 2.6.40 and I must remove it
from next.

The MFD changes will *probably* happen, if you're thinking about the
PRCMU movement etc.

To merge into the staging tree right now, you need to base it off
Gregs staging tree, which is where it'll be merged:
http://git.kernel.org/?p=3Dlinux/kernel/git/gregkh/staging-2.6.git;a=3Dsumm=
ary

Sorry about all the confusion, I think it's actually nobodys fault,
it's just reflecting the fact that embedded drivers with deep
platform dependencies are *really* *hard* to manage in staging.
It works best for things like a standard-form driver on a local bus
(I2C, PCI, USB ...) without any bindings to a lot of platform stuff.

Maybe the device tree will fix all this. Sometime.

Yours,
Linus Walleij

^ permalink raw reply

* GSoC Introduction
From: Prasad Bhat @ 2011-05-15  7:08 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

My name is Prasad and I am a student at PESIT in India.
I will be implementing VDP as my GSoC project.

So far I have read and understand specification for VDP and AVDTP.
And I have been experimenting with GStreamer pipelines and plug-ins.
I will start the actual development from May 23rd.

Regards,
Prasad

^ permalink raw reply

* Re: [PATCH] Fix a crash when creating a device from storage
From: Johan Hedberg @ 2011-05-14 23:31 UTC (permalink / raw)
  To: Vinicius Costa Gomes; +Cc: linux-bluetooth
In-Reply-To: <1304963744-31282-1-git-send-email-vinicius.gomes@openbossa.org>

Hi Vinicius,

On Mon, May 09, 2011, Vinicius Costa Gomes wrote:
> The list "services" is just a list of the object paths of the
> registered services that a device has. When we want to store
> the primary services information we need to store the "primaries"
> list, that contain all the primary services information.
> ---
>  src/device.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Fix endian conversion for appparams in pbap client
From: Johan Hedberg @ 2011-05-14 23:30 UTC (permalink / raw)
  To: Bartosz Szatkowski; +Cc: linux-bluetooth
In-Reply-To: <1304877615-10038-1-git-send-email-bulislaw@linux.com>

Hi,

On Sun, May 08, 2011, Bartosz Szatkowski wrote:
> ---
>  client/pbap.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/client/pbap.c b/client/pbap.c
> index 837419c..dee85c8 100644
> --- a/client/pbap.c
> +++ b/client/pbap.c
> @@ -312,6 +312,7 @@ static void read_return_apparam(struct session_data *session,
>  			if (hdr->len == PHONEBOOKSIZE_LEN) {
>  				guint16 val;
>  				memcpy(&val, hdr->val, sizeof(val));
> +                                val = get_be16(&val);
>  				*phone_book_size = val;
>  			}
>  			break;

Two issues with this:

1. Fix your editor settings. You're using spaces instead of tabs for
indentation.

2. Why not do *phone_book_size = get_be16(&val); directly?

Johan

^ permalink raw reply

* Re: [PATCH] Remove unused DISC_* macros
From: Johan Hedberg @ 2011-05-14 23:27 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth
In-Reply-To: <1304706134-1262-1-git-send-email-andre.guedes@openbossa.org>

Hi André,

On Fri, May 06, 2011, Andre Guedes wrote:
> ---
>  src/adapter.h |    7 -------
>  1 files changed, 0 insertions(+), 7 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Remove unneeded list when removing a device driver
From: Johan Hedberg @ 2011-05-14 23:24 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1304627636-22358-3-git-send-email-claudio.takahasi@openbossa.org>

Hi Claudio,

On Thu, May 05, 2011, Claudio Takahasi wrote:
> ---
>  src/device.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/src/device.c b/src/device.c
> index b0a6542..694a3df 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -1168,7 +1168,7 @@ add_uuids:
>  static void device_remove_drivers(struct btd_device *device, GSList *uuids)
>  {
>  	struct btd_adapter *adapter = device_get_adapter(device);
> -	GSList *list, *next;
> +	GSList *list;
>  	char srcaddr[18], dstaddr[18];
>  	bdaddr_t src;
>  	sdp_list_t *records;
> @@ -1181,12 +1181,10 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
>  
>  	DBG("Removing drivers for %s", dstaddr);
>  
> -	for (list = device->drivers; list; list = next) {
> +	for (list = device->drivers; list; list = list->next) {
>  		struct btd_device_driver *driver = list->data;
>  		const char **uuid;
>  
> -		next = list->next;
> -
>  		for (uuid = driver->uuids; *uuid; uuid++) {
>  			if (!g_slist_find_custom(uuids, *uuid,
>  						(GCompareFunc) strcasecmp))

I don't think this change is necessarily safe. Since the loop is making
a callback to code that it doesn't control there's a risk that the
callback could end up freeing the current pointer.

Johan

^ permalink raw reply

* Re: [PATCH] Remove unnecessary headers from main.c
From: Johan Hedberg @ 2011-05-14 23:21 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1304627636-22358-2-git-send-email-claudio.takahasi@openbossa.org>

Hi Claudio,

On Thu, May 05, 2011, Claudio Takahasi wrote:
> ---
>  src/main.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Remove unused "scan" variable from main_opts
From: Johan Hedberg @ 2011-05-14 23:20 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth
In-Reply-To: <1304627636-22358-1-git-send-email-claudio.takahasi@openbossa.org>

Hi Claudio,

On Thu, May 05, 2011, Claudio Takahasi wrote:
> ---
>  src/hcid.h |    1 -
>  src/main.c |    1 -
>  2 files changed, 0 insertions(+), 2 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/5] Add length argument to hci pincode reply
From: Johan Hedberg @ 2011-05-14 23:18 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, hadess, padovan
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

Hi David,

On Thu, May 05, 2011, David Herrmann wrote:
> This adds a new "length" argument to the hci pincode reply to allow
> sending binary pins including \0 characters.
> ---
>  plugins/hciops.c  |   10 +++++-----
>  plugins/mgmtops.c |    9 ++++-----
>  src/adapter.c     |    3 ++-
>  src/adapter.h     |    3 ++-
>  4 files changed, 13 insertions(+), 12 deletions(-)

All patches in this set have been pushed upstream. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Update params description of PIN Code Request
From: Johan Hedberg @ 2011-05-14 23:13 UTC (permalink / raw)
  To: Waldemar Rymarkiewicz; +Cc: Marcel Holtmann, linux-bluetooth
In-Reply-To: <1304499240-4966-1-git-send-email-waldemar.rymarkiewicz@tieto.com>

Hi Waldek,

On Wed, May 04, 2011, Waldemar Rymarkiewicz wrote:
> ---
>  doc/mgmt-api.txt |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)

Pushed upstream. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/3] client: remove unused variable
From: Johan Hedberg @ 2011-05-14 23:12 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1304929298-1586-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, May 09, 2011, Luiz Augusto von Dentz wrote:
> ---
>  client/session.c |    3 ---
>  1 files changed, 0 insertions(+), 3 deletions(-)

All three patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/1] HID: Add full support for logitech Unifying receivers
From: Bastien Nocera @ 2011-05-14 20:10 UTC (permalink / raw)
  To: Nestor Lopez Casado
  Cc: jkosina, linux-input, xnlopez, rtitmuss, ogay, BlueZ development
In-Reply-To: <1305297084-10224-1-git-send-email-nlopezcasad@logitech.com>

Hey Nestor,

On Fri, 2011-05-13 at 16:31 +0200, Nestor Lopez Casado wrote:
> With this driver, all the devices paired to a single Unifying receiver are exposed to user processes in separated /input/dev nodes.
> Keyboards with different layouts can be treated differently
> Multiplayer games on single PC (like home theater PC) can differentiate input coming from different kbds paired to the same receiver
> 
> Up to now, when Logitech Unifying receivers are connected to a Linux based system, a single keyboard and a single mouse are presented to
> the HID Layer, even if the Unifying receiver can pair up to six compatible devices. The Unifying receiver by default multiplexes all
> incoming events (from multiple keyboards/mice) into these two.

I'm very happy to see Logitech taking notice of Linux and helping out
support their devices better. I wanted to know whether you had any
information about switching those devices into HCI mode (Bluetooth), and
details for how one would read and write Bluetooth link keys, to make
sure that devices that worked through the "Unifying receiver" carry on
working in Bluetooth mode.

Cheers


^ permalink raw reply

* [GSoC] Presentation
From: Bartosz Szatkowski @ 2011-05-13 21:57 UTC (permalink / raw)
  To: linux-bluetooth

Hi,
I've been asked to sent some introducing mail, so here it goes ;)

My name is Bartosz Szatkowski and I'm going to implement/extend EDS
(Evolution Data Server) backend for PBAP in obexd as my GSoC project.
As far I've managed to go thought PBAP spec, OBEX spec(partialy),
general EDS architecture and API, existing PBAP code (dummy, tracker
and existing EDS base). Also I've write small frontend for pbap-client
(there are some issues with pbap-client in obex-client -- I'v already
sent on patch and I'm checking other issues).

Main coding part starts at May 24 so I'll be in touch :)

-- 
Pozdrowienia,
Bartosz Szatkowski

^ permalink raw reply

* Re: [PATCH 6/9] Bluetooth: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
From: Gustavo F. Padovan @ 2011-05-13 21:06 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: linux-bluetooth, linux-kernel, netdev, Marcel Holtmann
In-Reply-To: <1305244212-19183-7-git-send-email-sboyd@codeaurora.org>

Hi Stephen,

* Stephen Boyd <sboyd@codeaurora.org> [2011-05-12 16:50:09 -0700]:

> Enabling DEBUG_STRICT_USER_COPY_CHECKS causes the following
> warning:
> 
> In function 'copy_from_user',
>     inlined from 'rfcomm_sock_setsockopt' at
>     net/bluetooth/rfcomm/sock.c:705:
> arch/x86/include/asm/uaccess_64.h:65:
> warning: call to 'copy_from_user_overflow' declared with
> attribute warning: copy_from_user() buffer size is not provably
> correct
> 
> presumably due to buf_size being signed causing GCC to fail to
> see that buf_size can't become negative.
> 
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Gustavo F. Padovan <padovan@profusion.mobi>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> ---
>  net/bluetooth/rfcomm/sock.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)

Applied, thanks.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH 02/12] Bluetooth: LE advertising cache
From: Gustavo F. Padovan @ 2011-05-13 19:33 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth
In-Reply-To: <1304701521-26459-3-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

* Andre Guedes <andre.guedes@openbossa.org> [2011-05-06 14:05:11 -0300]:

> This patch implements the LE advertising cache. It stores sensitive
> information (bdaddr and bdaddr_type so far) gathered from LE
> advertising report events.
> 
> Only advertising entries from connectables devices are added to the
> cache.
> 
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
>  include/net/bluetooth/hci_core.h |   13 +++++++
>  net/bluetooth/hci_core.c         |   74 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 87 insertions(+), 0 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 14cc324..65135f8 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -89,6 +89,12 @@ struct oob_data {
>  	u8 randomizer[16];
>  };
>  
> +struct adv_entry {
> +	struct list_head list;
> +	bdaddr_t bdaddr;
> +	u8 bdaddr_type;
> +};
> +
>  #define NUM_REASSEMBLY 4
>  struct hci_dev {
>  	struct list_head list;
> @@ -181,6 +187,8 @@ struct hci_dev {
>  
>  	struct list_head	remote_oob_data;
>  
> +	struct list_head	adv_entries;
> +
>  	struct hci_dev_stats	stat;
>  
>  	struct sk_buff_head	driver_init;
> @@ -526,6 +534,11 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
>  								u8 *randomizer);
>  int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
>  
> +int hci_adv_entries_clear(struct hci_dev *hdev);
> +struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
> +int hci_add_adv_entry(struct hci_dev *hdev,
> +					struct hci_ev_le_advertising_info *ev);

Rename this to hci_adv_add_entry()

> +
>  void hci_del_off_timer(struct hci_dev *hdev);
>  
>  void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index b6bda3f..0ba3c39 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1204,6 +1204,77 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
>  	return 0;
>  }
>  
> +int hci_adv_entries_clear(struct hci_dev *hdev)
> +{
> +	struct list_head *p, *n;
> +
> +	list_for_each_safe(p, n, &hdev->adv_entries) {

list_for_each_entry_safe() here.

> +		struct adv_entry *entry;
> +
> +		entry = list_entry(p, struct adv_entry, list);
> +
> +		list_del(p);
> +		kfree(entry);
> +	}
> +
> +	BT_DBG("%s adv cache cleared", hdev->name);
> +
> +	return 0;
> +}
> +
> +struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr)
> +{
> +	struct list_head *p;
> +
> +	list_for_each(p, &hdev->adv_entries) {

list_for_each_entry() here.

> +		struct adv_entry *entry;
> +
> +		entry = list_entry(p, struct adv_entry, list);
> +
> +		if (bacmp(bdaddr, &entry->bdaddr) == 0)
> +			return entry;
> +	}
> +
> +	return NULL;
> +}
> +
> +static inline int is_connectable_adv(u8 evt_type)
> +{
> +	if (evt_type == ADV_IND || evt_type == ADV_DIRECT_IND)
> +		return 1;
> +
> +	return 0;

You use this function just in one place, get rid of it.

> +}
> +
> +int hci_add_adv_entry(struct hci_dev *hdev,
> +					struct hci_ev_le_advertising_info *ev)
> +{
> +	struct adv_entry *entry;
> +
> +	if (!is_connectable_adv(ev->evt_type))
> +		return -EINVAL;
> +
> +	entry = hci_find_adv_entry(hdev, &ev->bdaddr);
> +	/* Only new entries should be added to adv_entries. So, if
> +	 * bdaddr was found, don't add it. */
> +	if (entry)
> +		return 0;

	if (hci_find_adv_entry())
		return 0;

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* [PATCH -v2 7/7] Bluetooth: Rename __l2cap_chan_close() to l2cap_chan_close()
From: Gustavo F. Padovan @ 2011-05-13 19:20 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1305314450-25493-7-git-send-email-padovan@profusion.mobi>

To make it consistent with the rest of the API.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 include/net/bluetooth/l2cap.h |    2 +-
 net/bluetooth/l2cap_core.c    |   29 ++++++++++++-----------------
 net/bluetooth/l2cap_sock.c    |    2 +-
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 1c89c7f..a2dcbff 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -464,7 +464,7 @@ struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
 							int proto, gfp_t prio);
 
 struct l2cap_chan *l2cap_chan_create(struct sock *sk);
-void __l2cap_chan_close(struct l2cap_chan *chan, int reason);
+void l2cap_chan_close(struct l2cap_chan *chan, int reason);
 void l2cap_chan_destroy(struct l2cap_chan *chan);
 int l2cap_chan_connect(struct l2cap_chan *chan);
 int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 1390d0b..c7eda36 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -250,7 +250,7 @@ static void l2cap_chan_timeout(unsigned long arg)
 	else
 		reason = ETIMEDOUT;
 
-	__l2cap_chan_close(chan, reason);
+	l2cap_chan_close(chan, reason);
 
 	bh_unlock_sock(sk);
 
@@ -383,16 +383,6 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
 	}
 }
 
-/* Must be called on unlocked socket. */
-static void l2cap_chan_close(struct sock *sk)
-{
-	l2cap_chan_clear_timer(l2cap_pi(sk)->chan);
-	lock_sock(sk);
-	__l2cap_chan_close(l2cap_pi(sk)->chan, ECONNRESET);
-	release_sock(sk);
-	l2cap_sock_kill(sk);
-}
-
 static void l2cap_chan_cleanup_listen(struct sock *parent)
 {
 	struct sock *sk;
@@ -400,14 +390,19 @@ static void l2cap_chan_cleanup_listen(struct sock *parent)
 	BT_DBG("parent %p", parent);
 
 	/* Close not yet accepted channels */
-	while ((sk = bt_accept_dequeue(parent, NULL)))
-		l2cap_chan_close(sk);
+	while ((sk = bt_accept_dequeue(parent, NULL))) {
+		l2cap_chan_clear_timer(l2cap_pi(sk)->chan);
+		lock_sock(sk);
+		l2cap_chan_close(l2cap_pi(sk)->chan, ECONNRESET);
+		release_sock(sk);
+		l2cap_sock_kill(sk);
+	}
 
 	parent->sk_state = BT_CLOSED;
 	sock_set_flag(parent, SOCK_ZAPPED);
 }
 
-void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
+void l2cap_chan_close(struct l2cap_chan *chan, int reason)
 {
 	struct l2cap_conn *conn = chan->conn;
 	struct sock *sk = chan->sk;
@@ -724,10 +719,10 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
 					conn->feat_mask)
 					&& chan->conf_state &
 					L2CAP_CONF_STATE2_DEVICE) {
-				/* __l2cap_chan_close() calls list_del(chan)
+				/* l2cap_chan_close() calls list_del(chan)
 				 * so release the lock */
 				read_unlock_bh(&conn->chan_lock);
-				 __l2cap_chan_close(chan, ECONNRESET);
+				 l2cap_chan_close(chan, ECONNRESET);
 				read_lock_bh(&conn->chan_lock);
 				bh_unlock_sock(sk);
 				continue;
@@ -4157,7 +4152,7 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
 			l2cap_chan_clear_timer(chan);
 			l2cap_chan_set_timer(chan, HZ * 5);
 		} else if (chan->sec_level == BT_SECURITY_HIGH)
-			__l2cap_chan_close(chan, ECONNREFUSED);
+			l2cap_chan_close(chan, ECONNREFUSED);
 	} else {
 		if (chan->sec_level == BT_SECURITY_MEDIUM)
 			l2cap_chan_clear_timer(chan);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index aca1d56..735d89a 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -707,7 +707,7 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
 			err = __l2cap_wait_ack(sk);
 
 		sk->sk_shutdown = SHUTDOWN_MASK;
-		__l2cap_chan_close(chan, 0);
+		l2cap_chan_close(chan, 0);
 
 		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
 			err = bt_sock_wait_state(sk, BT_CLOSED,
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH -v2 6/7] Bluetooth: Remove export of l2cap_chan_clear_timer()
From: Gustavo F. Padovan @ 2011-05-13 19:20 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1305314450-25493-6-git-send-email-padovan@profusion.mobi>

The call to l2cap_chan_clear_timer() is not really needed in l2cap_sock.c.
This patch also adds a call to l2cap_chan_clear_timer() to the only place
in __l2cap_sock_close() that wasn't calling it. It's safe call it there
because l2cap_chan_clear_timer() check first for timer_peding().

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 include/net/bluetooth/l2cap.h |    1 -
 net/bluetooth/l2cap_core.c    |    3 ++-
 net/bluetooth/l2cap_sock.c    |    1 -
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index efb1fc4..1c89c7f 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -463,7 +463,6 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent);
 struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
 							int proto, gfp_t prio);
 
-void l2cap_chan_clear_timer(struct l2cap_chan *chan);
 struct l2cap_chan *l2cap_chan_create(struct sock *sk);
 void __l2cap_chan_close(struct l2cap_chan *chan, int reason);
 void l2cap_chan_destroy(struct l2cap_chan *chan);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index afd648e..1390d0b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -216,7 +216,7 @@ static void l2cap_chan_set_timer(struct l2cap_chan *chan, long timeout)
 	       sock_hold(chan->sk);
 }
 
-void l2cap_chan_clear_timer(struct l2cap_chan *chan)
+static void l2cap_chan_clear_timer(struct l2cap_chan *chan)
 {
        BT_DBG("chan %p state %d", chan, chan->sk->sk_state);
 
@@ -423,6 +423,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
 	case BT_CONFIG:
 		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
 					conn->hcon->type == ACL_LINK) {
+			l2cap_chan_clear_timer(chan);
 			l2cap_chan_set_timer(chan, sk->sk_sndtimeo);
 			l2cap_send_disconn_req(conn, chan, reason);
 		} else
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 14b686b..aca1d56 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -707,7 +707,6 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
 			err = __l2cap_wait_ack(sk);
 
 		sk->sk_shutdown = SHUTDOWN_MASK;
-		l2cap_chan_clear_timer(chan);
 		__l2cap_chan_close(chan, 0);
 
 		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH -v2 5/7] Bluetooth: create channel timer to replace sk_timer
From: Gustavo F. Padovan @ 2011-05-13 19:20 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1305314450-25493-5-git-send-email-padovan@profusion.mobi>

The new timer does not belong to struct sock, tought it still touch some
sock things, but this will be sorted out soon.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 include/net/bluetooth/l2cap.h |    5 +-
 net/bluetooth/l2cap_core.c    |  100 ++++++++++++++++++++++++++++++----------
 net/bluetooth/l2cap_sock.c    |   50 +--------------------
 3 files changed, 79 insertions(+), 76 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 094a7ac..efb1fc4 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -340,6 +340,7 @@ struct l2cap_chan {
 	__u8		remote_max_tx;
 	__u16		remote_mps;
 
+	struct timer_list	chan_timer;
 	struct timer_list	retrans_timer;
 	struct timer_list	monitor_timer;
 	struct timer_list	ack_timer;
@@ -457,12 +458,12 @@ int __l2cap_wait_ack(struct sock *sk);
 int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm);
 int l2cap_add_scid(struct l2cap_chan *chan,  __u16 scid);
 
-void l2cap_sock_set_timer(struct sock *sk, long timeout);
-void l2cap_sock_clear_timer(struct sock *sk);
 void l2cap_sock_kill(struct sock *sk);
 void l2cap_sock_init(struct sock *sk, struct sock *parent);
 struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
 							int proto, gfp_t prio);
+
+void l2cap_chan_clear_timer(struct l2cap_chan *chan);
 struct l2cap_chan *l2cap_chan_create(struct sock *sk);
 void __l2cap_chan_close(struct l2cap_chan *chan, int reason);
 void l2cap_chan_destroy(struct l2cap_chan *chan);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 0964854..afd648e 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -208,6 +208,56 @@ static u16 l2cap_alloc_cid(struct l2cap_conn *conn)
 	return 0;
 }
 
+static void l2cap_chan_set_timer(struct l2cap_chan *chan, long timeout)
+{
+       BT_DBG("chan %p state %d timeout %ld", chan->sk, chan->sk->sk_state,
+								 timeout);
+       if (!mod_timer(&chan->chan_timer, jiffies + timeout))
+	       sock_hold(chan->sk);
+}
+
+void l2cap_chan_clear_timer(struct l2cap_chan *chan)
+{
+       BT_DBG("chan %p state %d", chan, chan->sk->sk_state);
+
+       if (timer_pending(&chan->chan_timer) && del_timer(&chan->chan_timer))
+	       __sock_put(chan->sk);
+}
+
+static void l2cap_chan_timeout(unsigned long arg)
+{
+	struct l2cap_chan *chan = (struct l2cap_chan *) arg;
+	struct sock *sk = chan->sk;
+	int reason;
+
+	BT_DBG("chan %p state %d", chan, sk->sk_state);
+
+	bh_lock_sock(sk);
+
+	if (sock_owned_by_user(sk)) {
+		/* sk is owned by user. Try again later */
+		l2cap_chan_set_timer(chan, HZ / 5);
+		bh_unlock_sock(sk);
+		sock_put(sk);
+		return;
+	}
+
+	if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG)
+		reason = ECONNREFUSED;
+	else if (sk->sk_state == BT_CONNECT &&
+					chan->sec_level != BT_SECURITY_SDP)
+		reason = ECONNREFUSED;
+	else
+		reason = ETIMEDOUT;
+
+	__l2cap_chan_close(chan, reason);
+
+	bh_unlock_sock(sk);
+
+	l2cap_sock_kill(sk);
+	sock_put(sk);
+}
+
 struct l2cap_chan *l2cap_chan_create(struct sock *sk)
 {
 	struct l2cap_chan *chan;
@@ -222,6 +272,8 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk)
 	list_add(&chan->global_l, &chan_list);
 	write_unlock_bh(&chan_list_lock);
 
+	setup_timer(&chan->chan_timer, l2cap_chan_timeout, (unsigned long) chan);
+
 	return chan;
 }
 
@@ -281,7 +333,7 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
 	struct l2cap_conn *conn = chan->conn;
 	struct sock *parent = bt_sk(sk)->parent;
 
-	l2cap_sock_clear_timer(sk);
+	l2cap_chan_clear_timer(chan);
 
 	BT_DBG("chan %p, conn %p, err %d", chan, conn, err);
 
@@ -334,7 +386,7 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
 /* Must be called on unlocked socket. */
 static void l2cap_chan_close(struct sock *sk)
 {
-	l2cap_sock_clear_timer(sk);
+	l2cap_chan_clear_timer(l2cap_pi(sk)->chan);
 	lock_sock(sk);
 	__l2cap_chan_close(l2cap_pi(sk)->chan, ECONNRESET);
 	release_sock(sk);
@@ -371,7 +423,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
 	case BT_CONFIG:
 		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
 					conn->hcon->type == ACL_LINK) {
-			l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
+			l2cap_chan_set_timer(chan, sk->sk_sndtimeo);
 			l2cap_send_disconn_req(conn, chan, reason);
 		} else
 			l2cap_chan_del(chan, reason);
@@ -814,7 +866,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 
 	__l2cap_chan_add(conn, chan);
 
-	l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
+	l2cap_chan_set_timer(chan, sk->sk_sndtimeo);
 
 	sk->sk_state = BT_CONNECTED;
 	parent->sk_data_ready(parent, 0);
@@ -842,13 +894,13 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
 		bh_lock_sock(sk);
 
 		if (conn->hcon->type == LE_LINK) {
-			l2cap_sock_clear_timer(sk);
+			l2cap_chan_clear_timer(chan);
 			sk->sk_state = BT_CONNECTED;
 			sk->sk_state_change(sk);
 		}
 
 		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
-			l2cap_sock_clear_timer(sk);
+			l2cap_chan_clear_timer(chan);
 			sk->sk_state = BT_CONNECTED;
 			sk->sk_state_change(sk);
 		} else if (sk->sk_state == BT_CONNECT)
@@ -1047,11 +1099,11 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
 	l2cap_chan_add(conn, chan);
 
 	sk->sk_state = BT_CONNECT;
-	l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
+	l2cap_chan_set_timer(chan, sk->sk_sndtimeo);
 
 	if (hcon->state == BT_CONNECTED) {
 		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
-			l2cap_sock_clear_timer(sk);
+			l2cap_chan_clear_timer(chan);
 			if (l2cap_check_security(chan))
 				sk->sk_state = BT_CONNECTED;
 		} else
@@ -1615,7 +1667,7 @@ static void l2cap_chan_ready(struct sock *sk)
 	BT_DBG("sk %p, parent %p", sk, parent);
 
 	chan->conf_state = 0;
-	l2cap_sock_clear_timer(sk);
+	l2cap_chan_clear_timer(chan);
 
 	if (!parent) {
 		/* Outgoing channel.
@@ -2317,7 +2369,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
 	dcid = chan->scid;
 
-	l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
+	l2cap_chan_set_timer(chan, sk->sk_sndtimeo);
 
 	chan->ident = cmd->ident;
 
@@ -2434,8 +2486,8 @@ static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hd
 		/* don't delete l2cap channel if sk is owned by user */
 		if (sock_owned_by_user(sk)) {
 			sk->sk_state = BT_DISCONN;
-			l2cap_sock_clear_timer(sk);
-			l2cap_sock_set_timer(sk, HZ / 5);
+			l2cap_chan_clear_timer(chan);
+			l2cap_chan_set_timer(chan, HZ / 5);
 			break;
 		}
 
@@ -2608,7 +2660,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 
 	default:
 		sk->sk_err = ECONNRESET;
-		l2cap_sock_set_timer(sk, HZ * 5);
+		l2cap_chan_set_timer(chan, HZ * 5);
 		l2cap_send_disconn_req(conn, chan, ECONNRESET);
 		goto done;
 	}
@@ -2664,8 +2716,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
 	/* don't delete l2cap channel if sk is owned by user */
 	if (sock_owned_by_user(sk)) {
 		sk->sk_state = BT_DISCONN;
-		l2cap_sock_clear_timer(sk);
-		l2cap_sock_set_timer(sk, HZ / 5);
+		l2cap_chan_clear_timer(chan);
+		l2cap_chan_set_timer(chan, HZ / 5);
 		bh_unlock_sock(sk);
 		return 0;
 	}
@@ -2698,8 +2750,8 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
 	/* don't delete l2cap channel if sk is owned by user */
 	if (sock_owned_by_user(sk)) {
 		sk->sk_state = BT_DISCONN;
-		l2cap_sock_clear_timer(sk);
-		l2cap_sock_set_timer(sk, HZ / 5);
+		l2cap_chan_clear_timer(chan);
+		l2cap_chan_set_timer(chan, HZ / 5);
 		bh_unlock_sock(sk);
 		return 0;
 	}
@@ -4096,20 +4148,18 @@ static int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
 
 static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
 {
-	struct sock *sk = chan->sk;
-
 	if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED)
 		return;
 
 	if (encrypt == 0x00) {
 		if (chan->sec_level == BT_SECURITY_MEDIUM) {
-			l2cap_sock_clear_timer(sk);
-			l2cap_sock_set_timer(sk, HZ * 5);
+			l2cap_chan_clear_timer(chan);
+			l2cap_chan_set_timer(chan, HZ * 5);
 		} else if (chan->sec_level == BT_SECURITY_HIGH)
 			__l2cap_chan_close(chan, ECONNREFUSED);
 	} else {
 		if (chan->sec_level == BT_SECURITY_MEDIUM)
-			l2cap_sock_clear_timer(sk);
+			l2cap_chan_clear_timer(chan);
 	}
 }
 
@@ -4154,8 +4204,8 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 				l2cap_send_cmd(conn, chan->ident,
 					L2CAP_CONN_REQ, sizeof(req), &req);
 			} else {
-				l2cap_sock_clear_timer(sk);
-				l2cap_sock_set_timer(sk, HZ / 10);
+				l2cap_chan_clear_timer(chan);
+				l2cap_chan_set_timer(chan, HZ / 10);
 			}
 		} else if (sk->sk_state == BT_CONNECT2) {
 			struct l2cap_conn_rsp rsp;
@@ -4166,7 +4216,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 				result = L2CAP_CR_SUCCESS;
 			} else {
 				sk->sk_state = BT_DISCONN;
-				l2cap_sock_set_timer(sk, HZ / 10);
+				l2cap_chan_set_timer(chan, HZ / 10);
 				result = L2CAP_CR_SEC_BLOCK;
 			}
 
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 6a80a96..14b686b 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -32,52 +32,6 @@
 
 static const struct proto_ops l2cap_sock_ops;
 
-/* ---- L2CAP timers ---- */
-static void l2cap_sock_timeout(unsigned long arg)
-{
-	struct sock *sk = (struct sock *) arg;
-	int reason;
-
-	BT_DBG("sock %p state %d", sk, sk->sk_state);
-
-	bh_lock_sock(sk);
-
-	if (sock_owned_by_user(sk)) {
-		/* sk is owned by user. Try again later */
-		l2cap_sock_set_timer(sk, HZ / 5);
-		bh_unlock_sock(sk);
-		sock_put(sk);
-		return;
-	}
-
-	if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG)
-		reason = ECONNREFUSED;
-	else if (sk->sk_state == BT_CONNECT &&
-			l2cap_pi(sk)->chan->sec_level != BT_SECURITY_SDP)
-		reason = ECONNREFUSED;
-	else
-		reason = ETIMEDOUT;
-
-	__l2cap_chan_close(l2cap_pi(sk)->chan, reason);
-
-	bh_unlock_sock(sk);
-
-	l2cap_sock_kill(sk);
-	sock_put(sk);
-}
-
-void l2cap_sock_set_timer(struct sock *sk, long timeout)
-{
-	BT_DBG("sk %p state %d timeout %ld", sk, sk->sk_state, timeout);
-	sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout);
-}
-
-void l2cap_sock_clear_timer(struct sock *sk)
-{
-	BT_DBG("sock %p state %d", sk, sk->sk_state);
-	sk_stop_timer(sk, &sk->sk_timer);
-}
-
 static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 {
 	struct sock *sk = sock->sk;
@@ -753,7 +707,7 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
 			err = __l2cap_wait_ack(sk);
 
 		sk->sk_shutdown = SHUTDOWN_MASK;
-		l2cap_sock_clear_timer(sk);
+		l2cap_chan_clear_timer(chan);
 		__l2cap_chan_close(chan, 0);
 
 		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
@@ -879,8 +833,6 @@ struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, g
 	sk->sk_protocol = proto;
 	sk->sk_state = BT_OPEN;
 
-	setup_timer(&sk->sk_timer, l2cap_sock_timeout, (unsigned long) sk);
-
 	return sk;
 }
 
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH -v2 4/7] Bluetooth: Add chan->chan_type struct member
From: Gustavo F. Padovan @ 2011-05-13 19:20 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1305314450-25493-4-git-send-email-padovan@profusion.mobi>

chan_type says if our chan is raw(direclty access to HCI),
connection less or connection oriented.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 include/net/bluetooth/l2cap.h |    5 +++++
 net/bluetooth/l2cap_core.c    |   30 +++++++++++-------------------
 net/bluetooth/l2cap_sock.c    |   29 ++++++++++++++++++++++-------
 3 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index dc721ca..094a7ac 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -295,6 +295,7 @@ struct l2cap_chan {
 	__u16		omtu;
 	__u16		flush_to;
 	__u8		mode;
+	__u8		chan_type;
 
 	__le16		sport;
 
@@ -384,6 +385,10 @@ struct l2cap_conn {
 #define L2CAP_INFO_FEAT_MASK_REQ_SENT	0x04
 #define L2CAP_INFO_FEAT_MASK_REQ_DONE	0x08
 
+#define L2CAP_CHAN_RAW			1
+#define L2CAP_CHAN_CONN_LESS		2
+#define L2CAP_CHAN_CONN_ORIENTED	3
+
 /* ----- L2CAP socket info ----- */
 #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
 
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 1e049a7..0964854 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -245,7 +245,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
 
 	chan->conn = conn;
 
-	if (sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) {
+	if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
 		if (conn->hcon->type == LE_LINK) {
 			/* LE connection */
 			chan->omtu = L2CAP_LE_DEFAULT_MTU;
@@ -256,7 +256,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
 			chan->scid = l2cap_alloc_cid(conn);
 			chan->omtu = L2CAP_DEFAULT_MTU;
 		}
-	} else if (sk->sk_type == SOCK_DGRAM) {
+	} else if (chan->chan_type == L2CAP_CHAN_CONN_LESS) {
 		/* Connectionless socket */
 		chan->scid = L2CAP_CID_CONN_LESS;
 		chan->dcid = L2CAP_CID_CONN_LESS;
@@ -369,8 +369,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
 
 	case BT_CONNECTED:
 	case BT_CONFIG:
-		if ((sk->sk_type == SOCK_SEQPACKET ||
-					sk->sk_type == SOCK_STREAM) &&
+		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
 					conn->hcon->type == ACL_LINK) {
 			l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
 			l2cap_send_disconn_req(conn, chan, reason);
@@ -379,8 +378,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
 		break;
 
 	case BT_CONNECT2:
-		if ((sk->sk_type == SOCK_SEQPACKET ||
-					sk->sk_type == SOCK_STREAM) &&
+		if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
 					conn->hcon->type == ACL_LINK) {
 			struct l2cap_conn_rsp rsp;
 			__u16 result;
@@ -414,9 +412,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason)
 
 static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
 {
-	struct sock *sk = chan->sk;
-
-	if (sk->sk_type == SOCK_RAW) {
+	if (chan->chan_type == L2CAP_CHAN_RAW) {
 		switch (chan->sec_level) {
 		case BT_SECURITY_HIGH:
 			return HCI_AT_DEDICATED_BONDING_MITM;
@@ -657,8 +653,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
 
 		bh_lock_sock(sk);
 
-		if (sk->sk_type != SOCK_SEQPACKET &&
-				sk->sk_type != SOCK_STREAM) {
+		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
 			bh_unlock_sock(sk);
 			continue;
 		}
@@ -852,8 +847,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
 			sk->sk_state_change(sk);
 		}
 
-		if (sk->sk_type != SOCK_SEQPACKET &&
-				sk->sk_type != SOCK_STREAM) {
+		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
 			l2cap_sock_clear_timer(sk);
 			sk->sk_state = BT_CONNECTED;
 			sk->sk_state_change(sk);
@@ -1056,8 +1050,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
 	l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
 
 	if (hcon->state == BT_CONNECTED) {
-		if (sk->sk_type != SOCK_SEQPACKET &&
-				sk->sk_type != SOCK_STREAM) {
+		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
 			l2cap_sock_clear_timer(sk);
 			if (l2cap_check_security(chan))
 				sk->sk_state = BT_CONNECTED;
@@ -1537,13 +1530,12 @@ int l2cap_sar_segment_sdu(struct l2cap_chan *chan, struct msghdr *msg, size_t le
 
 int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
 {
-	struct sock *sk = chan->sk;
 	struct sk_buff *skb;
 	u16 control;
 	int err;
 
 	/* Connectionless channel */
-	if (sk->sk_type == SOCK_DGRAM) {
+	if (chan->chan_type == L2CAP_CHAN_CONN_LESS) {
 		skb = l2cap_create_connless_pdu(chan, msg, len);
 		if (IS_ERR(skb))
 			return PTR_ERR(skb);
@@ -1650,7 +1642,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
 	read_lock(&conn->chan_lock);
 	list_for_each_entry(chan, &conn->chan_l, list) {
 		struct sock *sk = chan->sk;
-		if (sk->sk_type != SOCK_RAW)
+		if (chan->chan_type != L2CAP_CHAN_RAW)
 			continue;
 
 		/* Don't send frame to the socket it came from */
@@ -4106,7 +4098,7 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
 {
 	struct sock *sk = chan->sk;
 
-	if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM)
+	if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED)
 		return;
 
 	if (encrypt == 0x00) {
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f36776e..6a80a96 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -162,7 +162,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
 
 	lock_sock(sk);
 
-	if ((sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM)
+	if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED
 			&& !(la.l2_psm || la.l2_cid)) {
 		err = -EINVAL;
 		goto done;
@@ -204,8 +204,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
 	}
 
 	/* PSM must be odd and lsb of upper byte must be 0 */
-	if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 &&
-				sk->sk_type != SOCK_RAW && !la.l2_cid) {
+	if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && !la.l2_cid &&
+					chan->chan_type != L2CAP_CHAN_RAW) {
 		err = -EINVAL;
 		goto done;
 	}
@@ -453,8 +453,8 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
 
 	switch (optname) {
 	case BT_SECURITY:
-		if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM
-				&& sk->sk_type != SOCK_RAW) {
+		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
+					chan->chan_type != L2CAP_CHAN_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -599,8 +599,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
 
 	switch (optname) {
 	case BT_SECURITY:
-		if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM
-				&& sk->sk_type != SOCK_RAW) {
+		if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
+					chan->chan_type != L2CAP_CHAN_RAW) {
 			err = -EINVAL;
 			break;
 		}
@@ -806,6 +806,7 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent)
 		sk->sk_type = parent->sk_type;
 		bt_sk(sk)->defer_setup = bt_sk(parent)->defer_setup;
 
+		chan->chan_type = pchan->chan_type;
 		chan->imtu = pchan->imtu;
 		chan->omtu = pchan->omtu;
 		chan->conf_state = pchan->conf_state;
@@ -818,6 +819,20 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent)
 		chan->force_reliable = pchan->force_reliable;
 		chan->flushable = pchan->flushable;
 	} else {
+
+		switch (sk->sk_type) {
+		case SOCK_RAW:
+			chan->chan_type = L2CAP_CHAN_RAW;
+			break;
+		case SOCK_DGRAM:
+			chan->chan_type = L2CAP_CHAN_CONN_LESS;
+			break;
+		case SOCK_SEQPACKET:
+		case SOCK_STREAM:
+			chan->chan_type = L2CAP_CHAN_CONN_ORIENTED;
+			break;
+		}
+
 		chan->imtu = L2CAP_DEFAULT_MTU;
 		chan->omtu = 0;
 		if (!disable_ertm && sk->sk_type == SOCK_STREAM) {
-- 
1.7.5.rc3


^ 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