📄 btusb.h
字号:
/* * Wipro Bluetooth HCI USB Transport Layer. * This file is part of the "Wipro Bluetooth USB Driver for Linux". * Copyright (C) 2001 Wipro Technologies. <www.wipro.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Please forward any queries regarding the driver to * Nitant Kulkarni - Nitant.Kulkarni@wipro.com * Kamal K N - kamala.kodi@wipro.com * Burgupalli Chaitanya - Chaitanya.Burgupalli@wipro.com * Sadashivan Manicham - Sadashivan.Manickam@wipro.com * */ /* * * NAME : btusb.h * * DESCRIPTION : This is the header file of Bluetooth USB transport layer * on Linux OS. It contains all the header file includes, * module specific data structures definitions, static data * declaration, type defines, constant defines, macros * definitions for filling of URBs global data structure * declarations and function prototypes of Bluetooth USB * class driver. * */#ifndef BTUSB_H#define BTUSB_H#if 0#define BTUSB_DEBUG /* Enable display of debug messages */#endif /* 0 */#include <linux/kernel.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/errno.h>#include <linux/poll.h>#include <linux/init.h>#include <linux/malloc.h>#include <linux/fcntl.h>#include <linux/fs.h>#include <linux/module.h>#include <linux/spinlock.h>#include "btusb_os_dep.h"#include "btusb_driver_dep.h"/* * The following #define prevents a device from being opened more * than once. */#define EXCLUSIVE_DEVICE_OPEN/* * The following #define transmits zero length packet by requesting an URB * of zero length. This is required when the length of data to be * transmitted is an exact multiple of the Bulk IN endpoints max packet * size. */#define TRANSMIT_ZERO_LENGTH_BULK_OUT/* * The following #define spawns multiple Bulk IN URBs *//* #define MULTIPLE_BULK_IN_URBS *//* * Description missing */#define NONATOMIC_KMEM_CACHE_GROW/* * Description missing *//* #define TEMPORARY_FIX_FOR_SLOW_DATA_RATE *//* Module specific defines */#define TRUE 1 /* bolean TRUE */#define FALSE 0 /* boolean FALSE */#define SUCCESS 0 /* Linux success code */#define ERROR -1 /* Linux error code */#define DEVICE_ALREADY_OPEN -2 /* * If the device is already open, any * attempt to open the device again is * rejected. */#define CONTINUE 0 /* Continue data reception from device */#define STOP -1 /* Stop data reception from device */#define FLOW_BLOCKED 0 /* No free URBs or error in submitting URB */#define NO_MEM -1 /* Out of memory. Cannot allocate transfer buffer */#define NO_DATA 0 /* Zero bytes returned */#define MAX_BT_PKT_SIZE 360 /* All read requests are to be of this size */#define MAX_WRITE_URBS 100 /* Size of write URB pool */#define MAX_ISO_OUT_URBS 8 /* Size of isochronous out URB pool */#define COMMAND_TYPE 0x01 /* HCI command packet */#define ACL_TYPE 0x02 /* HCI ACL data packet */#define SCO_TYPE 0x03 /* HCI SCO data packet */#define EVENT_TYPE 0x04 /* HCI Event packet */#define BT_MAJOR 216 /* Major number for BT USB class driver */#define WIRELESS_CLASS_CODE 0xE0 /* USB class-code for wireless device */#define RF_SUBCLASS_CODE 0x01 /* USB sub-class-code for RF devices */#define BT_PROGRAMMING_PROTOCOL_CODE 0x01 /* * USB programming protocol * code for Bluetooth device */#define BLUETOOTH_CONTROL_REQUEST_TYPE 0x20 /* * USB control request type * for Bluetooth commands */#define ISO_TYPE 0x00 /* Type code for USB isochronous pipe */#define INTERRUPT_TYPE 0x01 /* Type code for USB interrupt pipe */#define CONTROL_TYPE 0x02 /* Type code for USB control pipe */#define BULK_TYPE 0x03 /* Type code for USB bulk pipe */#define MAX_BTDEV 16 /* Maximum number of BT devices supported */#ifdef MULTIPLE_BULK_IN_URBS /* Modified by Sadashivan */#define MAX_PENDING_BULK_IN_URBS 3/* * MAX_PENDING_BULK_IN_URBS for bulk-in, * 1 for iso-in and * 1 for interrupt-in URB */#define MAX_PENDING_IN_URBS MAX_PENDING_BULK_IN_URBS + 1 + 1 #else /* MULTIPLE_BULK_IN_URBS */#define MAX_PENDING_IN_URBS 3 /* * 1 for bulk-in, * 1 for iso-in and * 1 for interrupt-in URB */#endif /* MULTIPLE_BULK_IN_URBS */#define DEFAULT_MAX_QUEUE_LENGTH 100 /* * 10 - For SCO, does not work for * RFCOMM *//* * MAX_PENDING_IN URB for nodes from actual pending URBs and * equal number for nodes from already completed URBs */#define ALTERNATE_SETTING 0 /* Default isochronous alternate setting *//* debug related defines - used to mention code block */#ifdef BTUSB_DEBUG#define DBG_INIT 1 /* Driver initialization routine */#define DBG_PROBE 2 /* Device probe routine */#define DBG_FILEOPS 3 /* File operation functions */#define DBG_CALLBACK 4 /* Callback routines */#define DBG_DISCONNECT 5 /* Device disconnection routine */#define DBG_EXIT 6 /* Driver exit routine */#define DBG_UNLINK_URB 7 /* Unlink URB routine. */#endif /* BTUSB_DEBUG *//* --- End of module specific defines --- *//* Type defines *//* Type defines of signed and unsigned integers of different sizes */typedef unsigned char uint8;typedef short int int16;typedef unsigned short uint16;typedef int int32;typedef unsigned int uint32;typedef unsigned char bool;/* Type define of a node structure */typedef struct NODE_T{ uint8 *buf; /* Pointer to chunk of data received */ uint16 length; /* Length of data chunk */ uint16 type; /* type of data */ struct NODE_T *nextNode; /* Pointer to next node in queue */} node_t __attribute__ ((packed));/* Type define of a queue structure */typedef struct QUEUE_T{ uint8 maxLength; /* Maximum number of nodes in queue */ uint8 currentLength; /* Current number of nodes in queue */ node_t *head; /* Pointer to head of queue */ node_t *tail; /* Pointer to tail of queue */} queue_t __attribute__ ((packed));/* * Type define of a structure to hold all the information of a * connected BT device */typedef struct BTUSB_T{ spinlock_t lock; /* lock to prevent concurrent operation on btusb_t struct */ uint minorNumber; /* Minor number associated with device */ bool devOpened; /* Flag to know if device has been opened */ struct file *devFile; /* Reference to device file struct */ struct usb_device *devDesc; /* Reference to device descriptor struct */ uint moduleIncCount; /* Count of number of times the device was probed */ queue_t recvQueue; /* Receive queue to hold incoming data */ uint8 bulk_in_EPAddress; /* bulk-in endpoint address */ uint8 bulk_in_EPMaxPktSize; /* bulk-in endpoint maximum packet size */ #ifdef MULTIPLE_BULK_IN_URBS urb_t *bulk_in_urb[MAX_PENDING_BULK_IN_URBS]; bool bulk_in_urb_submitted[MAX_PENDING_BULK_IN_URBS];#else /* MULTIPLE_BULK_IN_URBS */ urb_t *bulk_in_urb; /* Pointer to bulk-in URB */#endif /* MULTIPLE_BULK_IN_URBS */ bool bulk_in_urbSubmitted; /* Flag to know if bulk-in URB was submitted */ uint8 interrupt_in_EPAddress; /* interrupt-in endpoint address */ uint8 interrupt_in_EPMaxPktSize; /* interrupt-in endpoint maximum packet size */ uint8 interrupt_in_EPInterval; /* interrupt-in endpoint polling interval */ urb_t *interrupt_in_urb; /* Pointer to interrupt-in URB */ bool interrupt_in_urbSubmitted; /* Flag to know if int-in URB was submitted */ uint8 iso_in_EPAddress; /* isochronous-in endpoint address */ uint8 iso_in_EPMaxPktSize; /* isochronous-in endpoint maximum packet size */ urb_t *iso_in_urb; /* Pointer to isochronous-in URB */ bool iso_in_urbSubmitted; /* Flag to know if iso-in URB was submitted */ uint8 bulk_out_EPAddress; /* bulk-out endpoint address */ uint8 bulk_out_EPMaxPktSize; /* bulk-out endpoint maximum packet size */ /* The following flag was added by Sadashivan, 26 Jun, 2001 (begin) */#ifndef URB_QUEUEING_SUPPORT#ifdef TRANSMIT_ZERO_LENGTH_BULK_OUT /* * This flag specifies whether a zero length packet should be * transmitted or not. */ bool TransmitZeroLength_BulkOUT;#endif /* TRANSMIT_ZERO_LENGTH_BULK_OUT */#endif /* URB_QUEUEING_SUPPORT */ /* The following flag was added by Sadashivan, 26 Jun, 2001 (end) */ uint8 control_out_EPAddress; /* interrupt-out endpoint address */ uint8 control_out_EPMaxPktSize; /* int-out endpoint maximum packet size */ uint8 iso_out_EPAddress; /* isochronous-out endpoint address */ uint8 iso_out_EPMaxPktSize; /* iso-out endpoint maximum packet size */ /* URB pool for bulk and control OUT requests. */ urb_t *write_urb_pool[MAX_WRITE_URBS]; /* URB pool for isochronous OUT requests. */ urb_t *iso_out_urb_pool[MAX_ISO_OUT_URBS];#ifdef MULTIPLE_BULK_IN_URBS int pending_bulk_in_urbs; /* To hold the number of pending URBs */#endif /* MULTIPLE_BULK_IN_URBS */ int pending_isoOutURBs; /* Number of ISO-OUT URBs pending */ int pending_outPoolURBs; /* Number of other OUT URBs pending */ int pending_inURBs; /* Number of IN URBs pending */ uint8 InterruptInBuffer[MAX_BT_PKT_SIZE]; uint16 InterruptInDataLength;} btusb_t __attribute__ ((packed));/* --- End of type defines --- *//* Local functions prototype */intbtusb_init(void);voidbtusb_exit(void);#ifdef LINUX_2_4static void*btusb_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id);#else /* for Linux 2.2 kernel */static void*btusb_probe(struct usb_device *dev, unsigned int ifnum);#endif /* LINUX_2_4 */static voidbtusb_disconnect(struct usb_device *dev, void *ptr);static intbtusb_open(struct inode *inode_p, struct file *file_p);static intbtusb_close(struct inode *inode_p, struct file *file_p);static ssize_tbtusb_read(struct file *file_p, char *buf_p, size_t count, loff_t *pos_p);static ssize_tbtusb_write(struct file *file_p, const char *buf_p, size_t count, loff_t *pos_p);static intbtusb_ioctl(struct inode *inode_p, struct file *file_p, unsigned int cmd, unsigned long arg);static voidbtusb_read_callback(urb_t *bturb_p);static voidbtusb_write_callback(urb_t *bturb_p);static intbtusb_addToQueue(queue_t *recv_queue_p, node_t *nodeToAdd);static node_t*btusb_getNodeFromQueue(queue_t *recv_queue_p);static voidbtusb_unlink_urbs(btusb_t *devStruct);static voidbtusb_free_urbs(btusb_t *devStruct);static voidbtusb_cleanup_queue(queue_t *queueToClean);static voidbtusb_set_devStruct_defaults(btusb_t *devStruct);static intbtusb_allocate_urbs(btusb_t *devStruct, unsigned int ifnum);#ifdef BTUSB_DEBUGstatic void btusb_display_string(char *displayStr, uint8 codeBlock);#endif /* BTUSB_DEBUG *//* --- End of Local functions prototype --- *//* Static data *//* * Structure containing file operation functions used for character device * registration */static struct file_operations btusb_file_ops_g ={ open : btusb_open, release : btusb_close, read : btusb_read, write : btusb_write, ioctl : btusb_ioctl,};#ifdef LINUX_2_4/* USB device ID structure containing Bluetooth device class code */static struct usb_device_id btusb_ids_g [] ={ { bDeviceClass : WIRELESS_CLASS_CODE, bDeviceSubClass : RF_SUBCLASS_CODE, bDeviceProtocol : BT_PROGRAMMING_PROTOCOL_CODE, }, { }};#endif /* LINUX_2_4 *//* * Structure containing data for Bluetooth class driver registration with * USB host driver */static struct usb_driver btusb_driverInfo_g ={ name : "bluetooth", probe : btusb_probe, disconnect : btusb_disconnect,#ifdef LINUX_2_4 id_table : btusb_ids_g,#endif /* LINUX_2_4 */};/* --- End of static data ---*//* Global data *//* Array of pointers to device information structures of connected BT devices */btusb_t *btusb_devInfo_g[MAX_BTDEV];#ifdef BTUSB_DEBUG/* debug variables for each code block*/uint8 debug_all = 0;uint8 debug_init = 0;uint8 debug_probe = 0;uint8 debug_fileops = 0;uint8 debug_callbacks = 0;uint8 debug_disconnect = 0;uint8 debug_exit = 0;uint8 debug_unlink = 0;#endif /* BTUSB_DEBUG *//* --- End of global data ---*/#endif /* BTUSB_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -