Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit babf4d42 authored by Marcel Holtmann's avatar Marcel Holtmann
Browse files

[Bluetooth] Use hci_recv_fragment() within HCI USB driver



This patch modifies the HCI USB driver to use the new helper function
for reassembling HCI data packets and events.

Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent ef222013
Loading
Loading
Loading
Loading
+2 −86
Original line number Diff line number Diff line
@@ -199,7 +199,6 @@ static void hci_usb_tx_complete(struct urb *urb);
#define __pending_q(husb, type)   (&husb->pending_q[type-1])
#define __completed_q(husb, type) (&husb->completed_q[type-1])
#define __transmit_q(husb, type)  (&husb->transmit_q[type-1])
#define __reassembly(husb, type)  (husb->reassembly[type-1])

static inline struct _urb *__get_completed(struct hci_usb *husb, int type)
{
@@ -429,12 +428,6 @@ static void hci_usb_unlink_urbs(struct hci_usb *husb)
			kfree(urb->transfer_buffer);
			_urb_free(_urb);
		}

		/* Release reassembly buffers */
		if (husb->reassembly[i]) {
			kfree_skb(husb->reassembly[i]);
			husb->reassembly[i] = NULL;
		}
	}
}

@@ -671,83 +664,6 @@ static int hci_usb_send_frame(struct sk_buff *skb)
	return 0;
}

static inline int __recv_frame(struct hci_usb *husb, int type, void *data, int count)
{
	BT_DBG("%s type %d data %p count %d", husb->hdev->name, type, data, count);

	husb->hdev->stat.byte_rx += count;

	while (count) {
		struct sk_buff *skb = __reassembly(husb, type);
		struct { int expect; } *scb;
		int len = 0;
	
		if (!skb) {
			/* Start of the frame */

			switch (type) {
			case HCI_EVENT_PKT:
				if (count >= HCI_EVENT_HDR_SIZE) {
					struct hci_event_hdr *h = data;
					len = HCI_EVENT_HDR_SIZE + h->plen;
				} else
					return -EILSEQ;
				break;

			case HCI_ACLDATA_PKT:
				if (count >= HCI_ACL_HDR_SIZE) {
					struct hci_acl_hdr *h = data;
					len = HCI_ACL_HDR_SIZE + __le16_to_cpu(h->dlen);
				} else
					return -EILSEQ;
				break;
#ifdef CONFIG_BT_HCIUSB_SCO
			case HCI_SCODATA_PKT:
				if (count >= HCI_SCO_HDR_SIZE) {
					struct hci_sco_hdr *h = data;
					len = HCI_SCO_HDR_SIZE + h->dlen;
				} else
					return -EILSEQ;
				break;
#endif
			}
			BT_DBG("new packet len %d", len);

			skb = bt_skb_alloc(len, GFP_ATOMIC);
			if (!skb) {
				BT_ERR("%s no memory for the packet", husb->hdev->name);
				return -ENOMEM;
			}
			skb->dev = (void *) husb->hdev;
			bt_cb(skb)->pkt_type = type;
	
			__reassembly(husb, type) = skb;

			scb = (void *) skb->cb;
			scb->expect = len;
		} else {
			/* Continuation */
			scb = (void *) skb->cb;
			len = scb->expect;
		}

		len = min(len, count);
		
		memcpy(skb_put(skb, len), data, len);

		scb->expect -= len;
		if (!scb->expect) {
			/* Complete frame */
			__reassembly(husb, type) = NULL;
			bt_cb(skb)->pkt_type = type;
			hci_recv_frame(skb);
		}

		count -= len; data += len;
	}
	return 0;
}

static void hci_usb_rx_complete(struct urb *urb)
{
	struct _urb *_urb = container_of(urb, struct _urb, urb);
@@ -776,7 +692,7 @@ static void hci_usb_rx_complete(struct urb *urb)
					urb->iso_frame_desc[i].actual_length);
	
			if (!urb->iso_frame_desc[i].status)
				__recv_frame(husb, _urb->type, 
				hci_recv_fragment(husb->hdev, _urb->type, 
					urb->transfer_buffer + urb->iso_frame_desc[i].offset,
					urb->iso_frame_desc[i].actual_length);
		}
@@ -784,7 +700,7 @@ static void hci_usb_rx_complete(struct urb *urb)
		;
#endif
	} else {
		err = __recv_frame(husb, _urb->type, urb->transfer_buffer, count);
		err = hci_recv_fragment(husb->hdev, _urb->type, urb->transfer_buffer, count);
		if (err < 0) { 
			BT_ERR("%s corrupted packet: type %d count %d",
					husb->hdev->name, _urb->type, count);
+2 −3
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ struct hci_usb {
	__u8			ctrl_req;

	struct sk_buff_head	transmit_q[4];
	struct sk_buff		*reassembly[4];		/* Reassembly buffers */

	rwlock_t		completion_lock;