diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-05-02 16:13:55 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-06-08 15:58:16 -0400 |
commit | 715ec005cd10c5d53109ffe513e4d403644e3e48 (patch) | |
tree | f4a996e3e1efebbe8388ba167cfa258ec0056798 /net/bluetooth | |
parent | 9a91a04a95d30a18909e2aec9d7b17b4c86088a7 (diff) |
Bluetooth: Add chan->chan_type struct member
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>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 30 | ||||
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 29 |
2 files changed, 33 insertions, 26 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index e65f63130113..f5e50bf7ace0 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) | |||
245 | 245 | ||
246 | chan->conn = conn; | 246 | chan->conn = conn; |
247 | 247 | ||
248 | if (sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) { | 248 | if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) { |
249 | if (conn->hcon->type == LE_LINK) { | 249 | if (conn->hcon->type == LE_LINK) { |
250 | /* LE connection */ | 250 | /* LE connection */ |
251 | chan->omtu = L2CAP_LE_DEFAULT_MTU; | 251 | chan->omtu = L2CAP_LE_DEFAULT_MTU; |
@@ -256,7 +256,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) | |||
256 | chan->scid = l2cap_alloc_cid(conn); | 256 | chan->scid = l2cap_alloc_cid(conn); |
257 | chan->omtu = L2CAP_DEFAULT_MTU; | 257 | chan->omtu = L2CAP_DEFAULT_MTU; |
258 | } | 258 | } |
259 | } else if (sk->sk_type == SOCK_DGRAM) { | 259 | } else if (chan->chan_type == L2CAP_CHAN_CONN_LESS) { |
260 | /* Connectionless socket */ | 260 | /* Connectionless socket */ |
261 | chan->scid = L2CAP_CID_CONN_LESS; | 261 | chan->scid = L2CAP_CID_CONN_LESS; |
262 | chan->dcid = L2CAP_CID_CONN_LESS; | 262 | chan->dcid = L2CAP_CID_CONN_LESS; |
@@ -369,8 +369,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason) | |||
369 | 369 | ||
370 | case BT_CONNECTED: | 370 | case BT_CONNECTED: |
371 | case BT_CONFIG: | 371 | case BT_CONFIG: |
372 | if ((sk->sk_type == SOCK_SEQPACKET || | 372 | if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED && |
373 | sk->sk_type == SOCK_STREAM) && | ||
374 | conn->hcon->type == ACL_LINK) { | 373 | conn->hcon->type == ACL_LINK) { |
375 | l2cap_sock_set_timer(sk, sk->sk_sndtimeo); | 374 | l2cap_sock_set_timer(sk, sk->sk_sndtimeo); |
376 | l2cap_send_disconn_req(conn, chan, reason); | 375 | l2cap_send_disconn_req(conn, chan, reason); |
@@ -379,8 +378,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason) | |||
379 | break; | 378 | break; |
380 | 379 | ||
381 | case BT_CONNECT2: | 380 | case BT_CONNECT2: |
382 | if ((sk->sk_type == SOCK_SEQPACKET || | 381 | if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED && |
383 | sk->sk_type == SOCK_STREAM) && | ||
384 | conn->hcon->type == ACL_LINK) { | 382 | conn->hcon->type == ACL_LINK) { |
385 | struct l2cap_conn_rsp rsp; | 383 | struct l2cap_conn_rsp rsp; |
386 | __u16 result; | 384 | __u16 result; |
@@ -414,9 +412,7 @@ void __l2cap_chan_close(struct l2cap_chan *chan, int reason) | |||
414 | 412 | ||
415 | static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) | 413 | static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) |
416 | { | 414 | { |
417 | struct sock *sk = chan->sk; | 415 | if (chan->chan_type == L2CAP_CHAN_RAW) { |
418 | |||
419 | if (sk->sk_type == SOCK_RAW) { | ||
420 | switch (chan->sec_level) { | 416 | switch (chan->sec_level) { |
421 | case BT_SECURITY_HIGH: | 417 | case BT_SECURITY_HIGH: |
422 | return HCI_AT_DEDICATED_BONDING_MITM; | 418 | return HCI_AT_DEDICATED_BONDING_MITM; |
@@ -657,8 +653,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) | |||
657 | 653 | ||
658 | bh_lock_sock(sk); | 654 | bh_lock_sock(sk); |
659 | 655 | ||
660 | if (sk->sk_type != SOCK_SEQPACKET && | 656 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { |
661 | sk->sk_type != SOCK_STREAM) { | ||
662 | bh_unlock_sock(sk); | 657 | bh_unlock_sock(sk); |
663 | continue; | 658 | continue; |
664 | } | 659 | } |
@@ -852,8 +847,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) | |||
852 | sk->sk_state_change(sk); | 847 | sk->sk_state_change(sk); |
853 | } | 848 | } |
854 | 849 | ||
855 | if (sk->sk_type != SOCK_SEQPACKET && | 850 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { |
856 | sk->sk_type != SOCK_STREAM) { | ||
857 | l2cap_sock_clear_timer(sk); | 851 | l2cap_sock_clear_timer(sk); |
858 | sk->sk_state = BT_CONNECTED; | 852 | sk->sk_state = BT_CONNECTED; |
859 | sk->sk_state_change(sk); | 853 | sk->sk_state_change(sk); |
@@ -1056,8 +1050,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan) | |||
1056 | l2cap_sock_set_timer(sk, sk->sk_sndtimeo); | 1050 | l2cap_sock_set_timer(sk, sk->sk_sndtimeo); |
1057 | 1051 | ||
1058 | if (hcon->state == BT_CONNECTED) { | 1052 | if (hcon->state == BT_CONNECTED) { |
1059 | if (sk->sk_type != SOCK_SEQPACKET && | 1053 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { |
1060 | sk->sk_type != SOCK_STREAM) { | ||
1061 | l2cap_sock_clear_timer(sk); | 1054 | l2cap_sock_clear_timer(sk); |
1062 | if (l2cap_check_security(chan)) | 1055 | if (l2cap_check_security(chan)) |
1063 | sk->sk_state = BT_CONNECTED; | 1056 | sk->sk_state = BT_CONNECTED; |
@@ -1537,13 +1530,12 @@ int l2cap_sar_segment_sdu(struct l2cap_chan *chan, struct msghdr *msg, size_t le | |||
1537 | 1530 | ||
1538 | int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) | 1531 | int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) |
1539 | { | 1532 | { |
1540 | struct sock *sk = chan->sk; | ||
1541 | struct sk_buff *skb; | 1533 | struct sk_buff *skb; |
1542 | u16 control; | 1534 | u16 control; |
1543 | int err; | 1535 | int err; |
1544 | 1536 | ||
1545 | /* Connectionless channel */ | 1537 | /* Connectionless channel */ |
1546 | if (sk->sk_type == SOCK_DGRAM) { | 1538 | if (chan->chan_type == L2CAP_CHAN_CONN_LESS) { |
1547 | skb = l2cap_create_connless_pdu(chan, msg, len); | 1539 | skb = l2cap_create_connless_pdu(chan, msg, len); |
1548 | if (IS_ERR(skb)) | 1540 | if (IS_ERR(skb)) |
1549 | return PTR_ERR(skb); | 1541 | return PTR_ERR(skb); |
@@ -1650,7 +1642,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb) | |||
1650 | read_lock(&conn->chan_lock); | 1642 | read_lock(&conn->chan_lock); |
1651 | list_for_each_entry(chan, &conn->chan_l, list) { | 1643 | list_for_each_entry(chan, &conn->chan_l, list) { |
1652 | struct sock *sk = chan->sk; | 1644 | struct sock *sk = chan->sk; |
1653 | if (sk->sk_type != SOCK_RAW) | 1645 | if (chan->chan_type != L2CAP_CHAN_RAW) |
1654 | continue; | 1646 | continue; |
1655 | 1647 | ||
1656 | /* Don't send frame to the socket it came from */ | 1648 | /* Don't send frame to the socket it came from */ |
@@ -4100,7 +4092,7 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt) | |||
4100 | { | 4092 | { |
4101 | struct sock *sk = chan->sk; | 4093 | struct sock *sk = chan->sk; |
4102 | 4094 | ||
4103 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM) | 4095 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) |
4104 | return; | 4096 | return; |
4105 | 4097 | ||
4106 | if (encrypt == 0x00) { | 4098 | if (encrypt == 0x00) { |
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 0ecf214bd30e..2fcdf5eacb4d 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 | |||
162 | 162 | ||
163 | lock_sock(sk); | 163 | lock_sock(sk); |
164 | 164 | ||
165 | if ((sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) | 165 | if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED |
166 | && !(la.l2_psm || la.l2_cid)) { | 166 | && !(la.l2_psm || la.l2_cid)) { |
167 | err = -EINVAL; | 167 | err = -EINVAL; |
168 | goto done; | 168 | goto done; |
@@ -204,8 +204,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al | |||
204 | } | 204 | } |
205 | 205 | ||
206 | /* PSM must be odd and lsb of upper byte must be 0 */ | 206 | /* PSM must be odd and lsb of upper byte must be 0 */ |
207 | if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && | 207 | if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && !la.l2_cid && |
208 | sk->sk_type != SOCK_RAW && !la.l2_cid) { | 208 | chan->chan_type != L2CAP_CHAN_RAW) { |
209 | err = -EINVAL; | 209 | err = -EINVAL; |
210 | goto done; | 210 | goto done; |
211 | } | 211 | } |
@@ -453,8 +453,8 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch | |||
453 | 453 | ||
454 | switch (optname) { | 454 | switch (optname) { |
455 | case BT_SECURITY: | 455 | case BT_SECURITY: |
456 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM | 456 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
457 | && sk->sk_type != SOCK_RAW) { | 457 | chan->chan_type != L2CAP_CHAN_RAW) { |
458 | err = -EINVAL; | 458 | err = -EINVAL; |
459 | break; | 459 | break; |
460 | } | 460 | } |
@@ -599,8 +599,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch | |||
599 | 599 | ||
600 | switch (optname) { | 600 | switch (optname) { |
601 | case BT_SECURITY: | 601 | case BT_SECURITY: |
602 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM | 602 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
603 | && sk->sk_type != SOCK_RAW) { | 603 | chan->chan_type != L2CAP_CHAN_RAW) { |
604 | err = -EINVAL; | 604 | err = -EINVAL; |
605 | break; | 605 | break; |
606 | } | 606 | } |
@@ -806,6 +806,7 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
806 | sk->sk_type = parent->sk_type; | 806 | sk->sk_type = parent->sk_type; |
807 | bt_sk(sk)->defer_setup = bt_sk(parent)->defer_setup; | 807 | bt_sk(sk)->defer_setup = bt_sk(parent)->defer_setup; |
808 | 808 | ||
809 | chan->chan_type = pchan->chan_type; | ||
809 | chan->imtu = pchan->imtu; | 810 | chan->imtu = pchan->imtu; |
810 | chan->omtu = pchan->omtu; | 811 | chan->omtu = pchan->omtu; |
811 | chan->conf_state = pchan->conf_state; | 812 | chan->conf_state = pchan->conf_state; |
@@ -818,6 +819,20 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
818 | chan->force_reliable = pchan->force_reliable; | 819 | chan->force_reliable = pchan->force_reliable; |
819 | chan->flushable = pchan->flushable; | 820 | chan->flushable = pchan->flushable; |
820 | } else { | 821 | } else { |
822 | |||
823 | switch (sk->sk_type) { | ||
824 | case SOCK_RAW: | ||
825 | chan->chan_type = L2CAP_CHAN_RAW; | ||
826 | break; | ||
827 | case SOCK_DGRAM: | ||
828 | chan->chan_type = L2CAP_CHAN_CONN_LESS; | ||
829 | break; | ||
830 | case SOCK_SEQPACKET: | ||
831 | case SOCK_STREAM: | ||
832 | chan->chan_type = L2CAP_CHAN_CONN_ORIENTED; | ||
833 | break; | ||
834 | } | ||
835 | |||
821 | chan->imtu = L2CAP_DEFAULT_MTU; | 836 | chan->imtu = L2CAP_DEFAULT_MTU; |
822 | chan->omtu = 0; | 837 | chan->omtu = 0; |
823 | if (!disable_ertm && sk->sk_type == SOCK_STREAM) { | 838 | if (!disable_ertm && sk->sk_type == SOCK_STREAM) { |