diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-02-04 00:20:52 -0500 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-02-07 22:43:31 -0500 |
commit | fd83ccdb393e3190633e0240dd73faac8998164b (patch) | |
tree | a5d0c8c4fd9a99deb6e0aa25940d7b2d7682582e /net/bluetooth | |
parent | dcba0dba54b566a08376f93cab35cdabd6abda20 (diff) |
Bluetooth: move l2cap_sock_sendmsg() to l2cap_sock.c
Also moves some L2CAP sending functions declaration to l2cap.h
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 116 | ||||
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 102 |
2 files changed, 109 insertions, 109 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 6e48e580555e..da9b3a44b0f0 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -993,7 +993,7 @@ static void l2cap_drop_acked_frames(struct sock *sk) | |||
993 | del_timer(&l2cap_pi(sk)->retrans_timer); | 993 | del_timer(&l2cap_pi(sk)->retrans_timer); |
994 | } | 994 | } |
995 | 995 | ||
996 | static inline void l2cap_do_send(struct sock *sk, struct sk_buff *skb) | 996 | void l2cap_do_send(struct sock *sk, struct sk_buff *skb) |
997 | { | 997 | { |
998 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 998 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
999 | struct hci_conn *hcon = pi->conn->hcon; | 999 | struct hci_conn *hcon = pi->conn->hcon; |
@@ -1009,7 +1009,7 @@ static inline void l2cap_do_send(struct sock *sk, struct sk_buff *skb) | |||
1009 | hci_send_acl(hcon, skb, flags); | 1009 | hci_send_acl(hcon, skb, flags); |
1010 | } | 1010 | } |
1011 | 1011 | ||
1012 | static void l2cap_streaming_send(struct sock *sk) | 1012 | void l2cap_streaming_send(struct sock *sk) |
1013 | { | 1013 | { |
1014 | struct sk_buff *skb; | 1014 | struct sk_buff *skb; |
1015 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1015 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
@@ -1078,7 +1078,7 @@ static void l2cap_retransmit_one_frame(struct sock *sk, u8 tx_seq) | |||
1078 | l2cap_do_send(sk, tx_skb); | 1078 | l2cap_do_send(sk, tx_skb); |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | static int l2cap_ertm_send(struct sock *sk) | 1081 | int l2cap_ertm_send(struct sock *sk) |
1082 | { | 1082 | { |
1083 | struct sk_buff *skb, *tx_skb; | 1083 | struct sk_buff *skb, *tx_skb; |
1084 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1084 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
@@ -1218,7 +1218,7 @@ static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, in | |||
1218 | return sent; | 1218 | return sent; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | static struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len) | 1221 | struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len) |
1222 | { | 1222 | { |
1223 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; | 1223 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; |
1224 | struct sk_buff *skb; | 1224 | struct sk_buff *skb; |
@@ -1247,7 +1247,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr | |||
1247 | return skb; | 1247 | return skb; |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | static struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len) | 1250 | struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len) |
1251 | { | 1251 | { |
1252 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; | 1252 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; |
1253 | struct sk_buff *skb; | 1253 | struct sk_buff *skb; |
@@ -1275,7 +1275,7 @@ static struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *ms | |||
1275 | return skb; | 1275 | return skb; |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | static struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen) | 1278 | struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen) |
1279 | { | 1279 | { |
1280 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; | 1280 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; |
1281 | struct sk_buff *skb; | 1281 | struct sk_buff *skb; |
@@ -1320,7 +1320,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *m | |||
1320 | return skb; | 1320 | return skb; |
1321 | } | 1321 | } |
1322 | 1322 | ||
1323 | static inline int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len) | 1323 | int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len) |
1324 | { | 1324 | { |
1325 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1325 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
1326 | struct sk_buff *skb; | 1326 | struct sk_buff *skb; |
@@ -1366,108 +1366,6 @@ static inline int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, siz | |||
1366 | return size; | 1366 | return size; |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len) | ||
1370 | { | ||
1371 | struct sock *sk = sock->sk; | ||
1372 | struct l2cap_pinfo *pi = l2cap_pi(sk); | ||
1373 | struct sk_buff *skb; | ||
1374 | u16 control; | ||
1375 | int err; | ||
1376 | |||
1377 | BT_DBG("sock %p, sk %p", sock, sk); | ||
1378 | |||
1379 | err = sock_error(sk); | ||
1380 | if (err) | ||
1381 | return err; | ||
1382 | |||
1383 | if (msg->msg_flags & MSG_OOB) | ||
1384 | return -EOPNOTSUPP; | ||
1385 | |||
1386 | lock_sock(sk); | ||
1387 | |||
1388 | if (sk->sk_state != BT_CONNECTED) { | ||
1389 | err = -ENOTCONN; | ||
1390 | goto done; | ||
1391 | } | ||
1392 | |||
1393 | /* Connectionless channel */ | ||
1394 | if (sk->sk_type == SOCK_DGRAM) { | ||
1395 | skb = l2cap_create_connless_pdu(sk, msg, len); | ||
1396 | if (IS_ERR(skb)) { | ||
1397 | err = PTR_ERR(skb); | ||
1398 | } else { | ||
1399 | l2cap_do_send(sk, skb); | ||
1400 | err = len; | ||
1401 | } | ||
1402 | goto done; | ||
1403 | } | ||
1404 | |||
1405 | switch (pi->mode) { | ||
1406 | case L2CAP_MODE_BASIC: | ||
1407 | /* Check outgoing MTU */ | ||
1408 | if (len > pi->omtu) { | ||
1409 | err = -EMSGSIZE; | ||
1410 | goto done; | ||
1411 | } | ||
1412 | |||
1413 | /* Create a basic PDU */ | ||
1414 | skb = l2cap_create_basic_pdu(sk, msg, len); | ||
1415 | if (IS_ERR(skb)) { | ||
1416 | err = PTR_ERR(skb); | ||
1417 | goto done; | ||
1418 | } | ||
1419 | |||
1420 | l2cap_do_send(sk, skb); | ||
1421 | err = len; | ||
1422 | break; | ||
1423 | |||
1424 | case L2CAP_MODE_ERTM: | ||
1425 | case L2CAP_MODE_STREAMING: | ||
1426 | /* Entire SDU fits into one PDU */ | ||
1427 | if (len <= pi->remote_mps) { | ||
1428 | control = L2CAP_SDU_UNSEGMENTED; | ||
1429 | skb = l2cap_create_iframe_pdu(sk, msg, len, control, 0); | ||
1430 | if (IS_ERR(skb)) { | ||
1431 | err = PTR_ERR(skb); | ||
1432 | goto done; | ||
1433 | } | ||
1434 | __skb_queue_tail(TX_QUEUE(sk), skb); | ||
1435 | |||
1436 | if (sk->sk_send_head == NULL) | ||
1437 | sk->sk_send_head = skb; | ||
1438 | |||
1439 | } else { | ||
1440 | /* Segment SDU into multiples PDUs */ | ||
1441 | err = l2cap_sar_segment_sdu(sk, msg, len); | ||
1442 | if (err < 0) | ||
1443 | goto done; | ||
1444 | } | ||
1445 | |||
1446 | if (pi->mode == L2CAP_MODE_STREAMING) { | ||
1447 | l2cap_streaming_send(sk); | ||
1448 | } else { | ||
1449 | if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) && | ||
1450 | (pi->conn_state & L2CAP_CONN_WAIT_F)) { | ||
1451 | err = len; | ||
1452 | break; | ||
1453 | } | ||
1454 | err = l2cap_ertm_send(sk); | ||
1455 | } | ||
1456 | |||
1457 | if (err >= 0) | ||
1458 | err = len; | ||
1459 | break; | ||
1460 | |||
1461 | default: | ||
1462 | BT_DBG("bad state %1.1x", pi->mode); | ||
1463 | err = -EBADFD; | ||
1464 | } | ||
1465 | |||
1466 | done: | ||
1467 | release_sock(sk); | ||
1468 | return err; | ||
1469 | } | ||
1470 | |||
1471 | static void l2cap_chan_ready(struct sock *sk) | 1369 | static void l2cap_chan_ready(struct sock *sk) |
1472 | { | 1370 | { |
1473 | struct sock *parent = bt_sk(sk)->parent; | 1371 | struct sock *parent = bt_sk(sk)->parent; |
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 93af233bb167..fe4f834f03dd 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -681,6 +681,108 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch | |||
681 | return err; | 681 | return err; |
682 | } | 682 | } |
683 | 683 | ||
684 | static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len) | ||
685 | { | ||
686 | struct sock *sk = sock->sk; | ||
687 | struct l2cap_pinfo *pi = l2cap_pi(sk); | ||
688 | struct sk_buff *skb; | ||
689 | u16 control; | ||
690 | int err; | ||
691 | |||
692 | BT_DBG("sock %p, sk %p", sock, sk); | ||
693 | |||
694 | err = sock_error(sk); | ||
695 | if (err) | ||
696 | return err; | ||
697 | |||
698 | if (msg->msg_flags & MSG_OOB) | ||
699 | return -EOPNOTSUPP; | ||
700 | |||
701 | lock_sock(sk); | ||
702 | |||
703 | if (sk->sk_state != BT_CONNECTED) { | ||
704 | err = -ENOTCONN; | ||
705 | goto done; | ||
706 | } | ||
707 | |||
708 | /* Connectionless channel */ | ||
709 | if (sk->sk_type == SOCK_DGRAM) { | ||
710 | skb = l2cap_create_connless_pdu(sk, msg, len); | ||
711 | if (IS_ERR(skb)) { | ||
712 | err = PTR_ERR(skb); | ||
713 | } else { | ||
714 | l2cap_do_send(sk, skb); | ||
715 | err = len; | ||
716 | } | ||
717 | goto done; | ||
718 | } | ||
719 | |||
720 | switch (pi->mode) { | ||
721 | case L2CAP_MODE_BASIC: | ||
722 | /* Check outgoing MTU */ | ||
723 | if (len > pi->omtu) { | ||
724 | err = -EMSGSIZE; | ||
725 | goto done; | ||
726 | } | ||
727 | |||
728 | /* Create a basic PDU */ | ||
729 | skb = l2cap_create_basic_pdu(sk, msg, len); | ||
730 | if (IS_ERR(skb)) { | ||
731 | err = PTR_ERR(skb); | ||
732 | goto done; | ||
733 | } | ||
734 | |||
735 | l2cap_do_send(sk, skb); | ||
736 | err = len; | ||
737 | break; | ||
738 | |||
739 | case L2CAP_MODE_ERTM: | ||
740 | case L2CAP_MODE_STREAMING: | ||
741 | /* Entire SDU fits into one PDU */ | ||
742 | if (len <= pi->remote_mps) { | ||
743 | control = L2CAP_SDU_UNSEGMENTED; | ||
744 | skb = l2cap_create_iframe_pdu(sk, msg, len, control, 0); | ||
745 | if (IS_ERR(skb)) { | ||
746 | err = PTR_ERR(skb); | ||
747 | goto done; | ||
748 | } | ||
749 | __skb_queue_tail(TX_QUEUE(sk), skb); | ||
750 | |||
751 | if (sk->sk_send_head == NULL) | ||
752 | sk->sk_send_head = skb; | ||
753 | |||
754 | } else { | ||
755 | /* Segment SDU into multiples PDUs */ | ||
756 | err = l2cap_sar_segment_sdu(sk, msg, len); | ||
757 | if (err < 0) | ||
758 | goto done; | ||
759 | } | ||
760 | |||
761 | if (pi->mode == L2CAP_MODE_STREAMING) { | ||
762 | l2cap_streaming_send(sk); | ||
763 | } else { | ||
764 | if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) && | ||
765 | (pi->conn_state & L2CAP_CONN_WAIT_F)) { | ||
766 | err = len; | ||
767 | break; | ||
768 | } | ||
769 | err = l2cap_ertm_send(sk); | ||
770 | } | ||
771 | |||
772 | if (err >= 0) | ||
773 | err = len; | ||
774 | break; | ||
775 | |||
776 | default: | ||
777 | BT_DBG("bad state %1.1x", pi->mode); | ||
778 | err = -EBADFD; | ||
779 | } | ||
780 | |||
781 | done: | ||
782 | release_sock(sk); | ||
783 | return err; | ||
784 | } | ||
785 | |||
684 | static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags) | 786 | static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags) |
685 | { | 787 | { |
686 | struct sock *sk = sock->sk; | 788 | struct sock *sk = sock->sk; |