26 #include <linux/module.h>
28 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/fcntl.h>
33 #include <linux/ptrace.h>
34 #include <linux/poll.h>
36 #include <linux/slab.h>
37 #include <linux/tty.h>
38 #include <linux/errno.h>
39 #include <linux/string.h>
40 #include <linux/signal.h>
87 static inline void hci_uart_tx_complete(
struct hci_uart *hu,
int pkt_type)
112 skb = hu->
proto->dequeue(hu);
135 while ((skb = hci_uart_dequeue(hu))) {
139 len = tty->
ops->write(tty, skb->
data, skb->
len);
148 hci_uart_tx_complete(hu,
bt_cb(skb)->pkt_type);
169 BT_ERR(
"Can't register HCI device");
172 hu->
proto->close(hu);
190 static int hci_uart_open(
struct hci_dev *hdev)
202 static int hci_uart_flush(
struct hci_dev *hdev)
204 struct hci_uart *hu = hci_get_drvdata(hdev);
207 BT_DBG(
"hdev %p tty %p", hdev, tty);
218 hu->
proto->flush(hu);
224 static int hci_uart_close(
struct hci_dev *hdev)
231 hci_uart_flush(hdev);
237 static int hci_uart_send_frame(
struct sk_buff *skb)
243 BT_ERR(
"Frame for unknown device (hdev=NULL)");
250 hu = hci_get_drvdata(hdev);
254 hu->
proto->enqueue(hu, skb);
271 static int hci_uart_tty_open(
struct tty_struct *tty)
288 BT_ERR(
"Can't allocate control structure");
305 if (tty->
ldisc->ops->flush_buffer)
306 tty->
ldisc->ops->flush_buffer(tty);
317 static void hci_uart_tty_close(
struct tty_struct *tty)
332 hci_uart_close(hdev);
340 hu->
proto->close(hu);
354 static void hci_uart_tty_wakeup(
struct tty_struct *tty)
388 if (!hu || tty != hu->
tty)
395 hu->
proto->recv(hu, (
void *) data, count);
402 static int hci_uart_register_dev(
struct hci_uart *hu)
411 BT_ERR(
"Can't allocate HCI device");
418 hci_set_drvdata(hdev, hu);
420 hdev->
open = hci_uart_open;
421 hdev->
close = hci_uart_close;
422 hdev->
flush = hci_uart_flush;
423 hdev->
send = hci_uart_send_frame;
441 BT_ERR(
"Can't register HCI device");
451 static int hci_uart_set_proto(
struct hci_uart *hu,
int id)
456 p = hci_uart_get_proto(
id);
466 err = hci_uart_register_dev(hu);
489 unsigned int cmd,
unsigned long arg)
503 err = hci_uart_set_proto(hu, arg);
514 return hu->
proto->id;
543 unsigned char __user *
buf,
size_t nr)
549 const unsigned char *data,
size_t count)
554 static unsigned int hci_uart_tty_poll(
struct tty_struct *tty,
560 static int __init hci_uart_init(
void)
569 memset(&hci_uart_ldisc, 0,
sizeof (hci_uart_ldisc));
571 hci_uart_ldisc.name =
"n_hci";
572 hci_uart_ldisc.open = hci_uart_tty_open;
573 hci_uart_ldisc.close = hci_uart_tty_close;
574 hci_uart_ldisc.read = hci_uart_tty_read;
575 hci_uart_ldisc.write = hci_uart_tty_write;
576 hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
577 hci_uart_ldisc.poll = hci_uart_tty_poll;
578 hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
579 hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
583 BT_ERR(
"HCI line discipline registration failed. (%d)", err);
587 #ifdef CONFIG_BT_HCIUART_H4
590 #ifdef CONFIG_BT_HCIUART_BCSP
593 #ifdef CONFIG_BT_HCIUART_LL
596 #ifdef CONFIG_BT_HCIUART_ATH3K
599 #ifdef CONFIG_BT_HCIUART_3WIRE
606 static void __exit hci_uart_exit(
void)
610 #ifdef CONFIG_BT_HCIUART_H4
613 #ifdef CONFIG_BT_HCIUART_BCSP
616 #ifdef CONFIG_BT_HCIUART_LL
619 #ifdef CONFIG_BT_HCIUART_ATH3K
622 #ifdef CONFIG_BT_HCIUART_3WIRE
628 BT_ERR(
"Can't unregister HCI line discipline (%d)", err);