linux/net/bluetooth
David Herrmann 2c8e1411e9 Bluetooth: l2cap: add l2cap_user sub-modules
Several sub-modules like HIDP, rfcomm, ... need to track l2cap
connections. The l2cap_conn->hcon->dev object is used as parent for sysfs
devices so the sub-modules need to be notified when the hci_conn object is
removed from sysfs.

As submodules normally use the l2cap layer, the l2cap_user objects are
registered there instead of on the underlying hci_conn object. This avoids
any direct dependency on the HCI layer and lets the l2cap core handle any
specifics.

This patch introduces l2cap_user objects which contain a "probe" and
"remove" callback. You can register them on any l2cap_conn object and if
it is active, the "probe" callback will get called. Otherwise, an error is
returned.

The l2cap_conn object will call your "remove" callback directly before it
is removed from user-space. This allows you to remove your submodules
_before_ the parent l2cap_conn and hci_conn object is removed.

At any time you can asynchronously unregister your l2cap_user object if
your submodule vanishes before the l2cap_conn object does.

There is no way around l2cap_user. If we want wire-protocols in the
kernel, we always want the hci_conn object as parent in the sysfs tree. We
cannot use a channel here since we might need multiple channels for a
single protocol.
But the problem is, we _must_ get notified when an l2cap_conn object is
removed. We cannot use reference-counting for object-removal! This is not
how it works. If a hardware is removed, we should immediately remove the
object from sysfs. Any other behavior would be inconsistent with the rest
of the system. Also note that device_del() might sleep, but it doesn't
wait for user-space or block very long. It only _unlinks_ the object from
sysfs and the whole device-tree. Everything else is handled by ref-counts!
This is exactly what the other sub-modules must do: unlink their devices
when the "remove" l2cap_user callback is called. They should not do any
cleanup or synchronous shutdowns.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
2013-04-17 03:03:43 -03:00
..
bnep Bluetooth: discard bt_sock_unregister() errors 2013-03-08 10:38:44 -03:00
cmtp Bluetooth: discard bt_sock_unregister() errors 2013-03-08 10:38:44 -03:00
hidp Bluetooth: hidp: move hidp_schedule() to core.c 2013-04-17 02:56:59 -03:00
rfcomm Bluetooth: fix error return code in rfcomm_add_listener() 2013-03-20 14:17:52 -03:00
a2mp.c Bluetooth: Replaced kzalloc and memcpy with kmemdup 2013-03-18 14:01:50 -03:00
af_bluetooth.c Bluetooth: change bt_sock_unregister() to return void 2013-03-08 10:38:44 -03:00
amp.c Bluetooth: AMP: Use set_bit / test_bit for amp_mgr state 2013-01-09 17:05:05 -02:00
hci_conn.c Bluetooth: introduce hci_conn ref-counting 2013-04-17 02:45:22 -03:00
hci_core.c Bluetooth: Remove driver init queue from core 2013-04-04 19:28:25 +03:00
hci_event.c Bluetooth: remove unneeded hci_conn_hold/put_device() 2013-04-17 02:38:36 -03:00
hci_sock.c Bluetooth: Fix stand-alone HCI command handling 2013-03-08 10:40:26 -03:00
hci_sysfs.c Bluetooth: introduce hci_conn ref-counting 2013-04-17 02:45:22 -03:00
Kconfig Bluetooth: trivial: Remove newline before EOF 2012-10-24 00:42:47 -02:00
l2cap_core.c Bluetooth: l2cap: add l2cap_user sub-modules 2013-04-17 03:03:43 -03:00
l2cap_sock.c Bluetooth: hidp: verify l2cap sockets 2013-04-05 23:44:14 -03:00
lib.c bluetooth: Remove unneeded batostr function 2012-09-27 18:10:43 -03:00
Makefile Bluetooth: AMP: Use HCI cmd to Read Loc AMP Assoc 2012-09-27 17:10:32 -03:00
mgmt.c Bluetooth: rename hci_conn_put to hci_conn_drop 2013-04-11 16:34:15 -03:00
sco.c Bluetooth: Minor coding style fix 2013-04-11 16:34:17 -03:00
smp.c Bluetooth: rename hci_conn_put to hci_conn_drop 2013-04-11 16:34:15 -03:00