Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Bluetooth HCI UART driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2000-2001  Qualcomm Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "hci_uart.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct h4_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct sk_buff *rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct sk_buff_head txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* Initialize protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int h4_open(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct h4_struct *h4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	BT_DBG("hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	h4 = kzalloc(sizeof(*h4), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!h4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	skb_queue_head_init(&h4->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	hu->priv = h4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /* Flush protocol data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int h4_flush(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct h4_struct *h4 = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	BT_DBG("hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	skb_queue_purge(&h4->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* Close protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int h4_close(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct h4_struct *h4 = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	BT_DBG("hu %p", hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	skb_queue_purge(&h4->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	kfree_skb(h4->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	hu->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	kfree(h4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /* Enqueue frame for transmission (padding, crc, etc) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct h4_struct *h4 = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	BT_DBG("hu %p skb %p", hu, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Prepend skb with frame type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	skb_queue_tail(&h4->txq, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static const struct h4_recv_pkt h4_recv_pkts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	{ H4_RECV_ACL,   .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	{ H4_RECV_SCO,   .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	{ H4_RECV_EVENT, .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{ H4_RECV_ISO,   .recv = hci_recv_frame },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Recv data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int h4_recv(struct hci_uart *hu, const void *data, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct h4_struct *h4 = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	h4->rx_skb = h4_recv_buf(hu->hdev, h4->rx_skb, data, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				 h4_recv_pkts, ARRAY_SIZE(h4_recv_pkts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (IS_ERR(h4->rx_skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		int err = PTR_ERR(h4->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		h4->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static struct sk_buff *h4_dequeue(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct h4_struct *h4 = hu->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return skb_dequeue(&h4->txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static const struct hci_uart_proto h4p = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.id		= HCI_UART_H4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.name		= "H4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	.open		= h4_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	.close		= h4_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	.recv		= h4_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	.enqueue	= h4_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.dequeue	= h4_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	.flush		= h4_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int __init h4_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return hci_uart_register_proto(&h4p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int __exit h4_deinit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return hci_uart_unregister_proto(&h4p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			    const unsigned char *buffer, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			    const struct h4_recv_pkt *pkts, int pkts_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct hci_uart *hu = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	u8 alignment = hu->alignment ? hu->alignment : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* Check for error from previous call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (IS_ERR(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		int i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		/* remove padding bytes from buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		for (; hu->padding && count > 0; hu->padding--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			buffer++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			for (i = 0; i < pkts_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				if (buffer[0] != (&pkts[i])->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				skb = bt_skb_alloc((&pkts[i])->maxlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 						   GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 					return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				hci_skb_pkt_type(skb) = (&pkts[i])->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				hci_skb_expect(skb) = (&pkts[i])->hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			/* Check for invalid packet type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 				return ERR_PTR(-EILSEQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			count -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			buffer += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		len = min_t(uint, hci_skb_expect(skb) - skb->len, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		skb_put_data(skb, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		buffer += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		/* Check for partial packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (skb->len < hci_skb_expect(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		for (i = 0; i < pkts_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			if (hci_skb_pkt_type(skb) == (&pkts[i])->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (i >= pkts_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return ERR_PTR(-EILSEQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (skb->len == (&pkts[i])->hlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			u16 dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			switch ((&pkts[i])->lsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				/* No variable data length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				dlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				/* Single octet variable length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				dlen = skb->data[(&pkts[i])->loff];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				hci_skb_expect(skb) += dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				if (skb_tailroom(skb) < dlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 					kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 					return ERR_PTR(-EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				/* Double octet variable length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				dlen = get_unaligned_le16(skb->data +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 							  (&pkts[i])->loff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				hci_skb_expect(skb) += dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				if (skb_tailroom(skb) < dlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 					kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 					return ERR_PTR(-EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				/* Unsupported variable length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				return ERR_PTR(-EILSEQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			if (!dlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				hu->padding = (skb->len - 1) % alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				hu->padding = (alignment - hu->padding) % alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				/* No more data, complete frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				(&pkts[i])->recv(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			hu->padding = (skb->len - 1) % alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			hu->padding = (alignment - hu->padding) % alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			/* Complete frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			(&pkts[i])->recv(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) EXPORT_SYMBOL_GPL(h4_recv_buf);