Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[Bluetooth] Cleanup of the HCI UART driver

This patch contains the big cleanup of the HCI UART driver. The uneeded
header files are removed and their structure declarations are moved into
the protocol implementations.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

+258 -306
+78 -42
drivers/bluetooth/hci_bcsp.c
··· 1 - /* 2 - BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ). 3 - Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com> 4 - 5 - Based on 6 - hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com> 7 - ABCSP by Carl Orsborn <cjo@csr.com> 8 - 9 - This program is free software; you can redistribute it and/or modify 10 - it under the terms of the GNU General Public License version 2 as 11 - published by the Free Software Foundation; 12 - 13 - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 16 - IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 17 - CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 18 - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 - 22 - ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 23 - COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 24 - SOFTWARE IS DISCLAIMED. 25 - */ 26 - 27 1 /* 28 - * $Id: hci_bcsp.c,v 1.2 2002/09/26 05:05:14 maxk Exp $ 2 + * 3 + * Bluetooth HCI UART driver 4 + * 5 + * Copyright (C) 2002-2003 Fabrizio Gennari <fabrizio.gennari@philips.com> 6 + * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 7 + * 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + * 19 + * You should have received a copy of the GNU General Public License 20 + * along with this program; if not, write to the Free Software 21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 + * 29 23 */ 30 - 31 - #define VERSION "0.3" 32 24 33 25 #include <linux/config.h> 34 26 #include <linux/module.h> ··· 44 52 45 53 #include <net/bluetooth/bluetooth.h> 46 54 #include <net/bluetooth/hci_core.h> 55 + 47 56 #include "hci_uart.h" 48 - #include "hci_bcsp.h" 49 57 50 58 #ifndef CONFIG_BT_HCIUART_DEBUG 51 59 #undef BT_DBG 52 60 #define BT_DBG( A... ) 53 61 #endif 54 62 63 + #define VERSION "0.3" 64 + 55 65 static int txcrc = 1; 56 66 static int hciextn = 1; 67 + 68 + #define BCSP_TXWINSIZE 4 69 + 70 + #define BCSP_ACK_PKT 0x05 71 + #define BCSP_LE_PKT 0x06 72 + 73 + struct bcsp_struct { 74 + struct sk_buff_head unack; /* Unack'ed packets queue */ 75 + struct sk_buff_head rel; /* Reliable packets queue */ 76 + struct sk_buff_head unrel; /* Unreliable packets queue */ 77 + 78 + unsigned long rx_count; 79 + struct sk_buff *rx_skb; 80 + u8 rxseq_txack; /* rxseq == txack. */ 81 + u8 rxack; /* Last packet sent by us that the peer ack'ed */ 82 + struct timer_list tbcsp; 83 + 84 + enum { 85 + BCSP_W4_PKT_DELIMITER, 86 + BCSP_W4_PKT_START, 87 + BCSP_W4_BCSP_HDR, 88 + BCSP_W4_DATA, 89 + BCSP_W4_CRC 90 + } rx_state; 91 + 92 + enum { 93 + BCSP_ESCSTATE_NOESC, 94 + BCSP_ESCSTATE_ESC 95 + } rx_esc_state; 96 + 97 + u8 use_crc; 98 + u16 message_crc; 99 + u8 txack_req; /* Do we need to send ack's to the peer? */ 100 + 101 + /* Reliable packet sequence number - used to assign seq to each rel pkt. */ 102 + u8 msgq_txseq; 103 + }; 57 104 58 105 /* ---- BCSP CRC calculation ---- */ 59 106 ··· 143 112 rev |= (crc & 1); 144 113 crc = crc >> 1; 145 114 } 115 + 146 116 return (rev); 147 117 } 148 118 ··· 152 120 static void bcsp_slip_msgdelim(struct sk_buff *skb) 153 121 { 154 122 const char pkt_delim = 0xc0; 123 + 155 124 memcpy(skb_put(skb, 1), &pkt_delim, 1); 156 125 } 157 126 ··· 348 315 349 316 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 350 317 351 - 352 318 /* We could not send a reliable packet, either because there are 353 319 none or because there are too many unack'ed pkts. Did we receive 354 320 any packets we have not acknowledged yet ? */ ··· 393 361 BT_ERR("Peer acked invalid packet"); 394 362 395 363 BT_DBG("Removing %u pkts out of %u, up to seqno %u", 396 - pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07); 364 + pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07); 397 365 398 366 for (i = 0, skb = ((struct sk_buff *) &bcsp->unack)->next; i < pkts_to_be_removed 399 367 && skb != (struct sk_buff *) &bcsp->unack; i++) { ··· 404 372 kfree_skb(skb); 405 373 skb = nskb; 406 374 } 375 + 407 376 if (bcsp->unack.qlen == 0) 408 377 del_timer(&bcsp->tbcsp); 378 + 409 379 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 410 380 411 381 if (i != pkts_to_be_removed) ··· 562 528 563 529 hci_recv_frame(bcsp->rx_skb); 564 530 } 531 + 565 532 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 566 533 bcsp->rx_skb = NULL; 567 534 } ··· 631 596 632 597 BT_ERR ("Checksum failed: computed %04x received %04x", 633 598 bcsp_crc_reverse(bcsp->message_crc), 634 - (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) + 635 - bcsp->rx_skb->data[bcsp->rx_skb->len - 1]); 599 + (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) + 600 + bcsp->rx_skb->data[bcsp->rx_skb->len - 1]); 636 601 637 602 kfree_skb(bcsp->rx_skb); 638 603 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; ··· 666 631 bcsp->rx_count = 4; 667 632 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; 668 633 BCSP_CRC_INIT(bcsp->message_crc); 669 - 634 + 670 635 /* Do not increment ptr or decrement count 671 636 * Allocate packet. Max len of a BCSP pkt= 672 637 * 0xFFF (payload) +4 (header) +2 (crc) */ ··· 754 719 } 755 720 756 721 static struct hci_uart_proto bcsp = { 757 - .id = HCI_UART_BCSP, 758 - .open = bcsp_open, 759 - .close = bcsp_close, 760 - .enqueue = bcsp_enqueue, 761 - .dequeue = bcsp_dequeue, 762 - .recv = bcsp_recv, 763 - .flush = bcsp_flush 722 + .id = HCI_UART_BCSP, 723 + .open = bcsp_open, 724 + .close = bcsp_close, 725 + .enqueue = bcsp_enqueue, 726 + .dequeue = bcsp_dequeue, 727 + .recv = bcsp_recv, 728 + .flush = bcsp_flush 764 729 }; 765 730 766 731 int bcsp_init(void) 767 732 { 768 733 int err = hci_uart_register_proto(&bcsp); 734 + 769 735 if (!err) 770 736 BT_INFO("HCI BCSP protocol initialized"); 771 737 else
-71
drivers/bluetooth/hci_bcsp.h
··· 1 - /* 2 - BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ). 3 - Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com> 4 - 5 - Based on 6 - hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com> 7 - ABCSP by Carl Orsborn <cjo@csr.com> 8 - 9 - This program is free software; you can redistribute it and/or modify 10 - it under the terms of the GNU General Public License version 2 as 11 - published by the Free Software Foundation; 12 - 13 - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 16 - IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 17 - CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 18 - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 - 22 - ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 23 - COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 24 - SOFTWARE IS DISCLAIMED. 25 - */ 26 - 27 - /* 28 - * $Id: hci_bcsp.h,v 1.2 2002/09/26 05:05:14 maxk Exp $ 29 - */ 30 - 31 - #ifndef __HCI_BCSP_H__ 32 - #define __HCI_BCSP_H__ 33 - 34 - #define BCSP_TXWINSIZE 4 35 - 36 - #define BCSP_ACK_PKT 0x05 37 - #define BCSP_LE_PKT 0x06 38 - 39 - struct bcsp_struct { 40 - struct sk_buff_head unack; /* Unack'ed packets queue */ 41 - struct sk_buff_head rel; /* Reliable packets queue */ 42 - struct sk_buff_head unrel; /* Unreliable packets queue */ 43 - 44 - unsigned long rx_count; 45 - struct sk_buff *rx_skb; 46 - u8 rxseq_txack; /* rxseq == txack. */ 47 - u8 rxack; /* Last packet sent by us that the peer ack'ed */ 48 - struct timer_list tbcsp; 49 - 50 - enum { 51 - BCSP_W4_PKT_DELIMITER, 52 - BCSP_W4_PKT_START, 53 - BCSP_W4_BCSP_HDR, 54 - BCSP_W4_DATA, 55 - BCSP_W4_CRC 56 - } rx_state; 57 - 58 - enum { 59 - BCSP_ESCSTATE_NOESC, 60 - BCSP_ESCSTATE_ESC 61 - } rx_esc_state; 62 - 63 - u8 use_crc; 64 - u16 message_crc; 65 - u8 txack_req; /* Do we need to send ack's to the peer? */ 66 - 67 - /* Reliable packet sequence number - used to assign seq to each rel pkt. */ 68 - u8 msgq_txseq; 69 - }; 70 - 71 - #endif /* __HCI_BCSP_H__ */
+62 -39
drivers/bluetooth/hci_h4.c
··· 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(H4) protocol. 27 2 * 28 - * $Id: hci_h4.c,v 1.3 2002/09/09 01:17:32 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 "1.2" 31 25 32 26 #include <linux/config.h> 33 27 #include <linux/module.h> ··· 45 51 46 52 #include <net/bluetooth/bluetooth.h> 47 53 #include <net/bluetooth/hci_core.h> 54 + 48 55 #include "hci_uart.h" 49 - #include "hci_h4.h" 50 56 51 57 #ifndef CONFIG_BT_HCIUART_DEBUG 52 58 #undef BT_DBG 53 59 #define BT_DBG( A... ) 54 60 #endif 55 61 62 + #define VERSION "1.2" 63 + 64 + struct h4_struct { 65 + unsigned long rx_state; 66 + unsigned long rx_count; 67 + struct sk_buff *rx_skb; 68 + struct sk_buff_head txq; 69 + }; 70 + 71 + /* H4 receiver States */ 72 + #define H4_W4_PACKET_TYPE 0 73 + #define H4_W4_EVENT_HDR 1 74 + #define H4_W4_ACL_HDR 2 75 + #define H4_W4_SCO_HDR 3 76 + #define H4_W4_DATA 4 77 + 56 78 /* Initialize protocol */ 57 79 static int h4_open(struct hci_uart *hu) 58 80 { 59 81 struct h4_struct *h4; 60 - 82 + 61 83 BT_DBG("hu %p", hu); 62 - 84 + 63 85 h4 = kmalloc(sizeof(*h4), GFP_ATOMIC); 64 86 if (!h4) 65 87 return -ENOMEM; 88 + 66 89 memset(h4, 0, sizeof(*h4)); 67 90 68 91 skb_queue_head_init(&h4->txq); ··· 94 83 struct h4_struct *h4 = hu->priv; 95 84 96 85 BT_DBG("hu %p", hu); 86 + 97 87 skb_queue_purge(&h4->txq); 88 + 98 89 return 0; 99 90 } 100 91 ··· 104 91 static int h4_close(struct hci_uart *hu) 105 92 { 106 93 struct h4_struct *h4 = hu->priv; 94 + 107 95 hu->priv = NULL; 108 96 109 97 BT_DBG("hu %p", hu); 110 98 111 99 skb_queue_purge(&h4->txq); 100 + 112 101 if (h4->rx_skb) 113 102 kfree_skb(h4->rx_skb); 114 103 115 104 hu->priv = NULL; 116 105 kfree(h4); 106 + 117 107 return 0; 118 108 } 119 109 ··· 130 114 /* Prepend skb with frame type */ 131 115 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 132 116 skb_queue_tail(&h4->txq, skb); 117 + 133 118 return 0; 134 119 } 135 120 ··· 139 122 register int room = skb_tailroom(h4->rx_skb); 140 123 141 124 BT_DBG("len %d room %d", len, room); 125 + 142 126 if (!len) { 143 127 hci_recv_frame(h4->rx_skb); 144 128 } else if (len > room) { ··· 154 136 h4->rx_state = H4_W4_PACKET_TYPE; 155 137 h4->rx_skb = NULL; 156 138 h4->rx_count = 0; 139 + 157 140 return 0; 158 141 } 159 142 ··· 247 228 ptr++; count--; 248 229 continue; 249 230 }; 231 + 250 232 ptr++; count--; 251 233 252 234 /* Allocate packet */ ··· 258 238 h4->rx_count = 0; 259 239 return 0; 260 240 } 241 + 261 242 h4->rx_skb->dev = (void *) hu->hdev; 262 243 bt_cb(h4->rx_skb)->pkt_type = type; 263 244 } 245 + 264 246 return count; 265 247 } 266 248 ··· 273 251 } 274 252 275 253 static struct hci_uart_proto h4p = { 276 - .id = HCI_UART_H4, 277 - .open = h4_open, 278 - .close = h4_close, 279 - .recv = h4_recv, 280 - .enqueue = h4_enqueue, 281 - .dequeue = h4_dequeue, 282 - .flush = h4_flush, 254 + .id = HCI_UART_H4, 255 + .open = h4_open, 256 + .close = h4_close, 257 + .recv = h4_recv, 258 + .enqueue = h4_enqueue, 259 + .dequeue = h4_dequeue, 260 + .flush = h4_flush, 283 261 }; 284 - 262 + 285 263 int h4_init(void) 286 264 { 287 265 int err = hci_uart_register_proto(&h4p); 266 + 288 267 if (!err) 289 268 BT_INFO("HCI H4 protocol initialized"); 290 269 else 291 270 BT_ERR("HCI H4 protocol registration failed"); 292 - 271 + 293 272 return err; 294 273 } 295 274
-44
drivers/bluetooth/hci_h4.h
··· 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 - /* 26 - * $Id: hci_h4.h,v 1.2 2002/09/09 01:17:32 maxk Exp $ 27 - */ 28 - 29 - #ifdef __KERNEL__ 30 - struct h4_struct { 31 - unsigned long rx_state; 32 - unsigned long rx_count; 33 - struct sk_buff *rx_skb; 34 - struct sk_buff_head txq; 35 - }; 36 - 37 - /* H4 receiver States */ 38 - #define H4_W4_PACKET_TYPE 0 39 - #define H4_W4_EVENT_HDR 1 40 - #define H4_W4_ACL_HDR 2 41 - #define H4_W4_SCO_HDR 3 42 - #define H4_W4_DATA 4 43 - 44 - #endif /* __KERNEL__ */
+74 -70
drivers/bluetooth/hci_ldisc.c
··· 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.2" 31 25 32 26 #include <linux/config.h> 33 27 #include <linux/module.h> ··· 53 59 #define BT_DBG( A... ) 54 60 #endif 55 61 62 + #define VERSION "2.2" 63 + 56 64 static int reset = 0; 57 65 58 66 static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; ··· 68 72 return -EEXIST; 69 73 70 74 hup[p->id] = p; 75 + 71 76 return 0; 72 77 } 73 78 ··· 81 84 return -EINVAL; 82 85 83 86 hup[p->id] = NULL; 87 + 84 88 return 0; 85 89 } 86 90 ··· 89 91 { 90 92 if (id >= HCI_UART_MAX_PROTO) 91 93 return NULL; 94 + 92 95 return hup[id]; 93 96 } 94 97 95 98 static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) 96 99 { 97 100 struct hci_dev *hdev = hu->hdev; 98 - 101 + 99 102 /* Update HCI stat counters */ 100 103 switch (pkt_type) { 101 104 case HCI_COMMAND_PKT: ··· 116 117 static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) 117 118 { 118 119 struct sk_buff *skb = hu->tx_skb; 120 + 119 121 if (!skb) 120 122 skb = hu->proto->dequeue(hu); 121 123 else 122 124 hu->tx_skb = NULL; 125 + 123 126 return skb; 124 127 } 125 128 ··· 130 129 struct tty_struct *tty = hu->tty; 131 130 struct hci_dev *hdev = hu->hdev; 132 131 struct sk_buff *skb; 133 - 132 + 134 133 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { 135 134 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); 136 135 return 0; ··· 143 142 144 143 while ((skb = hci_uart_dequeue(hu))) { 145 144 int len; 146 - 145 + 147 146 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 148 147 len = tty->driver->write(tty, skb->data, skb->len); 149 148 hdev->stat.byte_tx += len; ··· 153 152 hu->tx_skb = skb; 154 153 break; 155 154 } 156 - 155 + 157 156 hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type); 158 157 kfree_skb(skb); 159 - } 160 - 158 + } 159 + 161 160 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) 162 161 goto restart; 163 162 ··· 174 173 /* Nothing to do for UART driver */ 175 174 176 175 set_bit(HCI_RUNNING, &hdev->flags); 176 + 177 177 return 0; 178 178 } 179 179 ··· 236 234 hu->proto->enqueue(hu, skb); 237 235 238 236 hci_uart_tx_wakeup(hu); 237 + 239 238 return 0; 240 239 } 241 240 ··· 244 241 { 245 242 struct hci_uart *hu; 246 243 247 - if (!hdev) return; 244 + if (!hdev) 245 + return; 248 246 249 247 BT_DBG("%s", hdev->name); 250 248 ··· 276 272 BT_ERR("Can't allocate controll structure"); 277 273 return -ENFILE; 278 274 } 275 + 279 276 memset(hu, 0, sizeof(struct hci_uart)); 280 277 281 278 tty->disc_data = hu; ··· 285 280 spin_lock_init(&hu->rx_lock); 286 281 287 282 /* Flush any pending characters in the driver and line discipline. */ 283 + 288 284 /* FIXME: why is this needed. Note don't use ldisc_ref here as the 289 285 open path is before the ldisc is referencable */ 286 + 290 287 if (tty->ldisc.flush_buffer) 291 288 tty->ldisc.flush_buffer(tty); 292 289 ··· 379 372 static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) 380 373 { 381 374 struct hci_uart *hu = (void *)tty->disc_data; 382 - 375 + 383 376 if (!hu || tty != hu->tty) 384 377 return; 385 378 386 379 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) 387 380 return; 388 - 381 + 389 382 spin_lock(&hu->rx_lock); 390 383 hu->proto->recv(hu, (void *) data, count); 391 384 hu->hdev->stat.byte_rx += count; ··· 436 429 static int hci_uart_set_proto(struct hci_uart *hu, int id) 437 430 { 438 431 struct hci_uart_proto *p; 439 - int err; 440 - 432 + int err; 433 + 441 434 p = hci_uart_get_proto(id); 442 435 if (!p) 443 436 return -EPROTONOSUPPORT; ··· 453 446 p->close(hu); 454 447 return err; 455 448 } 449 + 456 450 return 0; 457 451 } 458 452 ··· 471 463 * Return Value: Command dependent 472 464 */ 473 465 static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, 474 - unsigned int cmd, unsigned long arg) 466 + unsigned int cmd, unsigned long arg) 475 467 { 476 468 struct hci_uart *hu = (void *)tty->disc_data; 477 469 int err = 0; ··· 491 483 return err; 492 484 } 493 485 tty->low_latency = 1; 494 - } else 486 + } else 495 487 return -EBUSY; 496 488 497 489 case HCIUARTGETPROTO: 498 490 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 499 491 return hu->proto->id; 500 492 return -EUNATCH; 501 - 493 + 502 494 default: 503 495 err = n_tty_ioctl(tty, file, cmd, arg); 504 496 break; ··· 510 502 /* 511 503 * We don't provide read/write/poll interface for user space. 512 504 */ 513 - static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, unsigned char __user *buf, size_t nr) 514 - { 515 - return 0; 516 - } 517 - static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) 518 - { 519 - return 0; 520 - } 521 - static unsigned int hci_uart_tty_poll(struct tty_struct *tty, struct file *filp, poll_table *wait) 505 + static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, 506 + unsigned char __user *buf, size_t nr) 522 507 { 523 508 return 0; 524 509 } 525 510 526 - #ifdef CONFIG_BT_HCIUART_H4 527 - int h4_init(void); 528 - int h4_deinit(void); 529 - #endif 530 - #ifdef CONFIG_BT_HCIUART_BCSP 531 - int bcsp_init(void); 532 - int bcsp_deinit(void); 533 - #endif 511 + static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, 512 + const unsigned char *data, size_t count) 513 + { 514 + return 0; 515 + } 516 + 517 + static unsigned int hci_uart_tty_poll(struct tty_struct *tty, 518 + struct file *filp, poll_table *wait) 519 + { 520 + return 0; 521 + } 534 522 535 523 static int __init hci_uart_init(void) 536 524 { ··· 538 534 /* Register the tty discipline */ 539 535 540 536 memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc)); 541 - hci_uart_ldisc.magic = TTY_LDISC_MAGIC; 542 - hci_uart_ldisc.name = "n_hci"; 543 - hci_uart_ldisc.open = hci_uart_tty_open; 544 - hci_uart_ldisc.close = hci_uart_tty_close; 545 - hci_uart_ldisc.read = hci_uart_tty_read; 546 - hci_uart_ldisc.write = hci_uart_tty_write; 547 - hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; 548 - hci_uart_ldisc.poll = hci_uart_tty_poll; 549 - hci_uart_ldisc.receive_room= hci_uart_tty_room; 550 - hci_uart_ldisc.receive_buf = hci_uart_tty_receive; 551 - hci_uart_ldisc.write_wakeup= hci_uart_tty_wakeup; 552 - hci_uart_ldisc.owner = THIS_MODULE; 537 + hci_uart_ldisc.magic = TTY_LDISC_MAGIC; 538 + hci_uart_ldisc.name = "n_hci"; 539 + hci_uart_ldisc.open = hci_uart_tty_open; 540 + hci_uart_ldisc.close = hci_uart_tty_close; 541 + hci_uart_ldisc.read = hci_uart_tty_read; 542 + hci_uart_ldisc.write = hci_uart_tty_write; 543 + hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; 544 + hci_uart_ldisc.poll = hci_uart_tty_poll; 545 + hci_uart_ldisc.receive_room = hci_uart_tty_room; 546 + hci_uart_ldisc.receive_buf = hci_uart_tty_receive; 547 + hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup; 548 + hci_uart_ldisc.owner = THIS_MODULE; 553 549 554 550 if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { 555 551 BT_ERR("HCI line discipline registration failed. (%d)", err);
+44 -40
drivers/bluetooth/hci_uart.h
··· 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 - * $Id: hci_uart.h,v 1.2 2002/09/09 01:17:32 maxk Exp $ 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 + * 27 24 */ 28 25 29 - #ifndef N_HCI 26 + #ifndef N_HCI 30 27 #define N_HCI 15 31 28 #endif 32 29 ··· 39 42 #define HCI_UART_3WIRE 2 40 43 #define HCI_UART_H4DS 3 41 44 42 - #ifdef __KERNEL__ 43 45 struct hci_uart; 44 46 45 47 struct hci_uart_proto { ··· 52 56 }; 53 57 54 58 struct hci_uart { 55 - struct tty_struct *tty; 56 - struct hci_dev *hdev; 57 - unsigned long flags; 59 + struct tty_struct *tty; 60 + struct hci_dev *hdev; 61 + unsigned long flags; 58 62 59 - struct hci_uart_proto *proto; 60 - void *priv; 61 - 62 - struct sk_buff *tx_skb; 63 - unsigned long tx_state; 64 - spinlock_t rx_lock; 63 + struct hci_uart_proto *proto; 64 + void *priv; 65 + 66 + struct sk_buff *tx_skb; 67 + unsigned long tx_state; 68 + spinlock_t rx_lock; 65 69 }; 66 70 67 71 /* HCI_UART flag bits */ 68 - #define HCI_UART_PROTO_SET 0 72 + #define HCI_UART_PROTO_SET 0 69 73 70 74 /* TX states */ 71 - #define HCI_UART_SENDING 1 72 - #define HCI_UART_TX_WAKEUP 2 75 + #define HCI_UART_SENDING 1 76 + #define HCI_UART_TX_WAKEUP 2 73 77 74 78 int hci_uart_register_proto(struct hci_uart_proto *p); 75 79 int hci_uart_unregister_proto(struct hci_uart_proto *p); 76 80 int hci_uart_tx_wakeup(struct hci_uart *hu); 77 81 78 - #endif /* __KERNEL__ */ 82 + #ifdef CONFIG_BT_HCIUART_H4 83 + int h4_init(void); 84 + int h4_deinit(void); 85 + #endif 86 + 87 + #ifdef CONFIG_BT_HCIUART_BCSP 88 + int bcsp_init(void); 89 + int bcsp_deinit(void); 90 + #endif