struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
int proto, gfp_t prio);
void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, int err);
+struct l2cap_chan *l2cap_chan_alloc(struct sock *sk);
void l2cap_chan_del(struct l2cap_chan *chan, int err);
-int l2cap_do_connect(struct sock *sk);
+int l2cap_do_connect(struct l2cap_chan *chan);
#endif /* __L2CAP_H */
return 0;
}
-static struct l2cap_chan *l2cap_chan_alloc(struct sock *sk)
+struct l2cap_chan *l2cap_chan_alloc(struct sock *sk)
{
struct l2cap_chan *chan;
goto clean;
}
+ l2cap_pi(sk)->chan = chan;
+
write_lock_bh(&conn->chan_lock);
hci_conn_hold(conn->hcon);
__l2cap_chan_add(conn, chan);
- l2cap_pi(sk)->chan = chan;
-
l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
sk->sk_state = BT_CONNECTED;
return node ? sk : sk1;
}
-int l2cap_do_connect(struct sock *sk)
+int l2cap_do_connect(struct l2cap_chan *chan)
{
+ struct sock *sk = chan->sk;
bdaddr_t *src = &bt_sk(sk)->src;
bdaddr_t *dst = &bt_sk(sk)->dst;
struct l2cap_conn *conn;
- struct l2cap_chan *chan;
struct hci_conn *hcon;
struct hci_dev *hdev;
__u8 auth_type;
goto done;
}
- chan = l2cap_chan_alloc(sk);
- if (!chan) {
- hci_conn_put(hcon);
- err = -ENOMEM;
- goto done;
- }
-
/* Update source addr of the socket */
bacpy(src, conn->src);
l2cap_chan_add(conn, chan);
- l2cap_pi(sk)->chan = chan;
-
sk->sk_state = BT_CONNECT;
l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
goto response;
}
+ l2cap_pi(sk)->chan = chan;
+
write_lock_bh(&conn->chan_lock);
/* Check if we already have channel with that dcid */
__l2cap_chan_add(conn, chan);
- l2cap_pi(sk)->chan = chan;
-
dcid = l2cap_pi(sk)->scid;
l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
l2cap_pi(sk)->psm = la.l2_psm;
l2cap_pi(sk)->dcid = la.l2_cid;
- err = l2cap_do_connect(sk);
+ err = l2cap_do_connect(l2cap_pi(sk)->chan);
if (err)
goto done;
int kern)
{
struct sock *sk;
+ struct l2cap_chan *chan;
BT_DBG("sock %p", sock);
if (!sk)
return -ENOMEM;
+ chan = l2cap_chan_alloc(sk);
+ if (!chan) {
+ l2cap_sock_kill(sk);
+ return -ENOMEM;
+ }
+
+ l2cap_pi(sk)->chan = chan;
+
l2cap_sock_init(sk, NULL);
return 0;
}