Commit 78b4a56c28c096a1eb02f1d864eb450eb910e43d

Authored by Jiejing Zhang
Committed by Gustavo F. Padovan
1 parent e1ba1f1546

Bluetooth: hci_uart: check the return value of recv()

Check the return value of hu->proto->recv() in hci_uart_tty_receive()
the recv() may return error, check it, not add this to statistics.

Signed-off-by: Jiejing Zhang <jiejing.zhang@freescale.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>

Showing 2 changed files with 10 additions and 3 deletions Inline Diff

drivers/bluetooth/hci_ath.c
1 /* 1 /*
2 * Atheros Communication Bluetooth HCIATH3K UART protocol 2 * Atheros Communication Bluetooth HCIATH3K UART protocol
3 * 3 *
4 * HCIATH3K (HCI Atheros AR300x Protocol) is a Atheros Communication's 4 * HCIATH3K (HCI Atheros AR300x Protocol) is a Atheros Communication's
5 * power management protocol extension to H4 to support AR300x Bluetooth Chip. 5 * power management protocol extension to H4 to support AR300x Bluetooth Chip.
6 * 6 *
7 * Copyright (c) 2009-2010 Atheros Communications Inc. 7 * Copyright (c) 2009-2010 Atheros Communications Inc.
8 * 8 *
9 * Acknowledgements: 9 * Acknowledgements:
10 * This file is based on hci_h4.c, which was written 10 * This file is based on hci_h4.c, which was written
11 * by Maxim Krasnyansky and Marcel Holtmann. 11 * by Maxim Krasnyansky and Marcel Holtmann.
12 * 12 *
13 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version. 16 * (at your option) any later version.
17 * 17 *
18 * This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details. 21 * GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 26 *
27 */ 27 */
28 28
29 #include <linux/module.h> 29 #include <linux/module.h>
30 #include <linux/kernel.h> 30 #include <linux/kernel.h>
31 31
32 #include <linux/init.h> 32 #include <linux/init.h>
33 #include <linux/slab.h> 33 #include <linux/slab.h>
34 #include <linux/tty.h> 34 #include <linux/tty.h>
35 #include <linux/errno.h> 35 #include <linux/errno.h>
36 #include <linux/ioctl.h> 36 #include <linux/ioctl.h>
37 #include <linux/skbuff.h> 37 #include <linux/skbuff.h>
38 38
39 #include <net/bluetooth/bluetooth.h> 39 #include <net/bluetooth/bluetooth.h>
40 #include <net/bluetooth/hci_core.h> 40 #include <net/bluetooth/hci_core.h>
41 41
42 #include "hci_uart.h" 42 #include "hci_uart.h"
43 43
44 struct ath_struct { 44 struct ath_struct {
45 struct hci_uart *hu; 45 struct hci_uart *hu;
46 unsigned int cur_sleep; 46 unsigned int cur_sleep;
47 47
48 struct sk_buff_head txq; 48 struct sk_buff_head txq;
49 struct work_struct ctxtsw; 49 struct work_struct ctxtsw;
50 }; 50 };
51 51
52 static int ath_wakeup_ar3k(struct tty_struct *tty) 52 static int ath_wakeup_ar3k(struct tty_struct *tty)
53 { 53 {
54 struct ktermios ktermios; 54 struct ktermios ktermios;
55 int status = tty->driver->ops->tiocmget(tty); 55 int status = tty->driver->ops->tiocmget(tty);
56 56
57 if (status & TIOCM_CTS) 57 if (status & TIOCM_CTS)
58 return status; 58 return status;
59 59
60 /* Disable Automatic RTSCTS */ 60 /* Disable Automatic RTSCTS */
61 memcpy(&ktermios, tty->termios, sizeof(ktermios)); 61 memcpy(&ktermios, tty->termios, sizeof(ktermios));
62 ktermios.c_cflag &= ~CRTSCTS; 62 ktermios.c_cflag &= ~CRTSCTS;
63 tty_set_termios(tty, &ktermios); 63 tty_set_termios(tty, &ktermios);
64 64
65 /* Clear RTS first */ 65 /* Clear RTS first */
66 status = tty->driver->ops->tiocmget(tty); 66 status = tty->driver->ops->tiocmget(tty);
67 tty->driver->ops->tiocmset(tty, 0x00, TIOCM_RTS); 67 tty->driver->ops->tiocmset(tty, 0x00, TIOCM_RTS);
68 mdelay(20); 68 mdelay(20);
69 69
70 /* Set RTS, wake up board */ 70 /* Set RTS, wake up board */
71 status = tty->driver->ops->tiocmget(tty); 71 status = tty->driver->ops->tiocmget(tty);
72 tty->driver->ops->tiocmset(tty, TIOCM_RTS, 0x00); 72 tty->driver->ops->tiocmset(tty, TIOCM_RTS, 0x00);
73 mdelay(20); 73 mdelay(20);
74 74
75 status = tty->driver->ops->tiocmget(tty); 75 status = tty->driver->ops->tiocmget(tty);
76 76
77 /* Disable Automatic RTSCTS */ 77 /* Disable Automatic RTSCTS */
78 ktermios.c_cflag |= CRTSCTS; 78 ktermios.c_cflag |= CRTSCTS;
79 status = tty_set_termios(tty, &ktermios); 79 status = tty_set_termios(tty, &ktermios);
80 80
81 return status; 81 return status;
82 } 82 }
83 83
84 static void ath_hci_uart_work(struct work_struct *work) 84 static void ath_hci_uart_work(struct work_struct *work)
85 { 85 {
86 int status; 86 int status;
87 struct ath_struct *ath; 87 struct ath_struct *ath;
88 struct hci_uart *hu; 88 struct hci_uart *hu;
89 struct tty_struct *tty; 89 struct tty_struct *tty;
90 90
91 ath = container_of(work, struct ath_struct, ctxtsw); 91 ath = container_of(work, struct ath_struct, ctxtsw);
92 92
93 hu = ath->hu; 93 hu = ath->hu;
94 tty = hu->tty; 94 tty = hu->tty;
95 95
96 /* verify and wake up controller */ 96 /* verify and wake up controller */
97 if (ath->cur_sleep) { 97 if (ath->cur_sleep) {
98 status = ath_wakeup_ar3k(tty); 98 status = ath_wakeup_ar3k(tty);
99 if (!(status & TIOCM_CTS)) 99 if (!(status & TIOCM_CTS))
100 return; 100 return;
101 } 101 }
102 102
103 /* Ready to send Data */ 103 /* Ready to send Data */
104 clear_bit(HCI_UART_SENDING, &hu->tx_state); 104 clear_bit(HCI_UART_SENDING, &hu->tx_state);
105 hci_uart_tx_wakeup(hu); 105 hci_uart_tx_wakeup(hu);
106 } 106 }
107 107
108 /* Initialize protocol */ 108 /* Initialize protocol */
109 static int ath_open(struct hci_uart *hu) 109 static int ath_open(struct hci_uart *hu)
110 { 110 {
111 struct ath_struct *ath; 111 struct ath_struct *ath;
112 112
113 BT_DBG("hu %p", hu); 113 BT_DBG("hu %p", hu);
114 114
115 ath = kzalloc(sizeof(*ath), GFP_ATOMIC); 115 ath = kzalloc(sizeof(*ath), GFP_ATOMIC);
116 if (!ath) 116 if (!ath)
117 return -ENOMEM; 117 return -ENOMEM;
118 118
119 skb_queue_head_init(&ath->txq); 119 skb_queue_head_init(&ath->txq);
120 120
121 hu->priv = ath; 121 hu->priv = ath;
122 ath->hu = hu; 122 ath->hu = hu;
123 123
124 INIT_WORK(&ath->ctxtsw, ath_hci_uart_work); 124 INIT_WORK(&ath->ctxtsw, ath_hci_uart_work);
125 125
126 return 0; 126 return 0;
127 } 127 }
128 128
129 /* Flush protocol data */ 129 /* Flush protocol data */
130 static int ath_flush(struct hci_uart *hu) 130 static int ath_flush(struct hci_uart *hu)
131 { 131 {
132 struct ath_struct *ath = hu->priv; 132 struct ath_struct *ath = hu->priv;
133 133
134 BT_DBG("hu %p", hu); 134 BT_DBG("hu %p", hu);
135 135
136 skb_queue_purge(&ath->txq); 136 skb_queue_purge(&ath->txq);
137 137
138 return 0; 138 return 0;
139 } 139 }
140 140
141 /* Close protocol */ 141 /* Close protocol */
142 static int ath_close(struct hci_uart *hu) 142 static int ath_close(struct hci_uart *hu)
143 { 143 {
144 struct ath_struct *ath = hu->priv; 144 struct ath_struct *ath = hu->priv;
145 145
146 BT_DBG("hu %p", hu); 146 BT_DBG("hu %p", hu);
147 147
148 skb_queue_purge(&ath->txq); 148 skb_queue_purge(&ath->txq);
149 149
150 cancel_work_sync(&ath->ctxtsw); 150 cancel_work_sync(&ath->ctxtsw);
151 151
152 hu->priv = NULL; 152 hu->priv = NULL;
153 kfree(ath); 153 kfree(ath);
154 154
155 return 0; 155 return 0;
156 } 156 }
157 157
158 #define HCI_OP_ATH_SLEEP 0xFC04 158 #define HCI_OP_ATH_SLEEP 0xFC04
159 159
160 /* Enqueue frame for transmittion */ 160 /* Enqueue frame for transmittion */
161 static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb) 161 static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb)
162 { 162 {
163 struct ath_struct *ath = hu->priv; 163 struct ath_struct *ath = hu->priv;
164 164
165 if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) { 165 if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) {
166 kfree_skb(skb); 166 kfree_skb(skb);
167 return 0; 167 return 0;
168 } 168 }
169 169
170 /* 170 /*
171 * Update power management enable flag with parameters of 171 * Update power management enable flag with parameters of
172 * HCI sleep enable vendor specific HCI command. 172 * HCI sleep enable vendor specific HCI command.
173 */ 173 */
174 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { 174 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
175 struct hci_command_hdr *hdr = (void *)skb->data; 175 struct hci_command_hdr *hdr = (void *)skb->data;
176 176
177 if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP) 177 if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP)
178 ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE]; 178 ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE];
179 } 179 }
180 180
181 BT_DBG("hu %p skb %p", hu, skb); 181 BT_DBG("hu %p skb %p", hu, skb);
182 182
183 /* Prepend skb with frame type */ 183 /* Prepend skb with frame type */
184 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 184 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
185 185
186 skb_queue_tail(&ath->txq, skb); 186 skb_queue_tail(&ath->txq, skb);
187 set_bit(HCI_UART_SENDING, &hu->tx_state); 187 set_bit(HCI_UART_SENDING, &hu->tx_state);
188 188
189 schedule_work(&ath->ctxtsw); 189 schedule_work(&ath->ctxtsw);
190 190
191 return 0; 191 return 0;
192 } 192 }
193 193
194 static struct sk_buff *ath_dequeue(struct hci_uart *hu) 194 static struct sk_buff *ath_dequeue(struct hci_uart *hu)
195 { 195 {
196 struct ath_struct *ath = hu->priv; 196 struct ath_struct *ath = hu->priv;
197 197
198 return skb_dequeue(&ath->txq); 198 return skb_dequeue(&ath->txq);
199 } 199 }
200 200
201 /* Recv data */ 201 /* Recv data */
202 static int ath_recv(struct hci_uart *hu, void *data, int count) 202 static int ath_recv(struct hci_uart *hu, void *data, int count)
203 { 203 {
204 if (hci_recv_stream_fragment(hu->hdev, data, count) < 0) 204 int ret;
205
206 ret = hci_recv_stream_fragment(hu->hdev, data, count);
207 if (ret < 0) {
205 BT_ERR("Frame Reassembly Failed"); 208 BT_ERR("Frame Reassembly Failed");
209 return ret;
210 }
206 211
207 return count; 212 return count;
208 } 213 }
209 214
210 static struct hci_uart_proto athp = { 215 static struct hci_uart_proto athp = {
211 .id = HCI_UART_ATH3K, 216 .id = HCI_UART_ATH3K,
212 .open = ath_open, 217 .open = ath_open,
213 .close = ath_close, 218 .close = ath_close,
214 .recv = ath_recv, 219 .recv = ath_recv,
215 .enqueue = ath_enqueue, 220 .enqueue = ath_enqueue,
216 .dequeue = ath_dequeue, 221 .dequeue = ath_dequeue,
217 .flush = ath_flush, 222 .flush = ath_flush,
218 }; 223 };
219 224
220 int __init ath_init(void) 225 int __init ath_init(void)
221 { 226 {
222 int err = hci_uart_register_proto(&athp); 227 int err = hci_uart_register_proto(&athp);
223 228
224 if (!err) 229 if (!err)
225 BT_INFO("HCIATH3K protocol initialized"); 230 BT_INFO("HCIATH3K protocol initialized");
226 else 231 else
227 BT_ERR("HCIATH3K protocol registration failed"); 232 BT_ERR("HCIATH3K protocol registration failed");
228 233
229 return err; 234 return err;
230 } 235 }
231 236
232 int __exit ath_deinit(void) 237 int __exit ath_deinit(void)
233 { 238 {
234 return hci_uart_unregister_proto(&athp); 239 return hci_uart_unregister_proto(&athp);
235 } 240 }
236 241
drivers/bluetooth/hci_ldisc.c
1 /* 1 /*
2 * 2 *
3 * Bluetooth HCI UART driver 3 * Bluetooth HCI UART driver
4 * 4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated 5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
8 * 8 *
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 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 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 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 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 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 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 */ 24 */
25 25
26 #include <linux/module.h> 26 #include <linux/module.h>
27 27
28 #include <linux/kernel.h> 28 #include <linux/kernel.h>
29 #include <linux/init.h> 29 #include <linux/init.h>
30 #include <linux/types.h> 30 #include <linux/types.h>
31 #include <linux/fcntl.h> 31 #include <linux/fcntl.h>
32 #include <linux/interrupt.h> 32 #include <linux/interrupt.h>
33 #include <linux/ptrace.h> 33 #include <linux/ptrace.h>
34 #include <linux/poll.h> 34 #include <linux/poll.h>
35 35
36 #include <linux/slab.h> 36 #include <linux/slab.h>
37 #include <linux/tty.h> 37 #include <linux/tty.h>
38 #include <linux/errno.h> 38 #include <linux/errno.h>
39 #include <linux/string.h> 39 #include <linux/string.h>
40 #include <linux/signal.h> 40 #include <linux/signal.h>
41 #include <linux/ioctl.h> 41 #include <linux/ioctl.h>
42 #include <linux/skbuff.h> 42 #include <linux/skbuff.h>
43 43
44 #include <net/bluetooth/bluetooth.h> 44 #include <net/bluetooth/bluetooth.h>
45 #include <net/bluetooth/hci_core.h> 45 #include <net/bluetooth/hci_core.h>
46 46
47 #include "hci_uart.h" 47 #include "hci_uart.h"
48 48
49 #define VERSION "2.2" 49 #define VERSION "2.2"
50 50
51 static int reset = 0; 51 static int reset = 0;
52 52
53 static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; 53 static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO];
54 54
55 int hci_uart_register_proto(struct hci_uart_proto *p) 55 int hci_uart_register_proto(struct hci_uart_proto *p)
56 { 56 {
57 if (p->id >= HCI_UART_MAX_PROTO) 57 if (p->id >= HCI_UART_MAX_PROTO)
58 return -EINVAL; 58 return -EINVAL;
59 59
60 if (hup[p->id]) 60 if (hup[p->id])
61 return -EEXIST; 61 return -EEXIST;
62 62
63 hup[p->id] = p; 63 hup[p->id] = p;
64 64
65 return 0; 65 return 0;
66 } 66 }
67 67
68 int hci_uart_unregister_proto(struct hci_uart_proto *p) 68 int hci_uart_unregister_proto(struct hci_uart_proto *p)
69 { 69 {
70 if (p->id >= HCI_UART_MAX_PROTO) 70 if (p->id >= HCI_UART_MAX_PROTO)
71 return -EINVAL; 71 return -EINVAL;
72 72
73 if (!hup[p->id]) 73 if (!hup[p->id])
74 return -EINVAL; 74 return -EINVAL;
75 75
76 hup[p->id] = NULL; 76 hup[p->id] = NULL;
77 77
78 return 0; 78 return 0;
79 } 79 }
80 80
81 static struct hci_uart_proto *hci_uart_get_proto(unsigned int id) 81 static struct hci_uart_proto *hci_uart_get_proto(unsigned int id)
82 { 82 {
83 if (id >= HCI_UART_MAX_PROTO) 83 if (id >= HCI_UART_MAX_PROTO)
84 return NULL; 84 return NULL;
85 85
86 return hup[id]; 86 return hup[id];
87 } 87 }
88 88
89 static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) 89 static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
90 { 90 {
91 struct hci_dev *hdev = hu->hdev; 91 struct hci_dev *hdev = hu->hdev;
92 92
93 /* Update HCI stat counters */ 93 /* Update HCI stat counters */
94 switch (pkt_type) { 94 switch (pkt_type) {
95 case HCI_COMMAND_PKT: 95 case HCI_COMMAND_PKT:
96 hdev->stat.cmd_tx++; 96 hdev->stat.cmd_tx++;
97 break; 97 break;
98 98
99 case HCI_ACLDATA_PKT: 99 case HCI_ACLDATA_PKT:
100 hdev->stat.acl_tx++; 100 hdev->stat.acl_tx++;
101 break; 101 break;
102 102
103 case HCI_SCODATA_PKT: 103 case HCI_SCODATA_PKT:
104 hdev->stat.sco_tx++; 104 hdev->stat.sco_tx++;
105 break; 105 break;
106 } 106 }
107 } 107 }
108 108
109 static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) 109 static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu)
110 { 110 {
111 struct sk_buff *skb = hu->tx_skb; 111 struct sk_buff *skb = hu->tx_skb;
112 112
113 if (!skb) 113 if (!skb)
114 skb = hu->proto->dequeue(hu); 114 skb = hu->proto->dequeue(hu);
115 else 115 else
116 hu->tx_skb = NULL; 116 hu->tx_skb = NULL;
117 117
118 return skb; 118 return skb;
119 } 119 }
120 120
121 int hci_uart_tx_wakeup(struct hci_uart *hu) 121 int hci_uart_tx_wakeup(struct hci_uart *hu)
122 { 122 {
123 struct tty_struct *tty = hu->tty; 123 struct tty_struct *tty = hu->tty;
124 struct hci_dev *hdev = hu->hdev; 124 struct hci_dev *hdev = hu->hdev;
125 struct sk_buff *skb; 125 struct sk_buff *skb;
126 126
127 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { 127 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) {
128 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); 128 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
129 return 0; 129 return 0;
130 } 130 }
131 131
132 BT_DBG(""); 132 BT_DBG("");
133 133
134 restart: 134 restart:
135 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); 135 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
136 136
137 while ((skb = hci_uart_dequeue(hu))) { 137 while ((skb = hci_uart_dequeue(hu))) {
138 int len; 138 int len;
139 139
140 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 140 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
141 len = tty->ops->write(tty, skb->data, skb->len); 141 len = tty->ops->write(tty, skb->data, skb->len);
142 hdev->stat.byte_tx += len; 142 hdev->stat.byte_tx += len;
143 143
144 skb_pull(skb, len); 144 skb_pull(skb, len);
145 if (skb->len) { 145 if (skb->len) {
146 hu->tx_skb = skb; 146 hu->tx_skb = skb;
147 break; 147 break;
148 } 148 }
149 149
150 hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type); 150 hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type);
151 kfree_skb(skb); 151 kfree_skb(skb);
152 } 152 }
153 153
154 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) 154 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
155 goto restart; 155 goto restart;
156 156
157 clear_bit(HCI_UART_SENDING, &hu->tx_state); 157 clear_bit(HCI_UART_SENDING, &hu->tx_state);
158 return 0; 158 return 0;
159 } 159 }
160 160
161 /* ------- Interface to HCI layer ------ */ 161 /* ------- Interface to HCI layer ------ */
162 /* Initialize device */ 162 /* Initialize device */
163 static int hci_uart_open(struct hci_dev *hdev) 163 static int hci_uart_open(struct hci_dev *hdev)
164 { 164 {
165 BT_DBG("%s %p", hdev->name, hdev); 165 BT_DBG("%s %p", hdev->name, hdev);
166 166
167 /* Nothing to do for UART driver */ 167 /* Nothing to do for UART driver */
168 168
169 set_bit(HCI_RUNNING, &hdev->flags); 169 set_bit(HCI_RUNNING, &hdev->flags);
170 170
171 return 0; 171 return 0;
172 } 172 }
173 173
174 /* Reset device */ 174 /* Reset device */
175 static int hci_uart_flush(struct hci_dev *hdev) 175 static int hci_uart_flush(struct hci_dev *hdev)
176 { 176 {
177 struct hci_uart *hu = (struct hci_uart *) hdev->driver_data; 177 struct hci_uart *hu = (struct hci_uart *) hdev->driver_data;
178 struct tty_struct *tty = hu->tty; 178 struct tty_struct *tty = hu->tty;
179 179
180 BT_DBG("hdev %p tty %p", hdev, tty); 180 BT_DBG("hdev %p tty %p", hdev, tty);
181 181
182 if (hu->tx_skb) { 182 if (hu->tx_skb) {
183 kfree_skb(hu->tx_skb); hu->tx_skb = NULL; 183 kfree_skb(hu->tx_skb); hu->tx_skb = NULL;
184 } 184 }
185 185
186 /* Flush any pending characters in the driver and discipline. */ 186 /* Flush any pending characters in the driver and discipline. */
187 tty_ldisc_flush(tty); 187 tty_ldisc_flush(tty);
188 tty_driver_flush_buffer(tty); 188 tty_driver_flush_buffer(tty);
189 189
190 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 190 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
191 hu->proto->flush(hu); 191 hu->proto->flush(hu);
192 192
193 return 0; 193 return 0;
194 } 194 }
195 195
196 /* Close device */ 196 /* Close device */
197 static int hci_uart_close(struct hci_dev *hdev) 197 static int hci_uart_close(struct hci_dev *hdev)
198 { 198 {
199 BT_DBG("hdev %p", hdev); 199 BT_DBG("hdev %p", hdev);
200 200
201 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 201 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
202 return 0; 202 return 0;
203 203
204 hci_uart_flush(hdev); 204 hci_uart_flush(hdev);
205 hdev->flush = NULL; 205 hdev->flush = NULL;
206 return 0; 206 return 0;
207 } 207 }
208 208
209 /* Send frames from HCI layer */ 209 /* Send frames from HCI layer */
210 static int hci_uart_send_frame(struct sk_buff *skb) 210 static int hci_uart_send_frame(struct sk_buff *skb)
211 { 211 {
212 struct hci_dev* hdev = (struct hci_dev *) skb->dev; 212 struct hci_dev* hdev = (struct hci_dev *) skb->dev;
213 struct hci_uart *hu; 213 struct hci_uart *hu;
214 214
215 if (!hdev) { 215 if (!hdev) {
216 BT_ERR("Frame for unknown device (hdev=NULL)"); 216 BT_ERR("Frame for unknown device (hdev=NULL)");
217 return -ENODEV; 217 return -ENODEV;
218 } 218 }
219 219
220 if (!test_bit(HCI_RUNNING, &hdev->flags)) 220 if (!test_bit(HCI_RUNNING, &hdev->flags))
221 return -EBUSY; 221 return -EBUSY;
222 222
223 hu = (struct hci_uart *) hdev->driver_data; 223 hu = (struct hci_uart *) hdev->driver_data;
224 224
225 BT_DBG("%s: type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len); 225 BT_DBG("%s: type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len);
226 226
227 hu->proto->enqueue(hu, skb); 227 hu->proto->enqueue(hu, skb);
228 228
229 hci_uart_tx_wakeup(hu); 229 hci_uart_tx_wakeup(hu);
230 230
231 return 0; 231 return 0;
232 } 232 }
233 233
234 static void hci_uart_destruct(struct hci_dev *hdev) 234 static void hci_uart_destruct(struct hci_dev *hdev)
235 { 235 {
236 if (!hdev) 236 if (!hdev)
237 return; 237 return;
238 238
239 BT_DBG("%s", hdev->name); 239 BT_DBG("%s", hdev->name);
240 kfree(hdev->driver_data); 240 kfree(hdev->driver_data);
241 } 241 }
242 242
243 /* ------ LDISC part ------ */ 243 /* ------ LDISC part ------ */
244 /* hci_uart_tty_open 244 /* hci_uart_tty_open
245 * 245 *
246 * Called when line discipline changed to HCI_UART. 246 * Called when line discipline changed to HCI_UART.
247 * 247 *
248 * Arguments: 248 * Arguments:
249 * tty pointer to tty info structure 249 * tty pointer to tty info structure
250 * Return Value: 250 * Return Value:
251 * 0 if success, otherwise error code 251 * 0 if success, otherwise error code
252 */ 252 */
253 static int hci_uart_tty_open(struct tty_struct *tty) 253 static int hci_uart_tty_open(struct tty_struct *tty)
254 { 254 {
255 struct hci_uart *hu = (void *) tty->disc_data; 255 struct hci_uart *hu = (void *) tty->disc_data;
256 256
257 BT_DBG("tty %p", tty); 257 BT_DBG("tty %p", tty);
258 258
259 /* FIXME: This btw is bogus, nothing requires the old ldisc to clear 259 /* FIXME: This btw is bogus, nothing requires the old ldisc to clear
260 the pointer */ 260 the pointer */
261 if (hu) 261 if (hu)
262 return -EEXIST; 262 return -EEXIST;
263 263
264 /* Error if the tty has no write op instead of leaving an exploitable 264 /* Error if the tty has no write op instead of leaving an exploitable
265 hole */ 265 hole */
266 if (tty->ops->write == NULL) 266 if (tty->ops->write == NULL)
267 return -EOPNOTSUPP; 267 return -EOPNOTSUPP;
268 268
269 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) { 269 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
270 BT_ERR("Can't allocate control structure"); 270 BT_ERR("Can't allocate control structure");
271 return -ENFILE; 271 return -ENFILE;
272 } 272 }
273 273
274 tty->disc_data = hu; 274 tty->disc_data = hu;
275 hu->tty = tty; 275 hu->tty = tty;
276 tty->receive_room = 65536; 276 tty->receive_room = 65536;
277 277
278 spin_lock_init(&hu->rx_lock); 278 spin_lock_init(&hu->rx_lock);
279 279
280 /* Flush any pending characters in the driver and line discipline. */ 280 /* Flush any pending characters in the driver and line discipline. */
281 281
282 /* FIXME: why is this needed. Note don't use ldisc_ref here as the 282 /* FIXME: why is this needed. Note don't use ldisc_ref here as the
283 open path is before the ldisc is referencable */ 283 open path is before the ldisc is referencable */
284 284
285 if (tty->ldisc->ops->flush_buffer) 285 if (tty->ldisc->ops->flush_buffer)
286 tty->ldisc->ops->flush_buffer(tty); 286 tty->ldisc->ops->flush_buffer(tty);
287 tty_driver_flush_buffer(tty); 287 tty_driver_flush_buffer(tty);
288 288
289 return 0; 289 return 0;
290 } 290 }
291 291
292 /* hci_uart_tty_close() 292 /* hci_uart_tty_close()
293 * 293 *
294 * Called when the line discipline is changed to something 294 * Called when the line discipline is changed to something
295 * else, the tty is closed, or the tty detects a hangup. 295 * else, the tty is closed, or the tty detects a hangup.
296 */ 296 */
297 static void hci_uart_tty_close(struct tty_struct *tty) 297 static void hci_uart_tty_close(struct tty_struct *tty)
298 { 298 {
299 struct hci_uart *hu = (void *)tty->disc_data; 299 struct hci_uart *hu = (void *)tty->disc_data;
300 300
301 BT_DBG("tty %p", tty); 301 BT_DBG("tty %p", tty);
302 302
303 /* Detach from the tty */ 303 /* Detach from the tty */
304 tty->disc_data = NULL; 304 tty->disc_data = NULL;
305 305
306 if (hu) { 306 if (hu) {
307 struct hci_dev *hdev = hu->hdev; 307 struct hci_dev *hdev = hu->hdev;
308 308
309 if (hdev) 309 if (hdev)
310 hci_uart_close(hdev); 310 hci_uart_close(hdev);
311 311
312 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) { 312 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) {
313 hu->proto->close(hu); 313 hu->proto->close(hu);
314 if (hdev) { 314 if (hdev) {
315 hci_unregister_dev(hdev); 315 hci_unregister_dev(hdev);
316 hci_free_dev(hdev); 316 hci_free_dev(hdev);
317 } 317 }
318 } 318 }
319 } 319 }
320 } 320 }
321 321
322 /* hci_uart_tty_wakeup() 322 /* hci_uart_tty_wakeup()
323 * 323 *
324 * Callback for transmit wakeup. Called when low level 324 * Callback for transmit wakeup. Called when low level
325 * device driver can accept more send data. 325 * device driver can accept more send data.
326 * 326 *
327 * Arguments: tty pointer to associated tty instance data 327 * Arguments: tty pointer to associated tty instance data
328 * Return Value: None 328 * Return Value: None
329 */ 329 */
330 static void hci_uart_tty_wakeup(struct tty_struct *tty) 330 static void hci_uart_tty_wakeup(struct tty_struct *tty)
331 { 331 {
332 struct hci_uart *hu = (void *)tty->disc_data; 332 struct hci_uart *hu = (void *)tty->disc_data;
333 333
334 BT_DBG(""); 334 BT_DBG("");
335 335
336 if (!hu) 336 if (!hu)
337 return; 337 return;
338 338
339 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 339 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
340 340
341 if (tty != hu->tty) 341 if (tty != hu->tty)
342 return; 342 return;
343 343
344 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 344 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
345 hci_uart_tx_wakeup(hu); 345 hci_uart_tx_wakeup(hu);
346 } 346 }
347 347
348 /* hci_uart_tty_receive() 348 /* hci_uart_tty_receive()
349 * 349 *
350 * Called by tty low level driver when receive data is 350 * Called by tty low level driver when receive data is
351 * available. 351 * available.
352 * 352 *
353 * Arguments: tty pointer to tty isntance data 353 * Arguments: tty pointer to tty isntance data
354 * data pointer to received data 354 * data pointer to received data
355 * flags pointer to flags for data 355 * flags pointer to flags for data
356 * count count of received data in bytes 356 * count count of received data in bytes
357 * 357 *
358 * Return Value: None 358 * Return Value: None
359 */ 359 */
360 static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count) 360 static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count)
361 { 361 {
362 int ret;
362 struct hci_uart *hu = (void *)tty->disc_data; 363 struct hci_uart *hu = (void *)tty->disc_data;
363 364
364 if (!hu || tty != hu->tty) 365 if (!hu || tty != hu->tty)
365 return; 366 return;
366 367
367 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) 368 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
368 return; 369 return;
369 370
370 spin_lock(&hu->rx_lock); 371 spin_lock(&hu->rx_lock);
371 hu->proto->recv(hu, (void *) data, count); 372 ret = hu->proto->recv(hu, (void *) data, count);
372 hu->hdev->stat.byte_rx += count; 373 if (ret > 0)
374 hu->hdev->stat.byte_rx += count;
373 spin_unlock(&hu->rx_lock); 375 spin_unlock(&hu->rx_lock);
374 376
375 tty_unthrottle(tty); 377 tty_unthrottle(tty);
376 } 378 }
377 379
378 static int hci_uart_register_dev(struct hci_uart *hu) 380 static int hci_uart_register_dev(struct hci_uart *hu)
379 { 381 {
380 struct hci_dev *hdev; 382 struct hci_dev *hdev;
381 383
382 BT_DBG(""); 384 BT_DBG("");
383 385
384 /* Initialize and register HCI device */ 386 /* Initialize and register HCI device */
385 hdev = hci_alloc_dev(); 387 hdev = hci_alloc_dev();
386 if (!hdev) { 388 if (!hdev) {
387 BT_ERR("Can't allocate HCI device"); 389 BT_ERR("Can't allocate HCI device");
388 return -ENOMEM; 390 return -ENOMEM;
389 } 391 }
390 392
391 hu->hdev = hdev; 393 hu->hdev = hdev;
392 394
393 hdev->bus = HCI_UART; 395 hdev->bus = HCI_UART;
394 hdev->driver_data = hu; 396 hdev->driver_data = hu;
395 397
396 hdev->open = hci_uart_open; 398 hdev->open = hci_uart_open;
397 hdev->close = hci_uart_close; 399 hdev->close = hci_uart_close;
398 hdev->flush = hci_uart_flush; 400 hdev->flush = hci_uart_flush;
399 hdev->send = hci_uart_send_frame; 401 hdev->send = hci_uart_send_frame;
400 hdev->destruct = hci_uart_destruct; 402 hdev->destruct = hci_uart_destruct;
401 hdev->parent = hu->tty->dev; 403 hdev->parent = hu->tty->dev;
402 404
403 hdev->owner = THIS_MODULE; 405 hdev->owner = THIS_MODULE;
404 406
405 if (!reset) 407 if (!reset)
406 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 408 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
407 409
408 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags)) 410 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags))
409 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); 411 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
410 412
411 if (hci_register_dev(hdev) < 0) { 413 if (hci_register_dev(hdev) < 0) {
412 BT_ERR("Can't register HCI device"); 414 BT_ERR("Can't register HCI device");
413 hci_free_dev(hdev); 415 hci_free_dev(hdev);
414 return -ENODEV; 416 return -ENODEV;
415 } 417 }
416 418
417 return 0; 419 return 0;
418 } 420 }
419 421
420 static int hci_uart_set_proto(struct hci_uart *hu, int id) 422 static int hci_uart_set_proto(struct hci_uart *hu, int id)
421 { 423 {
422 struct hci_uart_proto *p; 424 struct hci_uart_proto *p;
423 int err; 425 int err;
424 426
425 p = hci_uart_get_proto(id); 427 p = hci_uart_get_proto(id);
426 if (!p) 428 if (!p)
427 return -EPROTONOSUPPORT; 429 return -EPROTONOSUPPORT;
428 430
429 err = p->open(hu); 431 err = p->open(hu);
430 if (err) 432 if (err)
431 return err; 433 return err;
432 434
433 hu->proto = p; 435 hu->proto = p;
434 436
435 err = hci_uart_register_dev(hu); 437 err = hci_uart_register_dev(hu);
436 if (err) { 438 if (err) {
437 p->close(hu); 439 p->close(hu);
438 return err; 440 return err;
439 } 441 }
440 442
441 return 0; 443 return 0;
442 } 444 }
443 445
444 /* hci_uart_tty_ioctl() 446 /* hci_uart_tty_ioctl()
445 * 447 *
446 * Process IOCTL system call for the tty device. 448 * Process IOCTL system call for the tty device.
447 * 449 *
448 * Arguments: 450 * Arguments:
449 * 451 *
450 * tty pointer to tty instance data 452 * tty pointer to tty instance data
451 * file pointer to open file object for device 453 * file pointer to open file object for device
452 * cmd IOCTL command code 454 * cmd IOCTL command code
453 * arg argument for IOCTL call (cmd dependent) 455 * arg argument for IOCTL call (cmd dependent)
454 * 456 *
455 * Return Value: Command dependent 457 * Return Value: Command dependent
456 */ 458 */
457 static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, 459 static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
458 unsigned int cmd, unsigned long arg) 460 unsigned int cmd, unsigned long arg)
459 { 461 {
460 struct hci_uart *hu = (void *)tty->disc_data; 462 struct hci_uart *hu = (void *)tty->disc_data;
461 int err = 0; 463 int err = 0;
462 464
463 BT_DBG(""); 465 BT_DBG("");
464 466
465 /* Verify the status of the device */ 467 /* Verify the status of the device */
466 if (!hu) 468 if (!hu)
467 return -EBADF; 469 return -EBADF;
468 470
469 switch (cmd) { 471 switch (cmd) {
470 case HCIUARTSETPROTO: 472 case HCIUARTSETPROTO:
471 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) { 473 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) {
472 err = hci_uart_set_proto(hu, arg); 474 err = hci_uart_set_proto(hu, arg);
473 if (err) { 475 if (err) {
474 clear_bit(HCI_UART_PROTO_SET, &hu->flags); 476 clear_bit(HCI_UART_PROTO_SET, &hu->flags);
475 return err; 477 return err;
476 } 478 }
477 } else 479 } else
478 return -EBUSY; 480 return -EBUSY;
479 break; 481 break;
480 482
481 case HCIUARTGETPROTO: 483 case HCIUARTGETPROTO:
482 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 484 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
483 return hu->proto->id; 485 return hu->proto->id;
484 return -EUNATCH; 486 return -EUNATCH;
485 487
486 case HCIUARTGETDEVICE: 488 case HCIUARTGETDEVICE:
487 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 489 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
488 return hu->hdev->id; 490 return hu->hdev->id;
489 return -EUNATCH; 491 return -EUNATCH;
490 492
491 case HCIUARTSETFLAGS: 493 case HCIUARTSETFLAGS:
492 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 494 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
493 return -EBUSY; 495 return -EBUSY;
494 hu->hdev_flags = arg; 496 hu->hdev_flags = arg;
495 break; 497 break;
496 498
497 case HCIUARTGETFLAGS: 499 case HCIUARTGETFLAGS:
498 return hu->hdev_flags; 500 return hu->hdev_flags;
499 501
500 default: 502 default:
501 err = n_tty_ioctl_helper(tty, file, cmd, arg); 503 err = n_tty_ioctl_helper(tty, file, cmd, arg);
502 break; 504 break;
503 }; 505 };
504 506
505 return err; 507 return err;
506 } 508 }
507 509
508 /* 510 /*
509 * We don't provide read/write/poll interface for user space. 511 * We don't provide read/write/poll interface for user space.
510 */ 512 */
511 static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, 513 static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
512 unsigned char __user *buf, size_t nr) 514 unsigned char __user *buf, size_t nr)
513 { 515 {
514 return 0; 516 return 0;
515 } 517 }
516 518
517 static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, 519 static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
518 const unsigned char *data, size_t count) 520 const unsigned char *data, size_t count)
519 { 521 {
520 return 0; 522 return 0;
521 } 523 }
522 524
523 static unsigned int hci_uart_tty_poll(struct tty_struct *tty, 525 static unsigned int hci_uart_tty_poll(struct tty_struct *tty,
524 struct file *filp, poll_table *wait) 526 struct file *filp, poll_table *wait)
525 { 527 {
526 return 0; 528 return 0;
527 } 529 }
528 530
529 static int __init hci_uart_init(void) 531 static int __init hci_uart_init(void)
530 { 532 {
531 static struct tty_ldisc_ops hci_uart_ldisc; 533 static struct tty_ldisc_ops hci_uart_ldisc;
532 int err; 534 int err;
533 535
534 BT_INFO("HCI UART driver ver %s", VERSION); 536 BT_INFO("HCI UART driver ver %s", VERSION);
535 537
536 /* Register the tty discipline */ 538 /* Register the tty discipline */
537 539
538 memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc)); 540 memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
539 hci_uart_ldisc.magic = TTY_LDISC_MAGIC; 541 hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
540 hci_uart_ldisc.name = "n_hci"; 542 hci_uart_ldisc.name = "n_hci";
541 hci_uart_ldisc.open = hci_uart_tty_open; 543 hci_uart_ldisc.open = hci_uart_tty_open;
542 hci_uart_ldisc.close = hci_uart_tty_close; 544 hci_uart_ldisc.close = hci_uart_tty_close;
543 hci_uart_ldisc.read = hci_uart_tty_read; 545 hci_uart_ldisc.read = hci_uart_tty_read;
544 hci_uart_ldisc.write = hci_uart_tty_write; 546 hci_uart_ldisc.write = hci_uart_tty_write;
545 hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; 547 hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
546 hci_uart_ldisc.poll = hci_uart_tty_poll; 548 hci_uart_ldisc.poll = hci_uart_tty_poll;
547 hci_uart_ldisc.receive_buf = hci_uart_tty_receive; 549 hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
548 hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup; 550 hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
549 hci_uart_ldisc.owner = THIS_MODULE; 551 hci_uart_ldisc.owner = THIS_MODULE;
550 552
551 if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { 553 if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
552 BT_ERR("HCI line discipline registration failed. (%d)", err); 554 BT_ERR("HCI line discipline registration failed. (%d)", err);
553 return err; 555 return err;
554 } 556 }
555 557
556 #ifdef CONFIG_BT_HCIUART_H4 558 #ifdef CONFIG_BT_HCIUART_H4
557 h4_init(); 559 h4_init();
558 #endif 560 #endif
559 #ifdef CONFIG_BT_HCIUART_BCSP 561 #ifdef CONFIG_BT_HCIUART_BCSP
560 bcsp_init(); 562 bcsp_init();
561 #endif 563 #endif
562 #ifdef CONFIG_BT_HCIUART_LL 564 #ifdef CONFIG_BT_HCIUART_LL
563 ll_init(); 565 ll_init();
564 #endif 566 #endif
565 #ifdef CONFIG_BT_HCIUART_ATH3K 567 #ifdef CONFIG_BT_HCIUART_ATH3K
566 ath_init(); 568 ath_init();
567 #endif 569 #endif
568 570
569 return 0; 571 return 0;
570 } 572 }
571 573
572 static void __exit hci_uart_exit(void) 574 static void __exit hci_uart_exit(void)
573 { 575 {
574 int err; 576 int err;
575 577
576 #ifdef CONFIG_BT_HCIUART_H4 578 #ifdef CONFIG_BT_HCIUART_H4
577 h4_deinit(); 579 h4_deinit();
578 #endif 580 #endif
579 #ifdef CONFIG_BT_HCIUART_BCSP 581 #ifdef CONFIG_BT_HCIUART_BCSP
580 bcsp_deinit(); 582 bcsp_deinit();
581 #endif 583 #endif
582 #ifdef CONFIG_BT_HCIUART_LL 584 #ifdef CONFIG_BT_HCIUART_LL
583 ll_deinit(); 585 ll_deinit();
584 #endif 586 #endif
585 #ifdef CONFIG_BT_HCIUART_ATH3K 587 #ifdef CONFIG_BT_HCIUART_ATH3K
586 ath_deinit(); 588 ath_deinit();
587 #endif 589 #endif
588 590
589 /* Release tty registration of line discipline */ 591 /* Release tty registration of line discipline */
590 if ((err = tty_unregister_ldisc(N_HCI))) 592 if ((err = tty_unregister_ldisc(N_HCI)))
591 BT_ERR("Can't unregister HCI line discipline (%d)", err); 593 BT_ERR("Can't unregister HCI line discipline (%d)", err);
592 } 594 }
593 595
594 module_init(hci_uart_init); 596 module_init(hci_uart_init);
595 module_exit(hci_uart_exit); 597 module_exit(hci_uart_exit);
596 598
597 module_param(reset, bool, 0644); 599 module_param(reset, bool, 0644);
598 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); 600 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
599 601
600 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 602 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
601 MODULE_DESCRIPTION("Bluetooth HCI UART driver ver " VERSION); 603 MODULE_DESCRIPTION("Bluetooth HCI UART driver ver " VERSION);
602 MODULE_VERSION(VERSION); 604 MODULE_VERSION(VERSION);
603 MODULE_LICENSE("GPL"); 605 MODULE_LICENSE("GPL");
604 MODULE_ALIAS_LDISC(N_HCI); 606 MODULE_ALIAS_LDISC(N_HCI);
605 607