Gustavo Padovan [Fri, 11 May 2012 16:16:11 +0000 (13:16 -0300)]
Bluetooth: Fix packet size provided to the controller
When building fragmented skb's skb->len keeps track of the size of head
plus all fragments combined, however when queueing the skb for sending we
need to report the head size instead of the total size, so we just set
skb->len to skb_headlen().
This bug appeared when implementing MSG_MORE support for L2CAP sockets, it
never showed up before because l2cap_skbuff_fromiovec() never accounted skb
size correctly. A following patch will fix this.
Signed-off-by: Gustavo Padovan <gustavo@padovan.org> Reviewed-by: Mat Martineau <mathewm@codeaurora.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Mat Martineau [Mon, 14 May 2012 21:49:27 +0000 (14:49 -0700)]
Bluetooth: Initialize the transmit queue for L2CAP streaming mode
Commit 105bdf9ec19e729bacdb33861c74fcf3eb39eb37 introduced a
regression in L2CAP streaming mode due to rearranged initialization
code that is shared between ERTM and streaming mode. This change
makes sure the transmit queue is initialized in both modes.
Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Acked-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Mat Martineau [Mon, 14 May 2012 18:24:33 +0000 (11:24 -0700)]
Bluetooth: Update tx_send_head when sending ERTM data
Commit 94122bbe9c8c4ad7ba9f02f9a30bfc95672c404e introduced a problem
where tx_send_head was not set to point to the first skb in the ERTM
transmit queue, which stalled data transmission. This change sets
that pointer when transmission is not already in progress.
Reported-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Johan Hedberg [Sat, 12 May 2012 19:11:50 +0000 (16:11 -0300)]
Bluetooth: mgmt: Fix device_connected sending order
The mgmt_ev_device_connected signal must be sent before any event
indications happen for sockets associated with the connection. Otherwise
e.g. device authorization for the sockets will fail with ENOTCONN as
user space things that there is no baseband link.
This patch fixes the issue by ensuring that the device_connected event
if sent (if it hasn't been so already) as soon as the first ACL data
packet arrives from the remote device.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Gustavo Padovan [Sun, 13 May 2012 06:20:07 +0000 (03:20 -0300)]
Bluetooth: notify userspace of security level change
It fixes L2CAP socket based security level elevation during a
connection. The HID profile needs this (for keyboards) and it is the only
way to achieve the security level elevation when using the management
interface to talk to the kernel (hence the management enabling patch
being the one that exposes this issue).
It enables the userspace a security level change when the socket is
already connected and create a way to notify the socket the result of the
request. At the moment of the request the socket is made non writable, if
the request fails the connections closes, otherwise the socket is made
writable again, POLL_OUT is emmited.
Signed-off-by: Gustavo Padovan <gustavo@padovan.org> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Larry Finger [Fri, 4 May 2012 13:27:43 +0000 (08:27 -0500)]
rtlwifi: fix for race condition when firmware is cached
In commit b0302ab, the rtlwifi family of drivers was converted to use
asynchronous firmware loading. Unfortumately, the implementation was
racy, and the ieee80211 routines could be started before rtl_init_core()
was called to setup the data.
This patch fixes the bug noted in https://bugzilla.kernel.org/show_bug.cgi?id=43187.
Reported-by: Joshua Roys <Joshua.Roys@gtri.gatech.edu> Tested-by: Neptune Ning <frostyplanet@gmail.com> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> Cc: Stable <stable@vger.kernel.org> [3.3] Signed-off-by: John W. Linville <linville@tuxdriver.com>
Mat Martineau [Wed, 2 May 2012 16:42:02 +0000 (09:42 -0700)]
Bluetooth: Refactor L2CAP ERTM and streaming transmit segmentation
Use more common code for ERTM and streaming mode segmentation and
transmission, and begin using skb control block data for delaying
extended or enhanced header generation until just before the packet is
transmitted. This code is also better suited for resegmentation,
which is needed when L2CAP links are reconfigured after an AMP channel
move.
Marcel Holtmann [Thu, 3 May 2012 05:12:31 +0000 (07:12 +0200)]
Bluetooth: Enable Low Energy support by default
The Bluetooth Low Energy support so far was disabled by default via
a module parameter. With this change the module parameter will be removed
and Low Energy is enabled by default.
Mat Martineau [Fri, 27 Apr 2012 23:50:50 +0000 (16:50 -0700)]
Bluetooth: Make better use of l2cap_chan reference counting
L2CAP sockets contain a pointer to l2cap_chan that needs to be
reference counted in order to prevent a possible dangling pointer when
the channel is freed.
There were a few other cases where an l2cap_chan pointer on the stack
was dereferenced after a call to l2cap_chan_del. Those pointers are
also now reference counted.
Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Mat Martineau [Fri, 27 Apr 2012 23:50:48 +0000 (16:50 -0700)]
Bluetooth: Initialize new l2cap_chan structure members
Structure members used by ERTM or streaming mode need to be
initialized when an ERTM or streaming mode link is configured. Some
duplicate code is also eliminated by moving in to the ERTM init
function.
Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Moving these functions simplifies future patches by eliminating
forward declarations, makes future patches easier to review, and
better preserves 'git blame' information.
Mat Martineau [Wed, 25 Apr 2012 23:36:12 +0000 (16:36 -0700)]
Bluetooth: Improve ERTM sequence number offset calculation
Instead of using modular division, the offset can be calculated using
only addition and subtraction. The previous calculation did not work
as intended and was more difficult to understand, involving unsigned
integer underflow and a check for a negative value where one was not
possible.
Currently debugfs commands "hscfgcmd" and "gpiogap" are provided
for host sleep configuration. But if user doesn't configure host
sleep parameters using these commands, host sleep activation is
failed during suspend (support for suspend and resume handlers is
added in next patch).
Default host sleep configuration is done during driver initialisation
in this patch.
Andre Guedes [Wed, 25 Apr 2012 00:02:56 +0000 (21:02 -0300)]
Bluetooth: Remove advertising cache
User-space pass the remote device address type to kernel through
struct sockaddr_l2 what makes the advertising useless. This patch
removes all advertising cache code.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:55 +0000 (21:02 -0300)]
Bluetooth: Use address type info from user-space
In order to establish a LE connection we need the address type
information. User-space already pass this information to kernel
through struct sockaddr_l2.
This patch adds the dst_type parameter to l2cap_chan_connect so we
are able to pass the address type info from user-space down to
hci_conn layer.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:54 +0000 (21:02 -0300)]
Bluetooth: Add dst_type parameter to hci_connect
This patch adds the dst_type parameter to hci_connect function.
Instead of searching the address type in advertising cache, we
use the dst_type parameter to establish LE connections.
The dst_type is ignored for BR/EDR connection establishment.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:51 +0000 (21:02 -0300)]
Bluetooth: Rename mgmt_to_le to bdaddr_to_le
Since address type macros are not only related to Management
Interface anymore, it makes sense to rename the helper function
mgmt_to_le to bdaddr_to_le.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:52 +0000 (21:02 -0300)]
Bluetooth: Add address type to struct sockaddr_l2
This patch adds the address type info to struct sockaddr_l2 so
user-space can inform the remote device address type required
to establish LE connections.
Soon, instead of looking the advertising cache up to discover the
address type, we'll use this address type info to establish LE
connections.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:50 +0000 (21:02 -0300)]
Bluetooth: Rename link_to_mgmt to link_to_bdaddr
Since address type macros are not only related to Management
Interface anymore, it makes sense to rename the helper function
link_to_mgmt to link_to_bdaddr.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Wed, 25 Apr 2012 00:02:49 +0000 (21:02 -0300)]
Bluetooth: Move address type macros to bluetooth.h
This patch moves address type macros to bluetooth.h since they will be
used by management interface and Bluetooth socket interface. It also
replaces the macro prefix MGMT_ADDR_ by BDADDR_.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Andre Guedes [Tue, 24 Apr 2012 19:11:11 +0000 (16:11 -0300)]
Bluetooth: Remove useless code in hci_connect
This patch removes unneeded variable assignments in hci_connect.
'sec_level' is already assigned to BT_SECURITY_LOW in hci_le_connect
and 'pending_sec_level' and 'auth_type' are assigned right after
if statement.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: Add support for reusing the same hci_conn for LE links
As most LE devices leave advertising mode when they enter the connected
state, we may want to "pass" that connection to other users.
The first user will be the pairing procedure, the connection is
established without an associated socket, after the pairing is
complete, userspace may want to discover via GATT what services the
newly bonded device has.
If userspace establishes the connection while the timeout still
hasn't expired, the connection will be re-used.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org> Tested-by: João Paulo Rechi Vita <jprvita@openbossa.org> Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
David Herrmann [Sun, 22 Apr 2012 12:39:58 +0000 (14:39 +0200)]
Bluetooth: Move device initialization to hci_alloc_dev()
We currently initialize locks, lists, works, etc. in hci_register_dev()
(hci_alloc_dev() was added later) which is bogus because an hdev is in an
invalid state if it is not registered.
This patch moves all memory initialization to hci_alloc_dev(). Device
registering and registration of sub-modules is still left in
hci_register_dev() as it belongs there.
The benefit is (despite cleaning up the code-base) we can now always be
sure that an hdev is a valid object and can be locked and worked on even
though it may not be registered.
This patch also reorders the initialization to be easier to understand.
First the memory is initialized, then all generic structures and as last
step the sub-init functions are called. This guarantees that all
dependencies are initialized in the right order and makes it also easier
to find a specific line. We previously initialized it in the same order as
the "struct hci_dev" is declared which seems pretty random.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
David Herrmann [Sun, 22 Apr 2012 12:39:57 +0000 (14:39 +0200)]
Bluetooth: Move hci_alloc/free_dev close to hci_register/unregister_dev
alloc() and register() (and free() and unregister()) are closely related
so move them more closely together. This will also allow to move
functionality from register() to alloc() without needing
forward-declarations.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: Don't check source address in SCO bind function
Checking the source address in SCO bind function will prevent from
having an incoming and outgoing SCO socket. However that might be
needed in case of multiple SCO connections on a single device.
We assume id starts with the number we'll try to add the new device
and keep iterating until we find the proper place. The only difference
is we start with 0 for BR/EDR device and 1 for AMP devices (thus AMP
devices will never receive register as index 0). Then every hdev->id in
the _ordered_ list <= to the id we want we increment id and move the
variable head. In the end we'll have id as the first available one and
head is where you need to add hdev after to keep the list ordered.
Mikel Astiz [Wed, 11 Apr 2012 06:48:51 +0000 (08:48 +0200)]
Bluetooth: btusb: Dynamic alternate setting
The alternate setting must be dynamically set according to the number of
active SCO links, and the bit depth of the audio. The possible values
for the alternate setting are described in the Bluetooth Core
Specification, Volume 4, Part B, section 2.1.1.
Bluetooth: mgmt: Fix address type while loading Long Term Key
This patch fixes the address type while loading long term keys when BT is
switched on. Without this fix pairing is reinitated even though LTK
exists for remote device because of mismatch of address type.
Signed-off-by: Hemant Gupta <hemant.gupta@stericsson.com> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Mikel Astiz [Wed, 11 Apr 2012 06:48:47 +0000 (08:48 +0200)]
Bluetooth: Use unsigned int instead of signed int
The involved values are all unsigned and thus unsigned int should be
used instead of signed int. Assigning ~0 to a signed int results in -1,
which is confusing and error-prone, while the code is trying to set the
maximum value possible.
The code still works because the C standard defines that unsigned
comparison will be performed in these cases, when comparing an unsigned
int and a signed int.
Mat Martineau [Wed, 11 Apr 2012 17:48:42 +0000 (10:48 -0700)]
Bluetooth: Add the l2cap_seq_list structure for tracking frames
A sequence list is a data structure used to track frames that need to
be retransmitted, and frames that have been requested for
retransmission by the remote device. It can compactly represent a
list of sequence numbers within the ERTM transmit window. Memory for
the list is allocated once at connection time, and common operations
in ERTM are O(1).
Signed-off-by: Mat Martineau <mathewm@codeaurora.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: mgmt: Fix missing connect failed event for LE
This patch adds management connect failed event when LE Create Connection
Command fails to inform user space that LE Connection failed to get
established.
Signed-off-by: Hemant Gupta <hemant.gupta@stericsson.com> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Bluetooth: Fix clearing discovery type when stopping discovery
This patch prevents resetting of discovery type while stopping
discovery, since otherwise the wrong type might be send in case of
discovery failure. It also doesn't matter that we are "lazy" with
updating the type since it is anyway reset when starting discovery again
and it's not needed to know the current discovery state.
Signed-off-by: Hemant Gupta <hemant.gupta@stericsson.com> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
David Herrmann [Wed, 28 Mar 2012 09:48:42 +0000 (11:48 +0200)]
Bluetooth: vhci: Ignore return code of nonseekable_open()
The comment in ./fs/open.c clearly states that nonseekable_open() will
never fail. Therefore, we can safely ignore the return code. This is the
recommended way to deal with nonseekable_open().
Our current code looks like nonseekable_open() is checked for the return
code. However, if we check the return code, we must also kfree() our
private data if the open fails. To avoid this overhead and to avoid
confusion, we simply drop the return code and return 0.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Marcel Holtmann [Tue, 27 Mar 2012 16:49:02 +0000 (18:49 +0200)]
Bluetooth: Update management interface revision
For each kernel release where commands or events are added to the
management interface, the revision field should be increment by one.
The increment should only happen once per kernel release and not
for every command/event that gets added. The revision value is for
informational purposes only, but this simple policy would make any
future debugging a lot simple.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
...
net/bluetooth/l2cap_core.c:302:6: warning: symbol '__l2cap_chan_add' was
not declared. Should it be static?
net/bluetooth/l2cap_core.c:351:6: warning: symbol 'l2cap_chan_add' was
not declared. Should it be static?
...
Mat Martineau [Fri, 23 Mar 2012 23:56:56 +0000 (16:56 -0700)]
Bluetooth: Add a structure to carry ERTM data in skb control blocks
Every field from ERTM control headers is now carried in the control
block so it only has to be parsed or generated once, and can be
efficiently accessed throughout the ERTM code.
Mat Martineau [Fri, 23 Mar 2012 23:56:55 +0000 (16:56 -0700)]
Bluetooth: Add definitions and struct members for new ERTM state machine
Adds some missing values for control field parsing, additional data
for the new state machine, and enumerations for states, incoming
packet classification, and state machine events.
Andre Guedes [Wed, 21 Mar 2012 03:03:37 +0000 (00:03 -0300)]
Bluetooth: Check HCI_PERIODIC_INQ in start_discovery
This patch adds a HCI_PERIODIC_INQ check to start_discovery.
If periodic inquiry is enabled, we fail MGMT Start Discovery
command with MGMT_STATUS_BUSY code.
Fix sparse warnings related to incorrect type in assignment and static
symbol. Also use const keyword. Warnings are shown below:
...
net/bluetooth/mgmt.c:305:28: warning: incorrect type in assignment
(different base types)
net/bluetooth/mgmt.c:305:28: expected unsigned short [usertype] *opcode
net/bluetooth/mgmt.c:305:28: got restricted __le16 *<noident>
...
net/bluetooth/mgmt.c:2609:3: warning: symbol 'mgmt_handlers' was not declared.
Should it be static?
...
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>