3 * Bluetooth HCI Three-wire UART driver
5 * Copyright (C) 2012 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/skbuff.h>
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
34 struct sk_buff_head unack
; /* Unack'ed packets queue */
35 struct sk_buff_head rel
; /* Reliable packets queue */
36 struct sk_buff_head unrel
; /* Unreliable packets queue */
38 struct sk_buff
*rx_skb
;
45 static int h5_open(struct hci_uart
*hu
)
51 h5
= kzalloc(sizeof(*h5
), GFP_KERNEL
);
57 skb_queue_head_init(&h5
->unack
);
58 skb_queue_head_init(&h5
->rel
);
59 skb_queue_head_init(&h5
->unrel
);
64 static int h5_close(struct hci_uart
*hu
)
66 struct h5
*h5
= hu
->priv
;
68 skb_queue_purge(&h5
->unack
);
69 skb_queue_purge(&h5
->rel
);
70 skb_queue_purge(&h5
->unrel
);
77 static int h5_recv(struct hci_uart
*hu
, void *data
, int count
)
82 static int h5_enqueue(struct hci_uart
*hu
, struct sk_buff
*skb
)
84 struct h5
*h5
= hu
->priv
;
86 if (skb
->len
> 0xfff) {
87 BT_ERR("Packet too long (%u bytes)", skb
->len
);
92 switch (bt_cb(skb
)->pkt_type
) {
95 skb_queue_tail(&h5
->rel
, skb
);
99 skb_queue_tail(&h5
->unrel
, skb
);
103 BT_ERR("Unknown packet type %u", bt_cb(skb
)->pkt_type
);
111 static struct sk_buff
*h5_prepare_pkt(struct h5
*h5
, struct sk_buff
*skb
)
113 h5
->txack_req
= false;
117 static struct sk_buff
*h5_prepare_ack(struct h5
*h5
)
119 h5
->txack_req
= false;
123 static struct sk_buff
*h5_dequeue(struct hci_uart
*hu
)
125 struct h5
*h5
= hu
->priv
;
126 struct sk_buff
*skb
, *nskb
;
128 if ((skb
= skb_dequeue(&h5
->unrel
)) != NULL
) {
129 nskb
= h5_prepare_pkt(h5
, skb
);
135 skb_queue_head(&h5
->unrel
, skb
);
136 BT_ERR("Could not dequeue pkt because alloc_skb failed");
140 return h5_prepare_ack(h5
);
145 static int h5_flush(struct hci_uart
*hu
)
151 static struct hci_uart_proto h5p
= {
152 .id
= HCI_UART_3WIRE
,
156 .enqueue
= h5_enqueue
,
157 .dequeue
= h5_dequeue
,
161 int __init
h5_init(void)
163 int err
= hci_uart_register_proto(&h5p
);
166 BT_INFO("HCI Three-wire UART (H5) protocol initialized");
168 BT_ERR("HCI Three-wire UART (H5) protocol init failed");
173 int __exit
h5_deinit(void)
175 return hci_uart_unregister_proto(&h5p
);
This page took 0.044069 seconds and 6 git commands to generate.