diff options
Diffstat (limited to 'net/bluetooth/rfcomm')
-rw-r--r-- | net/bluetooth/rfcomm/core.c | 43 | ||||
-rw-r--r-- | net/bluetooth/rfcomm/sock.c | 104 | ||||
-rw-r--r-- | net/bluetooth/rfcomm/tty.c | 4 |
3 files changed, 28 insertions, 123 deletions
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 7dca91bb8c57..39a5d87e33b4 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c | |||
@@ -113,11 +113,10 @@ static void rfcomm_session_del(struct rfcomm_session *s); | |||
113 | #define __get_rpn_stop_bits(line) (((line) >> 2) & 0x1) | 113 | #define __get_rpn_stop_bits(line) (((line) >> 2) & 0x1) |
114 | #define __get_rpn_parity(line) (((line) >> 3) & 0x7) | 114 | #define __get_rpn_parity(line) (((line) >> 3) & 0x7) |
115 | 115 | ||
116 | static inline void rfcomm_schedule(uint event) | 116 | static inline void rfcomm_schedule(void) |
117 | { | 117 | { |
118 | if (!rfcomm_thread) | 118 | if (!rfcomm_thread) |
119 | return; | 119 | return; |
120 | //set_bit(event, &rfcomm_event); | ||
121 | set_bit(RFCOMM_SCHED_WAKEUP, &rfcomm_event); | 120 | set_bit(RFCOMM_SCHED_WAKEUP, &rfcomm_event); |
122 | wake_up_process(rfcomm_thread); | 121 | wake_up_process(rfcomm_thread); |
123 | } | 122 | } |
@@ -179,13 +178,13 @@ static unsigned char rfcomm_crc_table[256] = { | |||
179 | /* FCS on 2 bytes */ | 178 | /* FCS on 2 bytes */ |
180 | static inline u8 __fcs(u8 *data) | 179 | static inline u8 __fcs(u8 *data) |
181 | { | 180 | { |
182 | return (0xff - __crc(data)); | 181 | return 0xff - __crc(data); |
183 | } | 182 | } |
184 | 183 | ||
185 | /* FCS on 3 bytes */ | 184 | /* FCS on 3 bytes */ |
186 | static inline u8 __fcs2(u8 *data) | 185 | static inline u8 __fcs2(u8 *data) |
187 | { | 186 | { |
188 | return (0xff - rfcomm_crc_table[__crc(data) ^ data[2]]); | 187 | return 0xff - rfcomm_crc_table[__crc(data) ^ data[2]]; |
189 | } | 188 | } |
190 | 189 | ||
191 | /* Check FCS */ | 190 | /* Check FCS */ |
@@ -203,13 +202,13 @@ static inline int __check_fcs(u8 *data, int type, u8 fcs) | |||
203 | static void rfcomm_l2state_change(struct sock *sk) | 202 | static void rfcomm_l2state_change(struct sock *sk) |
204 | { | 203 | { |
205 | BT_DBG("%p state %d", sk, sk->sk_state); | 204 | BT_DBG("%p state %d", sk, sk->sk_state); |
206 | rfcomm_schedule(RFCOMM_SCHED_STATE); | 205 | rfcomm_schedule(); |
207 | } | 206 | } |
208 | 207 | ||
209 | static void rfcomm_l2data_ready(struct sock *sk, int bytes) | 208 | static void rfcomm_l2data_ready(struct sock *sk, int bytes) |
210 | { | 209 | { |
211 | BT_DBG("%p bytes %d", sk, bytes); | 210 | BT_DBG("%p bytes %d", sk, bytes); |
212 | rfcomm_schedule(RFCOMM_SCHED_RX); | 211 | rfcomm_schedule(); |
213 | } | 212 | } |
214 | 213 | ||
215 | static int rfcomm_l2sock_create(struct socket **sock) | 214 | static int rfcomm_l2sock_create(struct socket **sock) |
@@ -255,7 +254,7 @@ static void rfcomm_session_timeout(unsigned long arg) | |||
255 | BT_DBG("session %p state %ld", s, s->state); | 254 | BT_DBG("session %p state %ld", s, s->state); |
256 | 255 | ||
257 | set_bit(RFCOMM_TIMED_OUT, &s->flags); | 256 | set_bit(RFCOMM_TIMED_OUT, &s->flags); |
258 | rfcomm_schedule(RFCOMM_SCHED_TIMEO); | 257 | rfcomm_schedule(); |
259 | } | 258 | } |
260 | 259 | ||
261 | static void rfcomm_session_set_timer(struct rfcomm_session *s, long timeout) | 260 | static void rfcomm_session_set_timer(struct rfcomm_session *s, long timeout) |
@@ -283,7 +282,7 @@ static void rfcomm_dlc_timeout(unsigned long arg) | |||
283 | 282 | ||
284 | set_bit(RFCOMM_TIMED_OUT, &d->flags); | 283 | set_bit(RFCOMM_TIMED_OUT, &d->flags); |
285 | rfcomm_dlc_put(d); | 284 | rfcomm_dlc_put(d); |
286 | rfcomm_schedule(RFCOMM_SCHED_TIMEO); | 285 | rfcomm_schedule(); |
287 | } | 286 | } |
288 | 287 | ||
289 | static void rfcomm_dlc_set_timer(struct rfcomm_dlc *d, long timeout) | 288 | static void rfcomm_dlc_set_timer(struct rfcomm_dlc *d, long timeout) |
@@ -465,7 +464,7 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) | |||
465 | case BT_CONFIG: | 464 | case BT_CONFIG: |
466 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { | 465 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { |
467 | set_bit(RFCOMM_AUTH_REJECT, &d->flags); | 466 | set_bit(RFCOMM_AUTH_REJECT, &d->flags); |
468 | rfcomm_schedule(RFCOMM_SCHED_AUTH); | 467 | rfcomm_schedule(); |
469 | break; | 468 | break; |
470 | } | 469 | } |
471 | /* Fall through */ | 470 | /* Fall through */ |
@@ -485,7 +484,7 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) | |||
485 | case BT_CONNECT2: | 484 | case BT_CONNECT2: |
486 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { | 485 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { |
487 | set_bit(RFCOMM_AUTH_REJECT, &d->flags); | 486 | set_bit(RFCOMM_AUTH_REJECT, &d->flags); |
488 | rfcomm_schedule(RFCOMM_SCHED_AUTH); | 487 | rfcomm_schedule(); |
489 | break; | 488 | break; |
490 | } | 489 | } |
491 | /* Fall through */ | 490 | /* Fall through */ |
@@ -533,7 +532,7 @@ int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb) | |||
533 | skb_queue_tail(&d->tx_queue, skb); | 532 | skb_queue_tail(&d->tx_queue, skb); |
534 | 533 | ||
535 | if (!test_bit(RFCOMM_TX_THROTTLED, &d->flags)) | 534 | if (!test_bit(RFCOMM_TX_THROTTLED, &d->flags)) |
536 | rfcomm_schedule(RFCOMM_SCHED_TX); | 535 | rfcomm_schedule(); |
537 | return len; | 536 | return len; |
538 | } | 537 | } |
539 | 538 | ||
@@ -545,7 +544,7 @@ void __rfcomm_dlc_throttle(struct rfcomm_dlc *d) | |||
545 | d->v24_sig |= RFCOMM_V24_FC; | 544 | d->v24_sig |= RFCOMM_V24_FC; |
546 | set_bit(RFCOMM_MSC_PENDING, &d->flags); | 545 | set_bit(RFCOMM_MSC_PENDING, &d->flags); |
547 | } | 546 | } |
548 | rfcomm_schedule(RFCOMM_SCHED_TX); | 547 | rfcomm_schedule(); |
549 | } | 548 | } |
550 | 549 | ||
551 | void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d) | 550 | void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d) |
@@ -556,7 +555,7 @@ void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d) | |||
556 | d->v24_sig &= ~RFCOMM_V24_FC; | 555 | d->v24_sig &= ~RFCOMM_V24_FC; |
557 | set_bit(RFCOMM_MSC_PENDING, &d->flags); | 556 | set_bit(RFCOMM_MSC_PENDING, &d->flags); |
558 | } | 557 | } |
559 | rfcomm_schedule(RFCOMM_SCHED_TX); | 558 | rfcomm_schedule(); |
560 | } | 559 | } |
561 | 560 | ||
562 | /* | 561 | /* |
@@ -577,7 +576,7 @@ int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig) | |||
577 | d->v24_sig = v24_sig; | 576 | d->v24_sig = v24_sig; |
578 | 577 | ||
579 | if (!test_and_set_bit(RFCOMM_MSC_PENDING, &d->flags)) | 578 | if (!test_and_set_bit(RFCOMM_MSC_PENDING, &d->flags)) |
580 | rfcomm_schedule(RFCOMM_SCHED_TX); | 579 | rfcomm_schedule(); |
581 | 580 | ||
582 | return 0; | 581 | return 0; |
583 | } | 582 | } |
@@ -816,7 +815,7 @@ static int rfcomm_queue_disc(struct rfcomm_dlc *d) | |||
816 | cmd->fcs = __fcs2((u8 *) cmd); | 815 | cmd->fcs = __fcs2((u8 *) cmd); |
817 | 816 | ||
818 | skb_queue_tail(&d->tx_queue, skb); | 817 | skb_queue_tail(&d->tx_queue, skb); |
819 | rfcomm_schedule(RFCOMM_SCHED_TX); | 818 | rfcomm_schedule(); |
820 | return 0; | 819 | return 0; |
821 | } | 820 | } |
822 | 821 | ||
@@ -1415,8 +1414,8 @@ static int rfcomm_recv_rpn(struct rfcomm_session *s, int cr, int len, struct sk_ | |||
1415 | return 0; | 1414 | return 0; |
1416 | 1415 | ||
1417 | if (len == 1) { | 1416 | if (len == 1) { |
1418 | /* This is a request, return default settings */ | 1417 | /* This is a request, return default (according to ETSI TS 07.10) settings */ |
1419 | bit_rate = RFCOMM_RPN_BR_115200; | 1418 | bit_rate = RFCOMM_RPN_BR_9600; |
1420 | data_bits = RFCOMM_RPN_DATA_8; | 1419 | data_bits = RFCOMM_RPN_DATA_8; |
1421 | stop_bits = RFCOMM_RPN_STOP_1; | 1420 | stop_bits = RFCOMM_RPN_STOP_1; |
1422 | parity = RFCOMM_RPN_PARITY_NONE; | 1421 | parity = RFCOMM_RPN_PARITY_NONE; |
@@ -1431,9 +1430,9 @@ static int rfcomm_recv_rpn(struct rfcomm_session *s, int cr, int len, struct sk_ | |||
1431 | 1430 | ||
1432 | if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_BITRATE)) { | 1431 | if (rpn->param_mask & cpu_to_le16(RFCOMM_RPN_PM_BITRATE)) { |
1433 | bit_rate = rpn->bit_rate; | 1432 | bit_rate = rpn->bit_rate; |
1434 | if (bit_rate != RFCOMM_RPN_BR_115200) { | 1433 | if (bit_rate > RFCOMM_RPN_BR_230400) { |
1435 | BT_DBG("RPN bit rate mismatch 0x%x", bit_rate); | 1434 | BT_DBG("RPN bit rate mismatch 0x%x", bit_rate); |
1436 | bit_rate = RFCOMM_RPN_BR_115200; | 1435 | bit_rate = RFCOMM_RPN_BR_9600; |
1437 | rpn_mask ^= RFCOMM_RPN_PM_BITRATE; | 1436 | rpn_mask ^= RFCOMM_RPN_PM_BITRATE; |
1438 | } | 1437 | } |
1439 | } | 1438 | } |
@@ -1698,7 +1697,7 @@ static int rfcomm_recv_frame(struct rfcomm_session *s, struct sk_buff *skb) | |||
1698 | break; | 1697 | break; |
1699 | 1698 | ||
1700 | default: | 1699 | default: |
1701 | BT_ERR("Unknown packet type 0x%02x\n", type); | 1700 | BT_ERR("Unknown packet type 0x%02x", type); |
1702 | break; | 1701 | break; |
1703 | } | 1702 | } |
1704 | kfree_skb(skb); | 1703 | kfree_skb(skb); |
@@ -1884,7 +1883,7 @@ static inline void rfcomm_accept_connection(struct rfcomm_session *s) | |||
1884 | * L2CAP MTU minus UIH header and FCS. */ | 1883 | * L2CAP MTU minus UIH header and FCS. */ |
1885 | s->mtu = min(l2cap_pi(nsock->sk)->omtu, l2cap_pi(nsock->sk)->imtu) - 5; | 1884 | s->mtu = min(l2cap_pi(nsock->sk)->omtu, l2cap_pi(nsock->sk)->imtu) - 5; |
1886 | 1885 | ||
1887 | rfcomm_schedule(RFCOMM_SCHED_RX); | 1886 | rfcomm_schedule(); |
1888 | } else | 1887 | } else |
1889 | sock_release(nsock); | 1888 | sock_release(nsock); |
1890 | } | 1889 | } |
@@ -2093,7 +2092,7 @@ static void rfcomm_security_cfm(struct hci_conn *conn, u8 status, u8 encrypt) | |||
2093 | 2092 | ||
2094 | rfcomm_session_put(s); | 2093 | rfcomm_session_put(s); |
2095 | 2094 | ||
2096 | rfcomm_schedule(RFCOMM_SCHED_AUTH); | 2095 | rfcomm_schedule(); |
2097 | } | 2096 | } |
2098 | 2097 | ||
2099 | static struct hci_cb rfcomm_cb = { | 2098 | static struct hci_cb rfcomm_cb = { |
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 194b3a04cfd3..aec505f934df 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c | |||
@@ -621,121 +621,29 @@ static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
621 | return sent; | 621 | return sent; |
622 | } | 622 | } |
623 | 623 | ||
624 | static long rfcomm_sock_data_wait(struct sock *sk, long timeo) | ||
625 | { | ||
626 | DECLARE_WAITQUEUE(wait, current); | ||
627 | |||
628 | add_wait_queue(sk_sleep(sk), &wait); | ||
629 | for (;;) { | ||
630 | set_current_state(TASK_INTERRUPTIBLE); | ||
631 | |||
632 | if (!skb_queue_empty(&sk->sk_receive_queue) || | ||
633 | sk->sk_err || | ||
634 | (sk->sk_shutdown & RCV_SHUTDOWN) || | ||
635 | signal_pending(current) || | ||
636 | !timeo) | ||
637 | break; | ||
638 | |||
639 | set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags); | ||
640 | release_sock(sk); | ||
641 | timeo = schedule_timeout(timeo); | ||
642 | lock_sock(sk); | ||
643 | clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags); | ||
644 | } | ||
645 | |||
646 | __set_current_state(TASK_RUNNING); | ||
647 | remove_wait_queue(sk_sleep(sk), &wait); | ||
648 | return timeo; | ||
649 | } | ||
650 | |||
651 | static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock, | 624 | static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
652 | struct msghdr *msg, size_t size, int flags) | 625 | struct msghdr *msg, size_t size, int flags) |
653 | { | 626 | { |
654 | struct sock *sk = sock->sk; | 627 | struct sock *sk = sock->sk; |
655 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; | 628 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
656 | int err = 0; | 629 | int len; |
657 | size_t target, copied = 0; | ||
658 | long timeo; | ||
659 | 630 | ||
660 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { | 631 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { |
661 | rfcomm_dlc_accept(d); | 632 | rfcomm_dlc_accept(d); |
662 | return 0; | 633 | return 0; |
663 | } | 634 | } |
664 | 635 | ||
665 | if (flags & MSG_OOB) | 636 | len = bt_sock_stream_recvmsg(iocb, sock, msg, size, flags); |
666 | return -EOPNOTSUPP; | ||
667 | |||
668 | msg->msg_namelen = 0; | ||
669 | |||
670 | BT_DBG("sk %p size %zu", sk, size); | ||
671 | 637 | ||
672 | lock_sock(sk); | 638 | lock_sock(sk); |
639 | if (!(flags & MSG_PEEK) && len > 0) | ||
640 | atomic_sub(len, &sk->sk_rmem_alloc); | ||
673 | 641 | ||
674 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, size); | ||
675 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); | ||
676 | |||
677 | do { | ||
678 | struct sk_buff *skb; | ||
679 | int chunk; | ||
680 | |||
681 | skb = skb_dequeue(&sk->sk_receive_queue); | ||
682 | if (!skb) { | ||
683 | if (copied >= target) | ||
684 | break; | ||
685 | |||
686 | if ((err = sock_error(sk)) != 0) | ||
687 | break; | ||
688 | if (sk->sk_shutdown & RCV_SHUTDOWN) | ||
689 | break; | ||
690 | |||
691 | err = -EAGAIN; | ||
692 | if (!timeo) | ||
693 | break; | ||
694 | |||
695 | timeo = rfcomm_sock_data_wait(sk, timeo); | ||
696 | |||
697 | if (signal_pending(current)) { | ||
698 | err = sock_intr_errno(timeo); | ||
699 | goto out; | ||
700 | } | ||
701 | continue; | ||
702 | } | ||
703 | |||
704 | chunk = min_t(unsigned int, skb->len, size); | ||
705 | if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) { | ||
706 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
707 | if (!copied) | ||
708 | copied = -EFAULT; | ||
709 | break; | ||
710 | } | ||
711 | copied += chunk; | ||
712 | size -= chunk; | ||
713 | |||
714 | sock_recv_ts_and_drops(msg, sk, skb); | ||
715 | |||
716 | if (!(flags & MSG_PEEK)) { | ||
717 | atomic_sub(chunk, &sk->sk_rmem_alloc); | ||
718 | |||
719 | skb_pull(skb, chunk); | ||
720 | if (skb->len) { | ||
721 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
722 | break; | ||
723 | } | ||
724 | kfree_skb(skb); | ||
725 | |||
726 | } else { | ||
727 | /* put message back and return */ | ||
728 | skb_queue_head(&sk->sk_receive_queue, skb); | ||
729 | break; | ||
730 | } | ||
731 | } while (size); | ||
732 | |||
733 | out: | ||
734 | if (atomic_read(&sk->sk_rmem_alloc) <= (sk->sk_rcvbuf >> 2)) | 642 | if (atomic_read(&sk->sk_rmem_alloc) <= (sk->sk_rcvbuf >> 2)) |
735 | rfcomm_dlc_unthrottle(rfcomm_pi(sk)->dlc); | 643 | rfcomm_dlc_unthrottle(rfcomm_pi(sk)->dlc); |
736 | |||
737 | release_sock(sk); | 644 | release_sock(sk); |
738 | return copied ? : err; | 645 | |
646 | return len; | ||
739 | } | 647 | } |
740 | 648 | ||
741 | static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen) | 649 | static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen) |
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index 84c2a4d013c6..a9b81f5dacd1 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c | |||
@@ -183,9 +183,7 @@ static struct device *rfcomm_get_device(struct rfcomm_dev *dev) | |||
183 | static ssize_t show_address(struct device *tty_dev, struct device_attribute *attr, char *buf) | 183 | static ssize_t show_address(struct device *tty_dev, struct device_attribute *attr, char *buf) |
184 | { | 184 | { |
185 | struct rfcomm_dev *dev = dev_get_drvdata(tty_dev); | 185 | struct rfcomm_dev *dev = dev_get_drvdata(tty_dev); |
186 | bdaddr_t bdaddr; | 186 | return sprintf(buf, "%s\n", batostr(&dev->dst)); |
187 | baswap(&bdaddr, &dev->dst); | ||
188 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | ||
189 | } | 187 | } |
190 | 188 | ||
191 | static ssize_t show_channel(struct device *tty_dev, struct device_attribute *attr, char *buf) | 189 | static ssize_t show_channel(struct device *tty_dev, struct device_attribute *attr, char *buf) |