hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/net/bluetooth/rfcomm/core.c
....@@ -40,7 +40,6 @@
4040 static bool disable_cfc;
4141 static bool l2cap_ertm;
4242 static int channel_mtu = -1;
43
-static unsigned int l2cap_mtu = RFCOMM_MAX_L2CAP_MTU;
4443
4544 static struct task_struct *rfcomm_thread;
4645
....@@ -73,8 +72,6 @@
7372
7473 /* ---- RFCOMM frame parsing macros ---- */
7574 #define __get_dlci(b) ((b & 0xfc) >> 2)
76
-#define __get_channel(b) ((b & 0xf8) >> 3)
77
-#define __get_dir(b) ((b & 0x04) >> 2)
7875 #define __get_type(b) ((b & 0xef))
7976
8077 #define __test_ea(b) ((b & 0x01))
....@@ -87,7 +84,6 @@
8784 #define __ctrl(type, pf) (((type & 0xef) | (pf << 4)))
8885 #define __dlci(dir, chn) (((chn & 0x1f) << 1) | dir)
8986 #define __srv_channel(dlci) (dlci >> 1)
90
-#define __dir(dlci) (dlci & 0x01)
9187
9288 #define __len8(len) (((len) << 1) | 1)
9389 #define __len16(len) ((len) << 1)
....@@ -483,6 +479,7 @@
483479 /* if closing a dlc in a session that hasn't been started,
484480 * just close and unlink the dlc
485481 */
482
+ fallthrough;
486483
487484 default:
488485 rfcomm_dlc_clear_timer(d);
....@@ -552,22 +549,58 @@
552549 return dlc;
553550 }
554551
555
-int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb)
552
+static int rfcomm_dlc_send_frag(struct rfcomm_dlc *d, struct sk_buff *frag)
556553 {
557
- int len = skb->len;
558
-
559
- if (d->state != BT_CONNECTED)
560
- return -ENOTCONN;
554
+ int len = frag->len;
561555
562556 BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len);
563557
564558 if (len > d->mtu)
565559 return -EINVAL;
566560
567
- rfcomm_make_uih(skb, d->addr);
568
- skb_queue_tail(&d->tx_queue, skb);
561
+ rfcomm_make_uih(frag, d->addr);
562
+ __skb_queue_tail(&d->tx_queue, frag);
569563
570
- if (!test_bit(RFCOMM_TX_THROTTLED, &d->flags))
564
+ return len;
565
+}
566
+
567
+int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb)
568
+{
569
+ unsigned long flags;
570
+ struct sk_buff *frag, *next;
571
+ int len;
572
+
573
+ if (d->state != BT_CONNECTED)
574
+ return -ENOTCONN;
575
+
576
+ frag = skb_shinfo(skb)->frag_list;
577
+ skb_shinfo(skb)->frag_list = NULL;
578
+
579
+ /* Queue all fragments atomically. */
580
+ spin_lock_irqsave(&d->tx_queue.lock, flags);
581
+
582
+ len = rfcomm_dlc_send_frag(d, skb);
583
+ if (len < 0 || !frag)
584
+ goto unlock;
585
+
586
+ for (; frag; frag = next) {
587
+ int ret;
588
+
589
+ next = frag->next;
590
+
591
+ ret = rfcomm_dlc_send_frag(d, frag);
592
+ if (ret < 0) {
593
+ dev_kfree_skb_irq(frag);
594
+ goto unlock;
595
+ }
596
+
597
+ len += ret;
598
+ }
599
+
600
+unlock:
601
+ spin_unlock_irqrestore(&d->tx_queue.lock, flags);
602
+
603
+ if (len > 0 && !test_bit(RFCOMM_TX_THROTTLED, &d->flags))
571604 rfcomm_schedule();
572605 return len;
573606 }
....@@ -751,7 +784,8 @@
751784 /* Set L2CAP options */
752785 sk = sock->sk;
753786 lock_sock(sk);
754
- l2cap_pi(sk)->chan->imtu = l2cap_mtu;
787
+ /* Set MTU to 0 so L2CAP can auto select the MTU */
788
+ l2cap_pi(sk)->chan->imtu = 0;
755789 l2cap_pi(sk)->chan->sec_level = sec_level;
756790 if (l2cap_ertm)
757791 l2cap_pi(sk)->chan->mode = L2CAP_MODE_ERTM;
....@@ -2038,7 +2072,8 @@
20382072 /* Set L2CAP options */
20392073 sk = sock->sk;
20402074 lock_sock(sk);
2041
- l2cap_pi(sk)->chan->imtu = l2cap_mtu;
2075
+ /* Set MTU to 0 so L2CAP can auto select the MTU */
2076
+ l2cap_pi(sk)->chan->imtu = 0;
20422077 release_sock(sk);
20432078
20442079 /* Start listening on the socket */
....@@ -2166,17 +2201,7 @@
21662201 return 0;
21672202 }
21682203
2169
-static int rfcomm_dlc_debugfs_open(struct inode *inode, struct file *file)
2170
-{
2171
- return single_open(file, rfcomm_dlc_debugfs_show, inode->i_private);
2172
-}
2173
-
2174
-static const struct file_operations rfcomm_dlc_debugfs_fops = {
2175
- .open = rfcomm_dlc_debugfs_open,
2176
- .read = seq_read,
2177
- .llseek = seq_lseek,
2178
- .release = single_release,
2179
-};
2204
+DEFINE_SHOW_ATTRIBUTE(rfcomm_dlc_debugfs);
21802205
21812206 static struct dentry *rfcomm_dlc_debugfs;
21822207
....@@ -2245,9 +2270,6 @@
22452270
22462271 module_param(channel_mtu, int, 0644);
22472272 MODULE_PARM_DESC(channel_mtu, "Default MTU for the RFCOMM channel");
2248
-
2249
-module_param(l2cap_mtu, uint, 0644);
2250
-MODULE_PARM_DESC(l2cap_mtu, "Default MTU for the L2CAP connection");
22512273
22522274 module_param(l2cap_ertm, bool, 0644);
22532275 MODULE_PARM_DESC(l2cap_ertm, "Use L2CAP ERTM mode for connection");