Commit 0372a662 authored by Marcel Holtmann's avatar Marcel Holtmann

[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: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 20dd6f59
/* /*
BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ). *
Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com> * Bluetooth HCI UART driver
*
Based on * Copyright (C) 2002-2003 Fabrizio Gennari <fabrizio.gennari@philips.com>
hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com> * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
ABCSP by Carl Orsborn <cjo@csr.com> *
*
This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License as published by
published by the Free Software Foundation; * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * This program is distributed in the hope that it will be useful,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. * but WITHOUT ANY WARRANTY; without even the implied warranty of
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES * GNU General Public License for more details.
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * You should have received a copy of the GNU General Public License
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, *
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
/*
* $Id: hci_bcsp.c,v 1.2 2002/09/26 05:05:14 maxk Exp $
*/ */
#define VERSION "0.3"
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -52,17 +44,56 @@ ...@@ -52,17 +44,56 @@
#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h> #include <net/bluetooth/hci_core.h>
#include "hci_uart.h" #include "hci_uart.h"
#include "hci_bcsp.h"
#ifndef CONFIG_BT_HCIUART_DEBUG #ifndef CONFIG_BT_HCIUART_DEBUG
#undef BT_DBG #undef BT_DBG
#define BT_DBG( A... ) #define BT_DBG( A... )
#endif #endif
#define VERSION "0.3"
static int txcrc = 1; static int txcrc = 1;
static int hciextn = 1; static int hciextn = 1;
#define BCSP_TXWINSIZE 4
#define BCSP_ACK_PKT 0x05
#define BCSP_LE_PKT 0x06
struct bcsp_struct {
struct sk_buff_head unack; /* Unack'ed packets queue */
struct sk_buff_head rel; /* Reliable packets queue */
struct sk_buff_head unrel; /* Unreliable packets queue */
unsigned long rx_count;
struct sk_buff *rx_skb;
u8 rxseq_txack; /* rxseq == txack. */
u8 rxack; /* Last packet sent by us that the peer ack'ed */
struct timer_list tbcsp;
enum {
BCSP_W4_PKT_DELIMITER,
BCSP_W4_PKT_START,
BCSP_W4_BCSP_HDR,
BCSP_W4_DATA,
BCSP_W4_CRC
} rx_state;
enum {
BCSP_ESCSTATE_NOESC,
BCSP_ESCSTATE_ESC
} rx_esc_state;
u8 use_crc;
u16 message_crc;
u8 txack_req; /* Do we need to send ack's to the peer? */
/* Reliable packet sequence number - used to assign seq to each rel pkt. */
u8 msgq_txseq;
};
/* ---- BCSP CRC calculation ---- */ /* ---- BCSP CRC calculation ---- */
/* Table for calculating CRC for polynomial 0x1021, LSB processed first, /* Table for calculating CRC for polynomial 0x1021, LSB processed first,
...@@ -112,6 +143,7 @@ static u16 bcsp_crc_reverse(u16 crc) ...@@ -112,6 +143,7 @@ static u16 bcsp_crc_reverse(u16 crc)
rev |= (crc & 1); rev |= (crc & 1);
crc = crc >> 1; crc = crc >> 1;
} }
return (rev); return (rev);
} }
...@@ -120,6 +152,7 @@ static u16 bcsp_crc_reverse(u16 crc) ...@@ -120,6 +152,7 @@ static u16 bcsp_crc_reverse(u16 crc)
static void bcsp_slip_msgdelim(struct sk_buff *skb) static void bcsp_slip_msgdelim(struct sk_buff *skb)
{ {
const char pkt_delim = 0xc0; const char pkt_delim = 0xc0;
memcpy(skb_put(skb, 1), &pkt_delim, 1); memcpy(skb_put(skb, 1), &pkt_delim, 1);
} }
...@@ -315,7 +348,6 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu) ...@@ -315,7 +348,6 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
spin_unlock_irqrestore(&bcsp->unack.lock, flags); spin_unlock_irqrestore(&bcsp->unack.lock, flags);
/* We could not send a reliable packet, either because there are /* We could not send a reliable packet, either because there are
none or because there are too many unack'ed pkts. Did we receive none or because there are too many unack'ed pkts. Did we receive
any packets we have not acknowledged yet ? */ any packets we have not acknowledged yet ? */
...@@ -372,8 +404,10 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp) ...@@ -372,8 +404,10 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
kfree_skb(skb); kfree_skb(skb);
skb = nskb; skb = nskb;
} }
if (bcsp->unack.qlen == 0) if (bcsp->unack.qlen == 0)
del_timer(&bcsp->tbcsp); del_timer(&bcsp->tbcsp);
spin_unlock_irqrestore(&bcsp->unack.lock, flags); spin_unlock_irqrestore(&bcsp->unack.lock, flags);
if (i != pkts_to_be_removed) if (i != pkts_to_be_removed)
...@@ -528,6 +562,7 @@ static inline void bcsp_complete_rx_pkt(struct hci_uart *hu) ...@@ -528,6 +562,7 @@ static inline void bcsp_complete_rx_pkt(struct hci_uart *hu)
hci_recv_frame(bcsp->rx_skb); hci_recv_frame(bcsp->rx_skb);
} }
bcsp->rx_state = BCSP_W4_PKT_DELIMITER; bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
bcsp->rx_skb = NULL; bcsp->rx_skb = NULL;
} }
...@@ -731,6 +766,7 @@ static struct hci_uart_proto bcsp = { ...@@ -731,6 +766,7 @@ static struct hci_uart_proto bcsp = {
int bcsp_init(void) int bcsp_init(void)
{ {
int err = hci_uart_register_proto(&bcsp); int err = hci_uart_register_proto(&bcsp);
if (!err) if (!err)
BT_INFO("HCI BCSP protocol initialized"); BT_INFO("HCI BCSP protocol initialized");
else else
......
/*
BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ).
Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com>
Based on
hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com>
ABCSP by Carl Orsborn <cjo@csr.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
/*
* $Id: hci_bcsp.h,v 1.2 2002/09/26 05:05:14 maxk Exp $
*/
#ifndef __HCI_BCSP_H__
#define __HCI_BCSP_H__
#define BCSP_TXWINSIZE 4
#define BCSP_ACK_PKT 0x05
#define BCSP_LE_PKT 0x06
struct bcsp_struct {
struct sk_buff_head unack; /* Unack'ed packets queue */
struct sk_buff_head rel; /* Reliable packets queue */
struct sk_buff_head unrel; /* Unreliable packets queue */
unsigned long rx_count;
struct sk_buff *rx_skb;
u8 rxseq_txack; /* rxseq == txack. */
u8 rxack; /* Last packet sent by us that the peer ack'ed */
struct timer_list tbcsp;
enum {
BCSP_W4_PKT_DELIMITER,
BCSP_W4_PKT_START,
BCSP_W4_BCSP_HDR,
BCSP_W4_DATA,
BCSP_W4_CRC
} rx_state;
enum {
BCSP_ESCSTATE_NOESC,
BCSP_ESCSTATE_ESC
} rx_esc_state;
u8 use_crc;
u16 message_crc;
u8 txack_req; /* Do we need to send ack's to the peer? */
/* Reliable packet sequence number - used to assign seq to each rel pkt. */
u8 msgq_txseq;
};
#endif /* __HCI_BCSP_H__ */
/* /*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2000-2001 Qualcomm Incorporated
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
/*
* Bluetooth HCI UART(H4) protocol.
* *
* $Id: hci_h4.c,v 1.3 2002/09/09 01:17:32 maxk Exp $ * Bluetooth HCI UART driver
*
* Copyright (C) 2000-2001 Qualcomm Incorporated
* Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
* Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/ */
#define VERSION "1.2"
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -51,14 +45,30 @@ ...@@ -51,14 +45,30 @@
#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h> #include <net/bluetooth/hci_core.h>
#include "hci_uart.h" #include "hci_uart.h"
#include "hci_h4.h"
#ifndef CONFIG_BT_HCIUART_DEBUG #ifndef CONFIG_BT_HCIUART_DEBUG
#undef BT_DBG #undef BT_DBG
#define BT_DBG( A... ) #define BT_DBG( A... )
#endif #endif
#define VERSION "1.2"
struct h4_struct {
unsigned long rx_state;
unsigned long rx_count;
struct sk_buff *rx_skb;
struct sk_buff_head txq;
};
/* H4 receiver States */
#define H4_W4_PACKET_TYPE 0
#define H4_W4_EVENT_HDR 1
#define H4_W4_ACL_HDR 2
#define H4_W4_SCO_HDR 3
#define H4_W4_DATA 4
/* Initialize protocol */ /* Initialize protocol */
static int h4_open(struct hci_uart *hu) static int h4_open(struct hci_uart *hu)
{ {
...@@ -69,6 +79,7 @@ static int h4_open(struct hci_uart *hu) ...@@ -69,6 +79,7 @@ static int h4_open(struct hci_uart *hu)
h4 = kmalloc(sizeof(*h4), GFP_ATOMIC); h4 = kmalloc(sizeof(*h4), GFP_ATOMIC);
if (!h4) if (!h4)
return -ENOMEM; return -ENOMEM;
memset(h4, 0, sizeof(*h4)); memset(h4, 0, sizeof(*h4));
skb_queue_head_init(&h4->txq); skb_queue_head_init(&h4->txq);
...@@ -83,7 +94,9 @@ static int h4_flush(struct hci_uart *hu) ...@@ -83,7 +94,9 @@ static int h4_flush(struct hci_uart *hu)
struct h4_struct *h4 = hu->priv; struct h4_struct *h4 = hu->priv;
BT_DBG("hu %p", hu); BT_DBG("hu %p", hu);
skb_queue_purge(&h4->txq); skb_queue_purge(&h4->txq);
return 0; return 0;
} }
...@@ -91,16 +104,19 @@ static int h4_flush(struct hci_uart *hu) ...@@ -91,16 +104,19 @@ static int h4_flush(struct hci_uart *hu)
static int h4_close(struct hci_uart *hu) static int h4_close(struct hci_uart *hu)
{ {
struct h4_struct *h4 = hu->priv; struct h4_struct *h4 = hu->priv;
hu->priv = NULL; hu->priv = NULL;
BT_DBG("hu %p", hu); BT_DBG("hu %p", hu);
skb_queue_purge(&h4->txq); skb_queue_purge(&h4->txq);
if (h4->rx_skb) if (h4->rx_skb)
kfree_skb(h4->rx_skb); kfree_skb(h4->rx_skb);
hu->priv = NULL; hu->priv = NULL;
kfree(h4); kfree(h4);
return 0; return 0;
} }
...@@ -114,6 +130,7 @@ static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb) ...@@ -114,6 +130,7 @@ static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
/* Prepend skb with frame type */ /* Prepend skb with frame type */
memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
skb_queue_tail(&h4->txq, skb); skb_queue_tail(&h4->txq, skb);
return 0; return 0;
} }
...@@ -122,6 +139,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len) ...@@ -122,6 +139,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len)
register int room = skb_tailroom(h4->rx_skb); register int room = skb_tailroom(h4->rx_skb);
BT_DBG("len %d room %d", len, room); BT_DBG("len %d room %d", len, room);
if (!len) { if (!len) {
hci_recv_frame(h4->rx_skb); hci_recv_frame(h4->rx_skb);
} else if (len > room) { } else if (len > room) {
...@@ -136,6 +154,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len) ...@@ -136,6 +154,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len)
h4->rx_state = H4_W4_PACKET_TYPE; h4->rx_state = H4_W4_PACKET_TYPE;
h4->rx_skb = NULL; h4->rx_skb = NULL;
h4->rx_count = 0; h4->rx_count = 0;
return 0; return 0;
} }
...@@ -228,6 +247,7 @@ static int h4_recv(struct hci_uart *hu, void *data, int count) ...@@ -228,6 +247,7 @@ static int h4_recv(struct hci_uart *hu, void *data, int count)
ptr++; count--; ptr++; count--;
continue; continue;
}; };
ptr++; count--; ptr++; count--;
/* Allocate packet */ /* Allocate packet */
...@@ -238,9 +258,11 @@ static int h4_recv(struct hci_uart *hu, void *data, int count) ...@@ -238,9 +258,11 @@ static int h4_recv(struct hci_uart *hu, void *data, int count)
h4->rx_count = 0; h4->rx_count = 0;
return 0; return 0;
} }
h4->rx_skb->dev = (void *) hu->hdev; h4->rx_skb->dev = (void *) hu->hdev;
bt_cb(h4->rx_skb)->pkt_type = type; bt_cb(h4->rx_skb)->pkt_type = type;
} }
return count; return count;
} }
...@@ -263,6 +285,7 @@ static struct hci_uart_proto h4p = { ...@@ -263,6 +285,7 @@ static struct hci_uart_proto h4p = {
int h4_init(void) int h4_init(void)
{ {
int err = hci_uart_register_proto(&h4p); int err = hci_uart_register_proto(&h4p);
if (!err) if (!err)
BT_INFO("HCI H4 protocol initialized"); BT_INFO("HCI H4 protocol initialized");
else else
......
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2000-2001 Qualcomm Incorporated
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
/*
* $Id: hci_h4.h,v 1.2 2002/09/09 01:17:32 maxk Exp $
*/
#ifdef __KERNEL__
struct h4_struct {
unsigned long rx_state;
unsigned long rx_count;
struct sk_buff *rx_skb;
struct sk_buff_head txq;
};
/* H4 receiver States */
#define H4_W4_PACKET_TYPE 0
#define H4_W4_EVENT_HDR 1
#define H4_W4_ACL_HDR 2
#define H4_W4_SCO_HDR 3
#define H4_W4_DATA 4
#endif /* __KERNEL__ */
/* /*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2000-2001 Qualcomm Incorporated
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
/*
* Bluetooth HCI UART driver.
* *
* $Id: hci_ldisc.c,v 1.5 2002/10/02 18:37:20 maxk Exp $ * Bluetooth HCI UART driver
*
* Copyright (C) 2000-2001 Qualcomm Incorporated
* Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
* Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/ */
#define VERSION "2.2"
#include <linux/config.h> #include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -59,6 +53,8 @@ ...@@ -59,6 +53,8 @@
#define BT_DBG( A... ) #define BT_DBG( A... )
#endif #endif
#define VERSION "2.2"
static int reset = 0; static int reset = 0;
static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; 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,6 +68,7 @@ int hci_uart_register_proto(struct hci_uart_proto *p)
return -EEXIST; return -EEXIST;
hup[p->id] = p; hup[p->id] = p;
return 0; return 0;
} }
...@@ -84,6 +81,7 @@ int hci_uart_unregister_proto(struct hci_uart_proto *p) ...@@ -84,6 +81,7 @@ int hci_uart_unregister_proto(struct hci_uart_proto *p)
return -EINVAL; return -EINVAL;
hup[p->id] = NULL; hup[p->id] = NULL;
return 0; return 0;
} }
...@@ -91,6 +89,7 @@ static struct hci_uart_proto *hci_uart_get_proto(unsigned int id) ...@@ -91,6 +89,7 @@ static struct hci_uart_proto *hci_uart_get_proto(unsigned int id)
{ {
if (id >= HCI_UART_MAX_PROTO) if (id >= HCI_UART_MAX_PROTO)
return NULL; return NULL;
return hup[id]; return hup[id];
} }
...@@ -117,10 +116,12 @@ static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) ...@@ -117,10 +116,12 @@ static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu)
{ {
struct sk_buff *skb = hu->tx_skb; struct sk_buff *skb = hu->tx_skb;
if (!skb) if (!skb)
skb = hu->proto->dequeue(hu); skb = hu->proto->dequeue(hu);
else else
hu->tx_skb = NULL; hu->tx_skb = NULL;
return skb; return skb;
} }
...@@ -173,6 +174,7 @@ static int hci_uart_open(struct hci_dev *hdev) ...@@ -173,6 +174,7 @@ static int hci_uart_open(struct hci_dev *hdev)
/* Nothing to do for UART driver */ /* Nothing to do for UART driver */
set_bit(HCI_RUNNING, &hdev->flags); set_bit(HCI_RUNNING, &hdev->flags);
return 0; return 0;
} }
...@@ -234,6 +236,7 @@ static int hci_uart_send_frame(struct sk_buff *skb) ...@@ -234,6 +236,7 @@ static int hci_uart_send_frame(struct sk_buff *skb)
hu->proto->enqueue(hu, skb); hu->proto->enqueue(hu, skb);
hci_uart_tx_wakeup(hu); hci_uart_tx_wakeup(hu);
return 0; return 0;
} }
...@@ -241,7 +244,8 @@ static void hci_uart_destruct(struct hci_dev *hdev) ...@@ -241,7 +244,8 @@ static void hci_uart_destruct(struct hci_dev *hdev)
{ {
struct hci_uart *hu; struct hci_uart *hu;
if (!hdev) return; if (!hdev)
return;
BT_DBG("%s", hdev->name); BT_DBG("%s", hdev->name);
...@@ -272,6 +276,7 @@ static int hci_uart_tty_open(struct tty_struct *tty) ...@@ -272,6 +276,7 @@ static int hci_uart_tty_open(struct tty_struct *tty)
BT_ERR("Can't allocate controll structure"); BT_ERR("Can't allocate controll structure");
return -ENFILE; return -ENFILE;
} }
memset(hu, 0, sizeof(struct hci_uart)); memset(hu, 0, sizeof(struct hci_uart));
tty->disc_data = hu; tty->disc_data = hu;
...@@ -280,8 +285,10 @@ static int hci_uart_tty_open(struct tty_struct *tty) ...@@ -280,8 +285,10 @@ static int hci_uart_tty_open(struct tty_struct *tty)
spin_lock_init(&hu->rx_lock); spin_lock_init(&hu->rx_lock);
/* Flush any pending characters in the driver and line discipline. */ /* Flush any pending characters in the driver and line discipline. */
/* FIXME: why is this needed. Note don't use ldisc_ref here as the /* FIXME: why is this needed. Note don't use ldisc_ref here as the
open path is before the ldisc is referencable */ open path is before the ldisc is referencable */
if (tty->ldisc.flush_buffer) if (tty->ldisc.flush_buffer)
tty->ldisc.flush_buffer(tty); tty->ldisc.flush_buffer(tty);
...@@ -446,6 +453,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id) ...@@ -446,6 +453,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
p->close(hu); p->close(hu);
return err; return err;
} }
return 0; return 0;
} }
...@@ -502,28 +510,24 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, ...@@ -502,28 +510,24 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
/* /*
* We don't provide read/write/poll interface for user space. * We don't provide read/write/poll interface for user space.
*/ */
static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, unsigned char __user *buf, size_t nr) static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
unsigned char __user *buf, size_t nr)
{ {
return 0; return 0;
} }
static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count)
static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
const unsigned char *data, size_t count)
{ {
return 0; return 0;
} }
static unsigned int hci_uart_tty_poll(struct tty_struct *tty, struct file *filp, poll_table *wait)
static unsigned int hci_uart_tty_poll(struct tty_struct *tty,
struct file *filp, poll_table *wait)
{ {
return 0; return 0;
} }
#ifdef CONFIG_BT_HCIUART_H4
int h4_init(void);
int h4_deinit(void);
#endif
#ifdef CONFIG_BT_HCIUART_BCSP
int bcsp_init(void);
int bcsp_deinit(void);
#endif
static int __init hci_uart_init(void) static int __init hci_uart_init(void)
{ {
static struct tty_ldisc hci_uart_ldisc; static struct tty_ldisc hci_uart_ldisc;
...@@ -542,9 +546,9 @@ static int __init hci_uart_init(void) ...@@ -542,9 +546,9 @@ static int __init hci_uart_init(void)
hci_uart_ldisc.write = hci_uart_tty_write; hci_uart_ldisc.write = hci_uart_tty_write;
hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
hci_uart_ldisc.poll = hci_uart_tty_poll; hci_uart_ldisc.poll = hci_uart_tty_poll;
hci_uart_ldisc.receive_room= hci_uart_tty_room; hci_uart_ldisc.receive_room = hci_uart_tty_room;
hci_uart_ldisc.receive_buf = hci_uart_tty_receive; hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
hci_uart_ldisc.write_wakeup= hci_uart_tty_wakeup; hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
hci_uart_ldisc.owner = THIS_MODULE; hci_uart_ldisc.owner = THIS_MODULE;
if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
......
/* /*
BlueZ - Bluetooth protocol stack for Linux *
Copyright (C) 2000-2001 Qualcomm Incorporated * Bluetooth HCI UART driver
*
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> * Copyright (C) 2000-2001 Qualcomm Incorporated
* Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
it under the terms of the GNU General Public License version 2 as *
published by the Free Software Foundation; *
* This program is free software; you can redistribute it and/or modify
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * it under the terms of the GNU General Public License as published by
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * the Free Software Foundation; either version 2 of the License, or
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. * (at your option) any later version.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY *
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES * This program is distributed in the hope that it will be useful,
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * but WITHOUT ANY WARRANTY; without even the implied warranty of
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * GNU General Public License for more details.
*
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, * You should have received a copy of the GNU General Public License
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS * along with this program; if not, write to the Free Software
SOFTWARE IS DISCLAIMED. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ *
/*
* $Id: hci_uart.h,v 1.2 2002/09/09 01:17:32 maxk Exp $
*/ */
#ifndef N_HCI #ifndef N_HCI
...@@ -42,7 +39,6 @@ ...@@ -42,7 +39,6 @@
#define HCI_UART_3WIRE 2 #define HCI_UART_3WIRE 2
#define HCI_UART_H4DS 3 #define HCI_UART_H4DS 3
#ifdef __KERNEL__
struct hci_uart; struct hci_uart;
struct hci_uart_proto { struct hci_uart_proto {
...@@ -79,4 +75,12 @@ int hci_uart_register_proto(struct hci_uart_proto *p); ...@@ -79,4 +75,12 @@ int hci_uart_register_proto(struct hci_uart_proto *p);
int hci_uart_unregister_proto(struct hci_uart_proto *p); int hci_uart_unregister_proto(struct hci_uart_proto *p);
int hci_uart_tx_wakeup(struct hci_uart *hu); int hci_uart_tx_wakeup(struct hci_uart *hu);
#endif /* __KERNEL__ */ #ifdef CONFIG_BT_HCIUART_H4
int h4_init(void);
int h4_deinit(void);
#endif
#ifdef CONFIG_BT_HCIUART_BCSP
int bcsp_init(void);
int bcsp_deinit(void);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment