Release 4.12 drivers/bluetooth/hci_h4.c
  
  
  
/*
 *
 *  Bluetooth HCI UART driver
 *
 *  Copyright (C) 2000-2001  Qualcomm Incorporated
 *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
 *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/signal.h>
#include <linux/ioctl.h>
#include <linux/skbuff.h>
#include <asm/unaligned.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
#include "hci_uart.h"
struct h4_struct {
	
struct sk_buff *rx_skb;
	
struct sk_buff_head txq;
};
/* Initialize protocol */
static int h4_open(struct hci_uart *hu)
{
	struct h4_struct *h4;
	BT_DBG("hu %p", hu);
	h4 = kzalloc(sizeof(*h4), GFP_KERNEL);
	if (!h4)
		return -ENOMEM;
	skb_queue_head_init(&h4->txq);
	hu->priv = h4;
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 60 | 96.77% | 2 | 50.00% | 
| David Herrmann | 1 | 1.61% | 1 | 25.00% | 
| Deepak Saxena | 1 | 1.61% | 1 | 25.00% | 
| Total | 62 | 100.00% | 4 | 100.00% | 
/* Flush protocol data */
static int h4_flush(struct hci_uart *hu)
{
	struct h4_struct *h4 = hu->priv;
	BT_DBG("hu %p", hu);
	skb_queue_purge(&h4->txq);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 38 | 100.00% | 2 | 100.00% | 
| Total | 38 | 100.00% | 2 | 100.00% | 
/* Close protocol */
static int h4_close(struct hci_uart *hu)
{
	struct h4_struct *h4 = hu->priv;
	hu->priv = NULL;
	BT_DBG("hu %p", hu);
	skb_queue_purge(&h4->txq);
	kfree_skb(h4->rx_skb);
	hu->priv = NULL;
	kfree(h4);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 55 | 88.71% | 2 | 66.67% | 
| Marcel Holtmann | 7 | 11.29% | 1 | 33.33% | 
| Total | 62 | 100.00% | 3 | 100.00% | 
/* Enqueue frame for transmittion (padding, crc, etc) */
static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
{
	struct h4_struct *h4 = hu->priv;
	BT_DBG("hu %p skb %p", hu, skb);
	/* Prepend skb with frame type */
	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
	skb_queue_tail(&h4->txq, skb);
	return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 63 | 95.45% | 2 | 50.00% | 
| Marcel Holtmann | 3 | 4.55% | 2 | 50.00% | 
| Total | 66 | 100.00% | 4 | 100.00% | 
static const struct h4_recv_pkt h4_recv_pkts[] = {
	{ H4_RECV_ACL,   .recv = hci_recv_frame },
	{ H4_RECV_SCO,   .recv = hci_recv_frame },
	{ H4_RECV_EVENT, .recv = hci_recv_frame },
};
/* Recv data */
static int h4_recv(struct hci_uart *hu, const void *data, int count)
{
	struct h4_struct *h4 = hu->priv;
	if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
		return -EUNATCH;
	h4->rx_skb = h4_recv_buf(hu->hdev, h4->rx_skb, data, count,
				 h4_recv_pkts, ARRAY_SIZE(h4_recv_pkts));
	if (IS_ERR(h4->rx_skb)) {
		int err = PTR_ERR(h4->rx_skb);
		BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err);
		h4->rx_skb = NULL;
		return err;
	}
	return count;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Marcel Holtmann | 50 | 42.74% | 3 | 33.33% | 
| Maksim Krasnyanskiy | 32 | 27.35% | 2 | 22.22% | 
| Chan-yeol Park | 23 | 19.66% | 2 | 22.22% | 
| Gustavo Fernando Padovan | 12 | 10.26% | 2 | 22.22% | 
| Total | 117 | 100.00% | 9 | 100.00% | 
static struct sk_buff *h4_dequeue(struct hci_uart *hu)
{
	struct h4_struct *h4 = hu->priv;
	return skb_dequeue(&h4->txq);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 31 | 100.00% | 1 | 100.00% | 
| Total | 31 | 100.00% | 1 | 100.00% | 
static const struct hci_uart_proto h4p = {
	.id		= HCI_UART_H4,
	.name		= "H4",
	.open		= h4_open,
	.close		= h4_close,
	.recv		= h4_recv,
	.enqueue	= h4_enqueue,
	.dequeue	= h4_dequeue,
	.flush		= h4_flush,
};
int __init h4_init(void)
{
	return hci_uart_register_proto(&h4p);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 13 | 86.67% | 1 | 33.33% | 
| Marcel Holtmann | 1 | 6.67% | 1 | 33.33% | 
| Gustavo Fernando Padovan | 1 | 6.67% | 1 | 33.33% | 
| Total | 15 | 100.00% | 3 | 100.00% | 
int __exit h4_deinit(void)
{
	return hci_uart_unregister_proto(&h4p);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Maksim Krasnyanskiy | 14 | 93.33% | 1 | 50.00% | 
| Gustavo Fernando Padovan | 1 | 6.67% | 1 | 50.00% | 
| Total | 15 | 100.00% | 2 | 100.00% | 
struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
			    const unsigned char *buffer, int count,
			    const struct h4_recv_pkt *pkts, int pkts_count)
{
	struct hci_uart *hu = hci_get_drvdata(hdev);
	u8 alignment = hu->alignment;
	while (count) {
		int i, len;
		/* remove padding bytes from buffer */
		for (; hu->padding && count > 0; hu->padding--) {
			count--;
			buffer++;
		}
		if (!count)
			break;
		if (!skb) {
			for (i = 0; i < pkts_count; i++) {
				if (buffer[0] != (&pkts[i])->type)
					continue;
				skb = bt_skb_alloc((&pkts[i])->maxlen,
						   GFP_ATOMIC);
				if (!skb)
					return ERR_PTR(-ENOMEM);
				hci_skb_pkt_type(skb) = (&pkts[i])->type;
				hci_skb_expect(skb) = (&pkts[i])->hlen;
				break;
			}
			/* Check for invalid packet type */
			if (!skb)
				return ERR_PTR(-EILSEQ);
			count -= 1;
			buffer += 1;
		}
		len = min_t(uint, hci_skb_expect(skb) - skb->len, count);
		memcpy(skb_put(skb, len), buffer, len);
		count -= len;
		buffer += len;
		/* Check for partial packet */
		if (skb->len < hci_skb_expect(skb))
			continue;
		for (i = 0; i < pkts_count; i++) {
			if (hci_skb_pkt_type(skb) == (&pkts[i])->type)
				break;
		}
		if (i >= pkts_count) {
			kfree_skb(skb);
			return ERR_PTR(-EILSEQ);
		}
		if (skb->len == (&pkts[i])->hlen) {
			u16 dlen;
			switch ((&pkts[i])->lsize) {
			case 0:
				/* No variable data length */
				dlen = 0;
				break;
			case 1:
				/* Single octet variable length */
				dlen = skb->data[(&pkts[i])->loff];
				hci_skb_expect(skb) += dlen;
				if (skb_tailroom(skb) < dlen) {
					kfree_skb(skb);
					return ERR_PTR(-EMSGSIZE);
				}
				break;
			case 2:
				/* Double octet variable length */
				dlen = get_unaligned_le16(skb->data +
							  (&pkts[i])->loff);
				hci_skb_expect(skb) += dlen;
				if (skb_tailroom(skb) < dlen) {
					kfree_skb(skb);
					return ERR_PTR(-EMSGSIZE);
				}
				break;
			default:
				/* Unsupported variable length */
				kfree_skb(skb);
				return ERR_PTR(-EILSEQ);
			}
			if (!dlen) {
				hu->padding = (skb->len - 1) % alignment;
				hu->padding = (alignment - hu->padding) % alignment;
				/* No more data, complete frame */
				(&pkts[i])->recv(hdev, skb);
				skb = NULL;
			}
		} else {
			hu->padding = (skb->len - 1) % alignment;
			hu->padding = (alignment - hu->padding) % alignment;
			/* Complete frame */
			(&pkts[i])->recv(hdev, skb);
			skb = NULL;
		}
	}
	return skb;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Marcel Holtmann | 461 | 77.61% | 3 | 60.00% | 
| Sebastian Reichel | 104 | 17.51% | 1 | 20.00% | 
| Loic Poulain | 29 | 4.88% | 1 | 20.00% | 
| Total | 594 | 100.00% | 5 | 100.00% | 
EXPORT_SYMBOL_GPL(h4_recv_buf);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp | 
| Marcel Holtmann | 587 | 50.34% | 11 | 47.83% | 
| Maksim Krasnyanskiy | 393 | 33.70% | 2 | 8.70% | 
| Sebastian Reichel | 104 | 8.92% | 1 | 4.35% | 
| Loic Poulain | 29 | 2.49% | 1 | 4.35% | 
| Chan-yeol Park | 23 | 1.97% | 2 | 8.70% | 
| Gustavo Fernando Padovan | 14 | 1.20% | 3 | 13.04% | 
| Rusty Russell | 14 | 1.20% | 1 | 4.35% | 
| Deepak Saxena | 1 | 0.09% | 1 | 4.35% | 
| David Herrmann | 1 | 0.09% | 1 | 4.35% | 
| Total | 1166 | 100.00% | 23 | 100.00% | 
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.