hci_uart.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. *
  3. * Bluetooth HCI UART driver
  4. *
  5. * Copyright (C) 2000-2001 Qualcomm Incorporated
  6. * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
  7. * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/version.h>
  26. #include <net/bluetooth/bluetooth.h>
  27. #include <net/bluetooth/hci_core.h>
  28. /* #define HCI_VERSION_CODE KERNEL_VERSION(3, 14, 41) */
  29. #define HCI_VERSION_CODE LINUX_VERSION_CODE
  30. #ifndef N_HCI
  31. #define N_HCI 15
  32. #endif
  33. #ifndef CONFIG_BT_HCIUART_H4
  34. #define CONFIG_BT_HCIUART_H4
  35. #endif
  36. #define BTCOEX
  37. /* Send host sleep notification to Controller */
  38. #define WOBT_NOTIFY 0 /* 1 enable; 0 disable */
  39. /* Send LE whitelist only for Background scan parameters */
  40. #define WOBT_NOTIFY_BG_SCAN_LE_WHITELIST_ONLY (0 * WOBT_NOTIFY) /* 1 enable; 0 disable */
  41. /* RTKBT Power-on Whitelist for sideband wake-up by LE Advertising from Remote.
  42. * Note that it's necessary to apply TV FW Patch. */
  43. #define RTKBT_TV_POWERON_WHITELIST (0 * WOBT_NOTIFY) /* 1 enable; 0 disable */
  44. /* Ioctls */
  45. #define HCIUARTSETPROTO _IOW('U', 200, int)
  46. #define HCIUARTGETPROTO _IOR('U', 201, int)
  47. #define HCIUARTGETDEVICE _IOR('U', 202, int)
  48. #define HCIUARTSETFLAGS _IOW('U', 203, int)
  49. #define HCIUARTGETFLAGS _IOR('U', 204, int)
  50. /* UART protocols */
  51. #define HCI_UART_MAX_PROTO 6
  52. #define HCI_UART_H4 0
  53. #define HCI_UART_BCSP 1
  54. #define HCI_UART_3WIRE 2
  55. #define HCI_UART_H4DS 3
  56. #define HCI_UART_LL 4
  57. #define HCI_UART_ATH3K 5
  58. #define HCI_UART_RAW_DEVICE 0
  59. #define HCI_UART_RESET_ON_INIT 1
  60. #define HCI_UART_CREATE_AMP 2
  61. #define HCI_UART_INIT_PENDING 3
  62. #define HCI_UART_EXT_CONFIG 4
  63. #define HCI_UART_VND_DETECT 5
  64. struct hci_uart;
  65. struct hci_uart_proto {
  66. unsigned int id;
  67. int (*open)(struct hci_uart *hu);
  68. int (*close)(struct hci_uart *hu);
  69. int (*flush)(struct hci_uart *hu);
  70. int (*recv)(struct hci_uart *hu, void *data, int len);
  71. int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb);
  72. struct sk_buff *(*dequeue)(struct hci_uart *hu);
  73. };
  74. struct hci_uart {
  75. struct tty_struct *tty;
  76. struct hci_dev *hdev;
  77. unsigned long flags;
  78. unsigned long hdev_flags;
  79. struct work_struct write_work;
  80. struct workqueue_struct *hci_uart_wq;
  81. struct hci_uart_proto *proto;
  82. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
  83. struct percpu_rw_semaphore proto_lock; /* Stop work for proto close */
  84. #else
  85. struct rw_semaphore proto_lock;
  86. #endif
  87. void *priv;
  88. struct semaphore tx_sem; /* semaphore for tx */
  89. struct sk_buff *tx_skb;
  90. unsigned long tx_state;
  91. #if WOBT_NOTIFY
  92. struct notifier_block pm_notify_block;
  93. #endif
  94. };
  95. /* HCI_UART proto flag bits */
  96. #define HCI_UART_PROTO_SET 0
  97. #define HCI_UART_REGISTERED 1
  98. #define HCI_UART_PROTO_READY 2
  99. /* TX states */
  100. #define HCI_UART_SENDING 1
  101. #define HCI_UART_TX_WAKEUP 2
  102. extern int hci_uart_register_proto(struct hci_uart_proto *p);
  103. extern int hci_uart_unregister_proto(struct hci_uart_proto *p);
  104. extern int hci_uart_tx_wakeup(struct hci_uart *hu);
  105. #ifdef CONFIG_BT_HCIUART_H4
  106. extern int h4_init(void);
  107. extern int h4_deinit(void);
  108. #endif
  109. extern int h5_init(void);
  110. extern int h5_deinit(void);
  111. #if HCI_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
  112. extern int hci_uart_send_frame(struct sk_buff *skb);
  113. #else
  114. extern int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb);
  115. #endif