diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-05-16 16:24:37 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-06-13 13:55:32 -0400 |
commit | 80808e431e1ef25856457de82ce141bed6a6313a (patch) | |
tree | 021d6affd8b8f6bf81ba51fadb9951b0b9e47d27 /net/bluetooth/l2cap_sock.c | |
parent | dc50a06dac61d7ca7ddb3d9bb8921ca5d68f51b6 (diff) |
Bluetooth: Add l2cap_chan_ops abstraction
Add an abstraction layer between L2CAP core and its users (only
l2cap_sock.c now). The first function implemented is new_connection() that
replaces calls to l2cap_sock_alloc() in l2cap_core.c
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/l2cap_sock.c')
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 2f4fd5751a46..4050edeaf78b 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #include <net/bluetooth/l2cap.h> | 31 | #include <net/bluetooth/l2cap.h> |
32 | 32 | ||
33 | static const struct proto_ops l2cap_sock_ops; | 33 | static const struct proto_ops l2cap_sock_ops; |
34 | static void l2cap_sock_init(struct sock *sk, struct sock *parent); | ||
35 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio); | ||
34 | 36 | ||
35 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) | 37 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) |
36 | { | 38 | { |
@@ -773,6 +775,25 @@ static int l2cap_sock_release(struct socket *sock) | |||
773 | return err; | 775 | return err; |
774 | } | 776 | } |
775 | 777 | ||
778 | static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data) | ||
779 | { | ||
780 | struct sock *sk, *parent = data; | ||
781 | |||
782 | sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP, | ||
783 | GFP_ATOMIC); | ||
784 | if (!sk) | ||
785 | return NULL; | ||
786 | |||
787 | l2cap_sock_init(sk, parent); | ||
788 | |||
789 | return l2cap_pi(sk)->chan; | ||
790 | } | ||
791 | |||
792 | static struct l2cap_ops l2cap_chan_ops = { | ||
793 | .name = "L2CAP Socket Interface", | ||
794 | .new_connection = l2cap_sock_new_connection_cb, | ||
795 | }; | ||
796 | |||
776 | static void l2cap_sock_destruct(struct sock *sk) | 797 | static void l2cap_sock_destruct(struct sock *sk) |
777 | { | 798 | { |
778 | BT_DBG("sk %p", sk); | 799 | BT_DBG("sk %p", sk); |
@@ -781,7 +802,7 @@ static void l2cap_sock_destruct(struct sock *sk) | |||
781 | skb_queue_purge(&sk->sk_write_queue); | 802 | skb_queue_purge(&sk->sk_write_queue); |
782 | } | 803 | } |
783 | 804 | ||
784 | void l2cap_sock_init(struct sock *sk, struct sock *parent) | 805 | static void l2cap_sock_init(struct sock *sk, struct sock *parent) |
785 | { | 806 | { |
786 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 807 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
787 | struct l2cap_chan *chan = pi->chan; | 808 | struct l2cap_chan *chan = pi->chan; |
@@ -838,10 +859,14 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
838 | chan->force_reliable = 0; | 859 | chan->force_reliable = 0; |
839 | chan->flushable = BT_FLUSHABLE_OFF; | 860 | chan->flushable = BT_FLUSHABLE_OFF; |
840 | chan->force_active = BT_POWER_FORCE_ACTIVE_ON; | 861 | chan->force_active = BT_POWER_FORCE_ACTIVE_ON; |
862 | |||
841 | } | 863 | } |
842 | 864 | ||
843 | /* Default config options */ | 865 | /* Default config options */ |
844 | chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; | 866 | chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; |
867 | |||
868 | chan->data = sk; | ||
869 | chan->ops = &l2cap_chan_ops; | ||
845 | } | 870 | } |
846 | 871 | ||
847 | static struct proto l2cap_proto = { | 872 | static struct proto l2cap_proto = { |
@@ -850,7 +875,7 @@ static struct proto l2cap_proto = { | |||
850 | .obj_size = sizeof(struct l2cap_pinfo) | 875 | .obj_size = sizeof(struct l2cap_pinfo) |
851 | }; | 876 | }; |
852 | 877 | ||
853 | struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) | 878 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) |
854 | { | 879 | { |
855 | struct sock *sk; | 880 | struct sock *sk; |
856 | struct l2cap_chan *chan; | 881 | struct l2cap_chan *chan; |