aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth/hci_bcsp.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-10-28 13:20:45 -0400
committerMarcel Holtmann <marcel@holtmann.org>2005-10-28 13:20:45 -0400
commit0372a6627f862f90a2c43772befeecef508cfd7b (patch)
tree8e2d141927ac8d63663d8c88a6a0eb7e096d8a8b /drivers/bluetooth/hci_bcsp.c
parent20dd6f59d6ea5fe47397c5254606c76b1d047727 (diff)
[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>
Diffstat (limited to 'drivers/bluetooth/hci_bcsp.c')
-rw-r--r--drivers/bluetooth/hci_bcsp.c120
1 files changed, 78 insertions, 42 deletions
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 91bd293d7a0a..0a4761415ac3 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -1,35 +1,27 @@
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 24
31#define VERSION "0.3"
32
33#include <linux/config.h> 25#include <linux/config.h>
34#include <linux/module.h> 26#include <linux/module.h>
35 27
@@ -52,17 +44,56 @@
52 44
53#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
54#include <net/bluetooth/hci_core.h> 46#include <net/bluetooth/hci_core.h>
47
55#include "hci_uart.h" 48#include "hci_uart.h"
56#include "hci_bcsp.h"
57 49
58#ifndef CONFIG_BT_HCIUART_DEBUG 50#ifndef CONFIG_BT_HCIUART_DEBUG
59#undef BT_DBG 51#undef BT_DBG
60#define BT_DBG( A... ) 52#define BT_DBG( A... )
61#endif 53#endif
62 54
55#define VERSION "0.3"
56
63static int txcrc = 1; 57static int txcrc = 1;
64static int hciextn = 1; 58static int hciextn = 1;
65 59
60#define BCSP_TXWINSIZE 4
61
62#define BCSP_ACK_PKT 0x05
63#define BCSP_LE_PKT 0x06
64
65struct bcsp_struct {
66 struct sk_buff_head unack; /* Unack'ed packets queue */
67 struct sk_buff_head rel; /* Reliable packets queue */
68 struct sk_buff_head unrel; /* Unreliable packets queue */
69
70 unsigned long rx_count;
71 struct sk_buff *rx_skb;
72 u8 rxseq_txack; /* rxseq == txack. */
73 u8 rxack; /* Last packet sent by us that the peer ack'ed */
74 struct timer_list tbcsp;
75
76 enum {
77 BCSP_W4_PKT_DELIMITER,
78 BCSP_W4_PKT_START,
79 BCSP_W4_BCSP_HDR,
80 BCSP_W4_DATA,
81 BCSP_W4_CRC
82 } rx_state;
83
84 enum {
85 BCSP_ESCSTATE_NOESC,
86 BCSP_ESCSTATE_ESC
87 } rx_esc_state;
88
89 u8 use_crc;
90 u16 message_crc;
91 u8 txack_req; /* Do we need to send ack's to the peer? */
92
93 /* Reliable packet sequence number - used to assign seq to each rel pkt. */
94 u8 msgq_txseq;
95};
96
66/* ---- BCSP CRC calculation ---- */ 97/* ---- BCSP CRC calculation ---- */
67 98
68/* Table for calculating CRC for polynomial 0x1021, LSB processed first, 99/* Table for calculating CRC for polynomial 0x1021, LSB processed first,
@@ -112,6 +143,7 @@ static u16 bcsp_crc_reverse(u16 crc)
112 rev |= (crc & 1); 143 rev |= (crc & 1);
113 crc = crc >> 1; 144 crc = crc >> 1;
114 } 145 }
146
115 return (rev); 147 return (rev);
116} 148}
117 149
@@ -120,6 +152,7 @@ static u16 bcsp_crc_reverse(u16 crc)
120static void bcsp_slip_msgdelim(struct sk_buff *skb) 152static void bcsp_slip_msgdelim(struct sk_buff *skb)
121{ 153{
122 const char pkt_delim = 0xc0; 154 const char pkt_delim = 0xc0;
155
123 memcpy(skb_put(skb, 1), &pkt_delim, 1); 156 memcpy(skb_put(skb, 1), &pkt_delim, 1);
124} 157}
125 158
@@ -315,7 +348,6 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
315 348
316 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 349 spin_unlock_irqrestore(&bcsp->unack.lock, flags);
317 350
318
319 /* We could not send a reliable packet, either because there are 351 /* We could not send a reliable packet, either because there are
320 none or because there are too many unack'ed pkts. Did we receive 352 none or because there are too many unack'ed pkts. Did we receive
321 any packets we have not acknowledged yet ? */ 353 any packets we have not acknowledged yet ? */
@@ -361,7 +393,7 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
361 BT_ERR("Peer acked invalid packet"); 393 BT_ERR("Peer acked invalid packet");
362 394
363 BT_DBG("Removing %u pkts out of %u, up to seqno %u", 395 BT_DBG("Removing %u pkts out of %u, up to seqno %u",
364 pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07); 396 pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07);
365 397
366 for (i = 0, skb = ((struct sk_buff *) &bcsp->unack)->next; i < pkts_to_be_removed 398 for (i = 0, skb = ((struct sk_buff *) &bcsp->unack)->next; i < pkts_to_be_removed
367 && skb != (struct sk_buff *) &bcsp->unack; i++) { 399 && skb != (struct sk_buff *) &bcsp->unack; i++) {
@@ -372,8 +404,10 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
372 kfree_skb(skb); 404 kfree_skb(skb);
373 skb = nskb; 405 skb = nskb;
374 } 406 }
407
375 if (bcsp->unack.qlen == 0) 408 if (bcsp->unack.qlen == 0)
376 del_timer(&bcsp->tbcsp); 409 del_timer(&bcsp->tbcsp);
410
377 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 411 spin_unlock_irqrestore(&bcsp->unack.lock, flags);
378 412
379 if (i != pkts_to_be_removed) 413 if (i != pkts_to_be_removed)
@@ -528,6 +562,7 @@ static inline void bcsp_complete_rx_pkt(struct hci_uart *hu)
528 562
529 hci_recv_frame(bcsp->rx_skb); 563 hci_recv_frame(bcsp->rx_skb);
530 } 564 }
565
531 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 566 bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
532 bcsp->rx_skb = NULL; 567 bcsp->rx_skb = NULL;
533} 568}
@@ -596,8 +631,8 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
596 631
597 BT_ERR ("Checksum failed: computed %04x received %04x", 632 BT_ERR ("Checksum failed: computed %04x received %04x",
598 bcsp_crc_reverse(bcsp->message_crc), 633 bcsp_crc_reverse(bcsp->message_crc),
599 (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) + 634 (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) +
600 bcsp->rx_skb->data[bcsp->rx_skb->len - 1]); 635 bcsp->rx_skb->data[bcsp->rx_skb->len - 1]);
601 636
602 kfree_skb(bcsp->rx_skb); 637 kfree_skb(bcsp->rx_skb);
603 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 638 bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
@@ -631,7 +666,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
631 bcsp->rx_count = 4; 666 bcsp->rx_count = 4;
632 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; 667 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
633 BCSP_CRC_INIT(bcsp->message_crc); 668 BCSP_CRC_INIT(bcsp->message_crc);
634 669
635 /* Do not increment ptr or decrement count 670 /* Do not increment ptr or decrement count
636 * Allocate packet. Max len of a BCSP pkt= 671 * Allocate packet. Max len of a BCSP pkt=
637 * 0xFFF (payload) +4 (header) +2 (crc) */ 672 * 0xFFF (payload) +4 (header) +2 (crc) */
@@ -719,18 +754,19 @@ static int bcsp_close(struct hci_uart *hu)
719} 754}
720 755
721static struct hci_uart_proto bcsp = { 756static struct hci_uart_proto bcsp = {
722 .id = HCI_UART_BCSP, 757 .id = HCI_UART_BCSP,
723 .open = bcsp_open, 758 .open = bcsp_open,
724 .close = bcsp_close, 759 .close = bcsp_close,
725 .enqueue = bcsp_enqueue, 760 .enqueue = bcsp_enqueue,
726 .dequeue = bcsp_dequeue, 761 .dequeue = bcsp_dequeue,
727 .recv = bcsp_recv, 762 .recv = bcsp_recv,
728 .flush = bcsp_flush 763 .flush = bcsp_flush
729}; 764};
730 765
731int bcsp_init(void) 766int bcsp_init(void)
732{ 767{
733 int err = hci_uart_register_proto(&bcsp); 768 int err = hci_uart_register_proto(&bcsp);
769
734 if (!err) 770 if (!err)
735 BT_INFO("HCI BCSP protocol initialized"); 771 BT_INFO("HCI BCSP protocol initialized");
736 else 772 else