diff options
Diffstat (limited to 'drivers/bluetooth/hci_ldisc.c')
| -rw-r--r-- | drivers/bluetooth/hci_ldisc.c | 134 |
1 files changed, 69 insertions, 65 deletions
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index aed80cc22890..4a775f6ea390 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
| @@ -1,33 +1,27 @@ | |||
| 1 | /* | ||
| 2 | BlueZ - Bluetooth protocol stack for Linux | ||
| 3 | Copyright (C) 2000-2001 Qualcomm Incorporated | ||
| 4 | |||
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> | ||
| 6 | |||
| 7 | This program is free software; you can redistribute it and/or modify | ||
| 8 | it under the terms of the GNU General Public License version 2 as | ||
| 9 | published by the Free Software Foundation; | ||
| 10 | |||
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | ||
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | ||
| 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES | ||
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 19 | |||
| 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, | ||
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | ||
| 22 | SOFTWARE IS DISCLAIMED. | ||
| 23 | */ | ||
| 24 | |||
| 25 | /* | 1 | /* |
| 26 | * Bluetooth HCI UART driver. | ||
| 27 | * | 2 | * |
| 28 | * $Id: hci_ldisc.c,v 1.5 2002/10/02 18:37:20 maxk Exp $ | 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 | * | ||
| 29 | */ | 24 | */ |
| 30 | #define VERSION "2.1" | ||
| 31 | 25 | ||
| 32 | #include <linux/config.h> | 26 | #include <linux/config.h> |
| 33 | #include <linux/module.h> | 27 | #include <linux/module.h> |
| @@ -59,6 +53,8 @@ | |||
| 59 | #define BT_DBG( A... ) | 53 | #define BT_DBG( A... ) |
| 60 | #endif | 54 | #endif |
| 61 | 55 | ||
| 56 | #define VERSION "2.2" | ||
| 57 | |||
| 62 | static int reset = 0; | 58 | static int reset = 0; |
| 63 | 59 | ||
| 64 | static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; | 60 | static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; |
| @@ -72,6 +68,7 @@ int hci_uart_register_proto(struct hci_uart_proto *p) | |||
| 72 | return -EEXIST; | 68 | return -EEXIST; |
| 73 | 69 | ||
| 74 | hup[p->id] = p; | 70 | hup[p->id] = p; |
| 71 | |||
| 75 | return 0; | 72 | return 0; |
| 76 | } | 73 | } |
| 77 | 74 | ||
| @@ -84,6 +81,7 @@ int hci_uart_unregister_proto(struct hci_uart_proto *p) | |||
| 84 | return -EINVAL; | 81 | return -EINVAL; |
| 85 | 82 | ||
| 86 | hup[p->id] = NULL; | 83 | hup[p->id] = NULL; |
| 84 | |||
| 87 | return 0; | 85 | return 0; |
| 88 | } | 86 | } |
| 89 | 87 | ||
| @@ -91,13 +89,14 @@ static struct hci_uart_proto *hci_uart_get_proto(unsigned int id) | |||
| 91 | { | 89 | { |
| 92 | if (id >= HCI_UART_MAX_PROTO) | 90 | if (id >= HCI_UART_MAX_PROTO) |
| 93 | return NULL; | 91 | return NULL; |
| 92 | |||
| 94 | return hup[id]; | 93 | return hup[id]; |
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) | 96 | static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) |
| 98 | { | 97 | { |
| 99 | struct hci_dev *hdev = hu->hdev; | 98 | struct hci_dev *hdev = hu->hdev; |
| 100 | 99 | ||
| 101 | /* Update HCI stat counters */ | 100 | /* Update HCI stat counters */ |
| 102 | switch (pkt_type) { | 101 | switch (pkt_type) { |
| 103 | case HCI_COMMAND_PKT: | 102 | case HCI_COMMAND_PKT: |
| @@ -117,10 +116,12 @@ static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) | |||
| 117 | static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) | 116 | static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) |
| 118 | { | 117 | { |
| 119 | struct sk_buff *skb = hu->tx_skb; | 118 | struct sk_buff *skb = hu->tx_skb; |
| 119 | |||
| 120 | if (!skb) | 120 | if (!skb) |
| 121 | skb = hu->proto->dequeue(hu); | 121 | skb = hu->proto->dequeue(hu); |
| 122 | else | 122 | else |
| 123 | hu->tx_skb = NULL; | 123 | hu->tx_skb = NULL; |
| 124 | |||
| 124 | return skb; | 125 | return skb; |
| 125 | } | 126 | } |
| 126 | 127 | ||
| @@ -129,7 +130,7 @@ int hci_uart_tx_wakeup(struct hci_uart *hu) | |||
| 129 | struct tty_struct *tty = hu->tty; | 130 | struct tty_struct *tty = hu->tty; |
| 130 | struct hci_dev *hdev = hu->hdev; | 131 | struct hci_dev *hdev = hu->hdev; |
| 131 | struct sk_buff *skb; | 132 | struct sk_buff *skb; |
| 132 | 133 | ||
| 133 | if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { | 134 | if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { |
| 134 | set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); | 135 | set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); |
| 135 | return 0; | 136 | return 0; |
| @@ -142,7 +143,7 @@ restart: | |||
| 142 | 143 | ||
| 143 | while ((skb = hci_uart_dequeue(hu))) { | 144 | while ((skb = hci_uart_dequeue(hu))) { |
| 144 | int len; | 145 | int len; |
| 145 | 146 | ||
| 146 | set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); | 147 | set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); |
| 147 | len = tty->driver->write(tty, skb->data, skb->len); | 148 | len = tty->driver->write(tty, skb->data, skb->len); |
| 148 | hdev->stat.byte_tx += len; | 149 | hdev->stat.byte_tx += len; |
| @@ -152,11 +153,11 @@ restart: | |||
| 152 | hu->tx_skb = skb; | 153 | hu->tx_skb = skb; |
| 153 | break; | 154 | break; |
| 154 | } | 155 | } |
| 155 | 156 | ||
| 156 | hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type); | 157 | hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type); |
| 157 | kfree_skb(skb); | 158 | kfree_skb(skb); |
| 158 | } | 159 | } |
| 159 | 160 | ||
| 160 | if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) | 161 | if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) |
| 161 | goto restart; | 162 | goto restart; |
| 162 | 163 | ||
| @@ -173,6 +174,7 @@ static int hci_uart_open(struct hci_dev *hdev) | |||
| 173 | /* Nothing to do for UART driver */ | 174 | /* Nothing to do for UART driver */ |
| 174 | 175 | ||
| 175 | set_bit(HCI_RUNNING, &hdev->flags); | 176 | set_bit(HCI_RUNNING, &hdev->flags); |
| 177 | |||
| 176 | return 0; | 178 | return 0; |
| 177 | } | 179 | } |
| 178 | 180 | ||
| @@ -234,6 +236,7 @@ static int hci_uart_send_frame(struct sk_buff *skb) | |||
| 234 | hu->proto->enqueue(hu, skb); | 236 | hu->proto->enqueue(hu, skb); |
| 235 | 237 | ||
| 236 | hci_uart_tx_wakeup(hu); | 238 | hci_uart_tx_wakeup(hu); |
| 239 | |||
| 237 | return 0; | 240 | return 0; |
| 238 | } | 241 | } |
| 239 | 242 | ||
| @@ -241,7 +244,8 @@ static void hci_uart_destruct(struct hci_dev *hdev) | |||
| 241 | { | 244 | { |
| 242 | struct hci_uart *hu; | 245 | struct hci_uart *hu; |
| 243 | 246 | ||
| 244 | if (!hdev) return; | 247 | if (!hdev) |
| 248 | return; | ||
| 245 | 249 | ||
| 246 | BT_DBG("%s", hdev->name); | 250 | BT_DBG("%s", hdev->name); |
| 247 | 251 | ||
| @@ -272,6 +276,7 @@ static int hci_uart_tty_open(struct tty_struct *tty) | |||
| 272 | BT_ERR("Can't allocate controll structure"); | 276 | BT_ERR("Can't allocate controll structure"); |
| 273 | return -ENFILE; | 277 | return -ENFILE; |
| 274 | } | 278 | } |
| 279 | |||
| 275 | memset(hu, 0, sizeof(struct hci_uart)); | 280 | memset(hu, 0, sizeof(struct hci_uart)); |
| 276 | 281 | ||
| 277 | tty->disc_data = hu; | 282 | tty->disc_data = hu; |
| @@ -280,8 +285,10 @@ static int hci_uart_tty_open(struct tty_struct *tty) | |||
| 280 | spin_lock_init(&hu->rx_lock); | 285 | spin_lock_init(&hu->rx_lock); |
| 281 | 286 | ||
| 282 | /* Flush any pending characters in the driver and line discipline. */ | 287 | /* Flush any pending characters in the driver and line discipline. */ |
| 288 | |||
| 283 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the | 289 | /* FIXME: why is this needed. Note don't use ldisc_ref here as the |
| 284 | open path is before the ldisc is referencable */ | 290 | open path is before the ldisc is referencable */ |
| 291 | |||
| 285 | if (tty->ldisc.flush_buffer) | 292 | if (tty->ldisc.flush_buffer) |
| 286 | tty->ldisc.flush_buffer(tty); | 293 | tty->ldisc.flush_buffer(tty); |
| 287 | 294 | ||
| @@ -372,13 +379,13 @@ static int hci_uart_tty_room (struct tty_struct *tty) | |||
| 372 | static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) | 379 | static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) |
| 373 | { | 380 | { |
| 374 | struct hci_uart *hu = (void *)tty->disc_data; | 381 | struct hci_uart *hu = (void *)tty->disc_data; |
| 375 | 382 | ||
| 376 | if (!hu || tty != hu->tty) | 383 | if (!hu || tty != hu->tty) |
| 377 | return; | 384 | return; |
| 378 | 385 | ||
| 379 | if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) | 386 | if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) |
| 380 | return; | 387 | return; |
| 381 | 388 | ||
| 382 | spin_lock(&hu->rx_lock); | 389 | spin_lock(&hu->rx_lock); |
| 383 | hu->proto->recv(hu, (void *) data, count); | 390 | hu->proto->recv(hu, (void *) data, count); |
| 384 | hu->hdev->stat.byte_rx += count; | 391 | hu->hdev->stat.byte_rx += count; |
| @@ -429,8 +436,8 @@ static int hci_uart_register_dev(struct hci_uart *hu) | |||
| 429 | static int hci_uart_set_proto(struct hci_uart *hu, int id) | 436 | static int hci_uart_set_proto(struct hci_uart *hu, int id) |
| 430 | { | 437 | { |
| 431 | struct hci_uart_proto *p; | 438 | struct hci_uart_proto *p; |
| 432 | int err; | 439 | int err; |
| 433 | 440 | ||
| 434 | p = hci_uart_get_proto(id); | 441 | p = hci_uart_get_proto(id); |
| 435 | if (!p) | 442 | if (!p) |
| 436 | return -EPROTONOSUPPORT; | 443 | return -EPROTONOSUPPORT; |
| @@ -446,6 +453,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id) | |||
| 446 | p->close(hu); | 453 | p->close(hu); |
| 447 | return err; | 454 | return err; |
| 448 | } | 455 | } |
| 456 | |||
| 449 | return 0; | 457 | return 0; |
| 450 | } | 458 | } |
| 451 | 459 | ||
| @@ -463,7 +471,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id) | |||
| 463 | * Return Value: Command dependent | 471 | * Return Value: Command dependent |
| 464 | */ | 472 | */ |
| 465 | static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, | 473 | static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, |
| 466 | unsigned int cmd, unsigned long arg) | 474 | unsigned int cmd, unsigned long arg) |
| 467 | { | 475 | { |
| 468 | struct hci_uart *hu = (void *)tty->disc_data; | 476 | struct hci_uart *hu = (void *)tty->disc_data; |
| 469 | int err = 0; | 477 | int err = 0; |
| @@ -483,14 +491,14 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, | |||
| 483 | return err; | 491 | return err; |
| 484 | } | 492 | } |
| 485 | tty->low_latency = 1; | 493 | tty->low_latency = 1; |
| 486 | } else | 494 | } else |
| 487 | return -EBUSY; | 495 | return -EBUSY; |
| 488 | 496 | ||
| 489 | case HCIUARTGETPROTO: | 497 | case HCIUARTGETPROTO: |
| 490 | if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) | 498 | if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) |
| 491 | return hu->proto->id; | 499 | return hu->proto->id; |
| 492 | return -EUNATCH; | 500 | return -EUNATCH; |
| 493 | 501 | ||
| 494 | default: | 502 | default: |
| 495 | err = n_tty_ioctl(tty, file, cmd, arg); | 503 | err = n_tty_ioctl(tty, file, cmd, arg); |
| 496 | break; | 504 | break; |
| @@ -502,28 +510,24 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, | |||
| 502 | /* | 510 | /* |
| 503 | * We don't provide read/write/poll interface for user space. | 511 | * We don't provide read/write/poll interface for user space. |
| 504 | */ | 512 | */ |
| 505 | static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, unsigned char __user *buf, size_t nr) | 513 | static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, |
| 514 | unsigned char __user *buf, size_t nr) | ||
| 506 | { | 515 | { |
| 507 | return 0; | 516 | return 0; |
| 508 | } | 517 | } |
| 509 | static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) | 518 | |
| 519 | static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, | ||
| 520 | const unsigned char *data, size_t count) | ||
| 510 | { | 521 | { |
| 511 | return 0; | 522 | return 0; |
| 512 | } | 523 | } |
| 513 | static unsigned int hci_uart_tty_poll(struct tty_struct *tty, struct file *filp, poll_table *wait) | 524 | |
| 525 | static unsigned int hci_uart_tty_poll(struct tty_struct *tty, | ||
| 526 | struct file *filp, poll_table *wait) | ||
| 514 | { | 527 | { |
| 515 | return 0; | 528 | return 0; |
| 516 | } | 529 | } |
| 517 | 530 | ||
| 518 | #ifdef CONFIG_BT_HCIUART_H4 | ||
| 519 | int h4_init(void); | ||
| 520 | int h4_deinit(void); | ||
| 521 | #endif | ||
| 522 | #ifdef CONFIG_BT_HCIUART_BCSP | ||
| 523 | int bcsp_init(void); | ||
| 524 | int bcsp_deinit(void); | ||
| 525 | #endif | ||
| 526 | |||
| 527 | static int __init hci_uart_init(void) | 531 | static int __init hci_uart_init(void) |
| 528 | { | 532 | { |
| 529 | static struct tty_ldisc hci_uart_ldisc; | 533 | static struct tty_ldisc hci_uart_ldisc; |
| @@ -534,18 +538,18 @@ static int __init hci_uart_init(void) | |||
| 534 | /* Register the tty discipline */ | 538 | /* Register the tty discipline */ |
| 535 | 539 | ||
| 536 | memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc)); | 540 | memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc)); |
| 537 | hci_uart_ldisc.magic = TTY_LDISC_MAGIC; | 541 | hci_uart_ldisc.magic = TTY_LDISC_MAGIC; |
| 538 | hci_uart_ldisc.name = "n_hci"; | 542 | hci_uart_ldisc.name = "n_hci"; |
| 539 | hci_uart_ldisc.open = hci_uart_tty_open; | 543 | hci_uart_ldisc.open = hci_uart_tty_open; |
| 540 | hci_uart_ldisc.close = hci_uart_tty_close; | 544 | hci_uart_ldisc.close = hci_uart_tty_close; |
| 541 | hci_uart_ldisc.read = hci_uart_tty_read; | 545 | hci_uart_ldisc.read = hci_uart_tty_read; |
| 542 | hci_uart_ldisc.write = hci_uart_tty_write; | 546 | hci_uart_ldisc.write = hci_uart_tty_write; |
| 543 | hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; | 547 | hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; |
| 544 | hci_uart_ldisc.poll = hci_uart_tty_poll; | 548 | hci_uart_ldisc.poll = hci_uart_tty_poll; |
| 545 | hci_uart_ldisc.receive_room= hci_uart_tty_room; | 549 | hci_uart_ldisc.receive_room = hci_uart_tty_room; |
| 546 | hci_uart_ldisc.receive_buf = hci_uart_tty_receive; | 550 | hci_uart_ldisc.receive_buf = hci_uart_tty_receive; |
| 547 | hci_uart_ldisc.write_wakeup= hci_uart_tty_wakeup; | 551 | hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup; |
| 548 | hci_uart_ldisc.owner = THIS_MODULE; | 552 | hci_uart_ldisc.owner = THIS_MODULE; |
| 549 | 553 | ||
| 550 | if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { | 554 | if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { |
| 551 | BT_ERR("HCI line discipline registration failed. (%d)", err); | 555 | BT_ERR("HCI line discipline registration failed. (%d)", err); |
