亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bluetty.c

?? linux qt class 類的函數定義
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
 * bluetty.c   Version 0.13
 *
 * Copyright (c) 2000, 2001 Greg Kroah-Hartman	<greg@kroah.com>
 * Copyright (c) 2000 Mark Douglas Corner	<mcorner@umich.edu>
 *
 * USB Bluetooth TTY driver, based on the Bluetooth Spec version 1.0B
 * 
 * (2001/11/30) Version 0.13 gkh
 *	- added locking patch from Masoodur Rahman <rmasoodu@in.ibm.com>
 *	- removed active variable, as open_count will do.
 *
 * (2001/07/09) Version 0.12 gkh
 *	- removed in_interrupt() call, as it doesn't make sense to do 
 *	  that anymore.
 *
 * (2001/06/05) Version 0.11 gkh
 *	- Fixed problem with read urb status saying that we have shutdown,
 *	  and that we shouldn't resubmit the urb.  Patch from unknown.
 *
 * (2001/05/28) Version 0.10 gkh
 *	- Fixed problem with using data from userspace in the bluetooth_write
 *	  function as found by the CHECKER project.
 *	- Added a buffer to the write_urb_pool which reduces the number of
 *	  buffers being created and destroyed for ever write.  Also cleans
 *	  up the logic a bit.
 *	- Added a buffer to the control_urb_pool which fixes a memory leak
 *	  when the device is removed from the system.
 *
 * (2001/05/28) Version 0.9 gkh
 *	Fixed problem with bluetooth==NULL for bluetooth_read_bulk_callback
 *	which was found by both the CHECKER project and Mikko Rahkonen.
 *
 * (08/04/2001) gb
 *	Identify version on module load.
 *
 * (2001/03/10) Version 0.8 gkh
 *	Fixed problem with not unlinking interrupt urb on device close
 *	and resubmitting the read urb on error with bluetooth struct.
 *	Thanks to Narayan Mohanram <narayan@RovingNetworks.com> for the
 *	fixes.
 *
 * (11/29/2000) Version 0.7 gkh
 *	Fixed problem with overrunning the tty flip buffer.
 *	Removed unneeded NULL pointer initialization.
 *
 * (10/05/2000) Version 0.6 gkh
 *	Fixed bug with urb->dev not being set properly, now that the usb
 *	core needs it.
 *	Got a real major id number and name.
 *
 * (08/06/2000) Version 0.5 gkh
 *	Fixed problem of not resubmitting the bulk read urb if there is
 *	an error in the callback.  Ericsson devices seem to need this.
 *
 * (07/11/2000) Version 0.4 gkh
 *	Fixed bug in disconnect for when we call tty_hangup
 *	Fixed bug in bluetooth_ctrl_msg where the bluetooth struct was not
 *	getting attached to the control urb properly.
 *	Fixed bug in bluetooth_write where we pay attention to the result
 *	of bluetooth_ctrl_msg.
 *
 * (08/03/2000) Version 0.3 gkh mdc
 *	Merged in Mark's changes to make the driver play nice with the Axis
 *	stack.
 *	Made the write bulk use an urb pool to enable larger transfers with
 *	fewer calls to the driver.
 *	Fixed off by one bug in acl pkt receive
 *	Made packet counters specific to each bluetooth device 
 *	Added checks for zero length callbacks
 *	Added buffers for int and bulk packets.  Had to do this otherwise 
 *	packet types could intermingle.
 *	Made a control urb pool for the control messages.
 *
 * (07/11/2000) Version 0.2 gkh
 *	Fixed a small bug found by Nils Faerber in the usb_bluetooth_probe 
 *	function.
 *
 * (07/09/2000) Version 0.1 gkh
 *	Initial release. Has support for sending ACL data (which is really just
 *	a HCI frame.) Raw HCI commands and HCI events are not supported.
 *	A ioctl will probably be needed for the HCI commands and events in the
 *	future. All isoch endpoints are ignored at this time also.
 *	This driver should work for all currently shipping USB Bluetooth 
 *	devices at this time :)
 * 
 */

/*
 * 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
 */


#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <asm/uaccess.h>

#define DEBUG
#include <linux/usb.h>

/*
 * Version Information
 */
#define DRIVER_VERSION "v0.13"
#define DRIVER_AUTHOR "Greg Kroah-Hartman, Mark Douglas Corner"
#define DRIVER_DESC "USB Bluetooth tty driver"

/* define this if you have hardware that is not good */
/*#define	BTBUGGYHARDWARE */

/* Class, SubClass, and Protocol codes that describe a Bluetooth device */
#define WIRELESS_CLASS_CODE			0xe0
#define RF_SUBCLASS_CODE			0x01
#define BLUETOOTH_PROGRAMMING_PROTOCOL_CODE	0x01


#define BLUETOOTH_TTY_MAJOR	216	/* real device node major id */
#define BLUETOOTH_TTY_MINORS	256	/* whole lotta bluetooth devices */

#define USB_BLUETOOTH_MAGIC	0x6d02	/* magic number for bluetooth struct */

#define BLUETOOTH_CONTROL_REQUEST_TYPE	0x20

/* Bluetooth packet types */
#define CMD_PKT			0x01
#define ACL_PKT			0x02
#define SCO_PKT			0x03
#define EVENT_PKT		0x04
#define ERROR_PKT		0x05
#define NEG_PKT			0x06

/* Message sizes */
#define MAX_EVENT_SIZE		0xFF
#define EVENT_HDR_SIZE		3	/* 2 for the header + 1 for the type indicator */
#define EVENT_BUFFER_SIZE	(MAX_EVENT_SIZE + EVENT_HDR_SIZE)

#define MAX_ACL_SIZE		0xFFFF
#define ACL_HDR_SIZE		5	/* 4 for the header + 1 for the type indicator */
#define ACL_BUFFER_SIZE		(MAX_ACL_SIZE + ACL_HDR_SIZE)

/* parity check flag */
#define RELEVANT_IFLAG(iflag)	(iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))

#define CHAR2INT16(c1,c0)	(((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))

#define NUM_BULK_URBS		24
#define NUM_CONTROL_URBS	16

struct usb_bluetooth {
	int			magic;
	struct usb_device *	dev;
	struct tty_driver *	tty_driver;	/* the tty_driver for this device */
	struct tty_struct *	tty;		/* the coresponding tty for this port */

	unsigned char		minor;		/* the starting minor number for this device */
	int			throttle;	/* throttled by tty layer */
	int			open_count;
	
	__u8			control_out_bInterfaceNum;
	struct urb *		control_urb_pool[NUM_CONTROL_URBS];
	struct usb_ctrlrequest	dr[NUM_CONTROL_URBS];

	unsigned char *		interrupt_in_buffer;
	struct urb *		interrupt_in_urb;
	__u8			interrupt_in_endpointAddress;
	__u8			interrupt_in_interval;
	int			interrupt_in_buffer_size;

	unsigned char *		bulk_in_buffer;
	struct urb *		read_urb;
	__u8			bulk_in_endpointAddress;
	int			bulk_in_buffer_size;

	int			bulk_out_buffer_size;
	struct urb *		write_urb_pool[NUM_BULK_URBS];
	__u8			bulk_out_endpointAddress;

	wait_queue_head_t	write_wait;

	struct tq_struct	tqueue;		/* task queue for line discipline waking up */
	
	unsigned int		int_packet_pos;
	unsigned char		int_buffer[EVENT_BUFFER_SIZE];
	unsigned int		bulk_packet_pos;
	unsigned char		bulk_buffer[ACL_BUFFER_SIZE];	/* 64k preallocated, fix? */
	struct semaphore	lock;
};


/* local function prototypes */
static int  bluetooth_open		(struct tty_struct *tty, struct file *filp);
static void bluetooth_close		(struct tty_struct *tty, struct file *filp);
static int  bluetooth_write		(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
static int  bluetooth_write_room	(struct tty_struct *tty);
static int  bluetooth_chars_in_buffer	(struct tty_struct *tty);
static void bluetooth_throttle		(struct tty_struct *tty);
static void bluetooth_unthrottle	(struct tty_struct *tty);
static int  bluetooth_ioctl		(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
static void bluetooth_set_termios	(struct tty_struct *tty, struct termios *old);

static void bluetooth_int_callback		(struct urb *urb);
static void bluetooth_ctrl_callback		(struct urb *urb);
static void bluetooth_read_bulk_callback	(struct urb *urb);
static void bluetooth_write_bulk_callback	(struct urb *urb);

static void * usb_bluetooth_probe(struct usb_device *dev, unsigned int ifnum,
			 	  const struct usb_device_id *id);
static void usb_bluetooth_disconnect	(struct usb_device *dev, void *ptr);


static struct usb_device_id usb_bluetooth_ids [] = {
	{ USB_DEVICE_INFO(WIRELESS_CLASS_CODE, RF_SUBCLASS_CODE, BLUETOOTH_PROGRAMMING_PROTOCOL_CODE) },
	{ }						/* Terminating entry */
};

MODULE_DEVICE_TABLE (usb, usb_bluetooth_ids);

static struct usb_driver usb_bluetooth_driver = {
	name:		"bluetty",
	probe:		usb_bluetooth_probe,
	disconnect:	usb_bluetooth_disconnect,
	id_table:	usb_bluetooth_ids,
};

static int			bluetooth_refcount;
static struct tty_driver	bluetooth_tty_driver;
static struct tty_struct *	bluetooth_tty[BLUETOOTH_TTY_MINORS];
static struct termios *		bluetooth_termios[BLUETOOTH_TTY_MINORS];
static struct termios *		bluetooth_termios_locked[BLUETOOTH_TTY_MINORS];
static struct usb_bluetooth	*bluetooth_table[BLUETOOTH_TTY_MINORS];


static inline int bluetooth_paranoia_check (struct usb_bluetooth *bluetooth, const char *function)
{
	if (!bluetooth) {
		dbg("%s - bluetooth == NULL", function);
		return -1;
	}
	if (bluetooth->magic != USB_BLUETOOTH_MAGIC) {
		dbg("%s - bad magic number for bluetooth", function);
		return -1;
	}

	return 0;
}


static inline struct usb_bluetooth* get_usb_bluetooth (struct usb_bluetooth *bluetooth, const char *function)
{
	if (!bluetooth || 
	    bluetooth_paranoia_check (bluetooth, function)) { 
		/* then say that we dont have a valid usb_bluetooth thing, which will
		 * end up generating -ENODEV return values */
		return NULL;
	}

	return bluetooth;
}


static inline struct usb_bluetooth *get_bluetooth_by_minor (int minor)
{
	return bluetooth_table[minor];
}


static int bluetooth_ctrl_msg (struct usb_bluetooth *bluetooth, int request, int value, const unsigned char *buf, int len)
{
	struct urb *urb = NULL;
	struct usb_ctrlrequest *dr = NULL;
	int i;
	int status;

	dbg (__FUNCTION__);

	/* try to find a free urb in our list */
	for (i = 0; i < NUM_CONTROL_URBS; ++i) {
		if (bluetooth->control_urb_pool[i]->status != -EINPROGRESS) {
			urb = bluetooth->control_urb_pool[i];
			dr = &bluetooth->dr[i];
			break;
		}
	}
	if (urb == NULL) {
		dbg (__FUNCTION__ " - no free urbs");
		return -ENOMEM;
	}

	/* keep increasing the urb transfer buffer to fit the size of the message */
	if (urb->transfer_buffer == NULL) {
		urb->transfer_buffer = kmalloc (len, GFP_KERNEL);
		if (urb->transfer_buffer == NULL) {
			err (__FUNCTION__" - out of memory");
			return -ENOMEM;
		}
	}
	if (urb->transfer_buffer_length < len) {
		kfree (urb->transfer_buffer);
		urb->transfer_buffer = kmalloc (len, GFP_KERNEL);
		if (urb->transfer_buffer == NULL) {
			err (__FUNCTION__" - out of memory");
			return -ENOMEM;
		}
	}
	memcpy (urb->transfer_buffer, buf, len);

	dr->bRequestType= BLUETOOTH_CONTROL_REQUEST_TYPE;
	dr->bRequest = request;
	dr->wValue = cpu_to_le16((u16) value);
	dr->wIndex = cpu_to_le16((u16) bluetooth->control_out_bInterfaceNum);
	dr->wLength = cpu_to_le16((u16) len);
	
	FILL_CONTROL_URB (urb, bluetooth->dev, usb_sndctrlpipe(bluetooth->dev, 0),
			  (unsigned char*)dr, urb->transfer_buffer, len, bluetooth_ctrl_callback, bluetooth);

	/* send it down the pipe */
	status = usb_submit_urb(urb, GFP_KERNEL);
	if (status)
		dbg(__FUNCTION__ " - usb_submit_urb(control) failed with status = %d", status);
	
	return status;
}





/*****************************************************************************
 * Driver tty interface functions
 *****************************************************************************/
static int bluetooth_open (struct tty_struct *tty, struct file * filp)
{
	struct usb_bluetooth *bluetooth;
	int result;

	dbg(__FUNCTION__);

	/* initialize the pointer incase something fails */
	tty->driver_data = NULL;

	/* get the bluetooth object associated with this tty pointer */
	bluetooth = get_bluetooth_by_minor (minor(tty->device));

	if (bluetooth_paranoia_check (bluetooth, __FUNCTION__)) {
		return -ENODEV;
	}

	down (&bluetooth->lock);
 
	++bluetooth->open_count;
	if (bluetooth->open_count == 1) {
		/* set up our structure making the tty driver remember our object, and us it */
		tty->driver_data = bluetooth;
		bluetooth->tty = tty;

		/* force low_latency on so that our tty_push actually forces the data through, 
	 	* otherwise it is scheduled, and with high data rates (like with OHCI) data
	 	* can get lost. */
		bluetooth->tty->low_latency = 1;
	
		/* Reset the packet position counters */
		bluetooth->int_packet_pos = 0;
		bluetooth->bulk_packet_pos = 0;

#ifndef BTBUGGYHARDWARE
		/* Start reading from the device */
		FILL_BULK_URB (bluetooth->read_urb, bluetooth->dev, 
			       usb_rcvbulkpipe(bluetooth->dev, bluetooth->bulk_in_endpointAddress),
			       bluetooth->bulk_in_buffer,
			       bluetooth->bulk_in_buffer_size,
			       bluetooth_read_bulk_callback, bluetooth);
		result = usb_submit_urb(bluetooth->read_urb, GFP_KERNEL);
		if (result)
			dbg(__FUNCTION__ " - usb_submit_urb(read bulk) failed with status %d", result);
#endif
		FILL_INT_URB (bluetooth->interrupt_in_urb, bluetooth->dev,
			      usb_rcvintpipe(bluetooth->dev, bluetooth->interrupt_in_endpointAddress),
			      bluetooth->interrupt_in_buffer,
			      bluetooth->interrupt_in_buffer_size,
			      bluetooth_int_callback, bluetooth,
			      bluetooth->interrupt_in_interval);
		result = usb_submit_urb(bluetooth->interrupt_in_urb, GFP_KERNEL);
		if (result)
			dbg(__FUNCTION__ " - usb_submit_urb(interrupt in) failed with status %d", result);
	}
	
	up(&bluetooth->lock);

	return 0;
}


static void bluetooth_close (struct tty_struct *tty, struct file * filp)
{
	struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
	int i;

	if (!bluetooth) {
		return;
	}

	dbg(__FUNCTION__);

	if (!bluetooth->open_count) {
		dbg (__FUNCTION__ " - device not opened");
		return;
	}

	down (&bluetooth->lock);
 
	--bluetooth->open_count;
	if (bluetooth->open_count <= 0) {
		bluetooth->open_count = 0;

		/* shutdown any bulk reads and writes that might be going on */
		for (i = 0; i < NUM_BULK_URBS; ++i)
			usb_unlink_urb (bluetooth->write_urb_pool[i]);
		usb_unlink_urb (bluetooth->read_urb);
		usb_unlink_urb (bluetooth->interrupt_in_urb);
	}
	up(&bluetooth->lock);
}


static int bluetooth_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
{
	struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
	struct urb *urb = NULL;
	unsigned char *temp_buffer = NULL;
	const unsigned char *current_buffer;
	const unsigned char *current_position;
	int bytes_sent;
	int buffer_size;
	int i;
	int retval = 0;

	if (!bluetooth) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩精品一二三区| 久久午夜羞羞影院免费观看| 777午夜精品免费视频| 精品国产sm最大网站| 国产精品色呦呦| 亚洲福利国产精品| 激情av综合网| 色综合 综合色| 精品国产一区二区三区久久久蜜月| 国产精品成人网| 日韩精品1区2区3区| 不卡的av中国片| 91精品久久久久久蜜臀| 国产午夜精品一区二区| 亚洲图片有声小说| 粉嫩绯色av一区二区在线观看| 欧美性大战久久久久久久| 精品国产1区二区| 亚洲国产三级在线| 国产成人在线网站| 欧美日韩国产片| 国产精品日产欧美久久久久| 日韩激情视频在线观看| 91在线看国产| 久久久蜜臀国产一区二区| 亚洲一区二区三区视频在线| 高清久久久久久| 日韩亚洲电影在线| 亚洲伊人伊色伊影伊综合网| 丁香婷婷综合五月| 欧美一级黄色录像| 又紧又大又爽精品一区二区| 国产精品综合二区| 欧美日韩国产综合一区二区| 中文字幕免费观看一区| 捆绑紧缚一区二区三区视频| 欧美亚洲愉拍一区二区| 中文字幕制服丝袜成人av| 久久99精品一区二区三区| 欧美日韩成人一区| 亚洲综合在线免费观看| 成人黄色片在线观看| 精品粉嫩超白一线天av| 日韩精品亚洲专区| 欧美日韩国产精选| 一区二区三区四区在线播放| av资源网一区| 日本一区二区视频在线观看| 激情五月激情综合网| 欧美一区中文字幕| 亚洲国产欧美一区二区三区丁香婷| 成人性生交大片| 久久精品一区二区三区av| 日本欧美韩国一区三区| 欧美日韩国产小视频| 亚洲一区影音先锋| 在线影视一区二区三区| 一级日本不卡的影视| 99久久99久久精品免费观看| 日韩精品国产精品| 亚洲免费观看在线观看| 成人国产在线观看| 国产亚洲女人久久久久毛片| 国产在线播放一区二区三区| 精品国产不卡一区二区三区| 久久精品国产精品亚洲综合| 日韩免费观看高清完整版| 日韩精品乱码av一区二区| 91精品国产一区二区三区蜜臀| 午夜欧美视频在线观看| 欧美日韩国产美| 奇米888四色在线精品| 欧美一区二区久久| 蜜桃视频在线观看一区二区| 日韩免费一区二区三区在线播放| 日韩和欧美一区二区| 日韩三级中文字幕| 激情综合网最新| 久久久久久久电影| 成人的网站免费观看| 亚洲欧美一区二区三区国产精品| 91影院在线观看| 一区二区国产视频| 欧美日韩一级片在线观看| 欧美a级理论片| 精品久久免费看| 国产成人午夜视频| 亚洲蜜桃精久久久久久久| 在线观看日韩精品| 免费人成黄页网站在线一区二区| 激情文学综合丁香| 久久看人人爽人人| 成人黄色在线看| 一区二区三区四区乱视频| 555www色欧美视频| 黄页视频在线91| 国产精品国模大尺度视频| 色国产综合视频| 日本欧美一区二区三区| 久久久.com| 在线观看视频一区二区| 蜜桃免费网站一区二区三区| 久久久久久久网| 色视频一区二区| 青青草原综合久久大伊人精品| 久久综合久色欧美综合狠狠| 91丝袜美腿高跟国产极品老师| 日本视频免费一区| 欧美激情在线一区二区| 欧美视频完全免费看| 激情另类小说区图片区视频区| 亚洲三级在线看| 欧美一区二区精美| 91网站最新网址| 欧美伊人精品成人久久综合97| 蜜臀av国产精品久久久久| 国产精品国产a| 8x8x8国产精品| 成人av一区二区三区| 日韩综合小视频| 国产精品女主播av| 777a∨成人精品桃花网| 国产成人综合亚洲91猫咪| 日韩**一区毛片| 欧美精品一区二区高清在线观看| 9久草视频在线视频精品| 天天综合色天天| 欧美国产激情一区二区三区蜜月| 欧美午夜精品一区| 丰满少妇在线播放bd日韩电影| 午夜视频一区二区三区| 中文字幕在线观看一区二区| 欧美一级免费大片| 色婷婷一区二区三区四区| 黑人精品欧美一区二区蜜桃| 亚洲一区二区三区四区在线免费观看| 久久久久9999亚洲精品| 欧美一区二区三区免费视频| 99视频国产精品| 捆绑变态av一区二区三区| 亚洲午夜精品网| 国产精品久久久久久久岛一牛影视 | 欧美日韩一区二区不卡| 成人高清视频免费观看| 久久精品噜噜噜成人88aⅴ| 亚洲综合激情小说| 欧美激情中文字幕一区二区| 日韩美女一区二区三区| 欧美视频完全免费看| 91一区二区在线| 大胆欧美人体老妇| 久久久久国产精品麻豆ai换脸| 欧美影院一区二区| 成人av电影在线观看| 久久电影网站中文字幕 | 欧美日韩视频在线一区二区 | 亚洲成人激情综合网| 国产精品国产精品国产专区不蜜| 久久综合狠狠综合久久综合88| 欧美精品少妇一区二区三区| 色婷婷av一区二区三区软件| 99久久久国产精品免费蜜臀| 国产精品中文字幕日韩精品| 日本vs亚洲vs韩国一区三区| 婷婷开心久久网| 亚洲午夜国产一区99re久久| 亚洲最大成人网4388xx| 亚洲美女在线一区| 综合电影一区二区三区 | 欧美中文字幕不卡| 91在线免费视频观看| 99久久精品国产导航| 成人激情免费网站| 福利一区二区在线观看| 东方欧美亚洲色图在线| 国产不卡视频一区二区三区| 丁香激情综合国产| 国产成人日日夜夜| 欧美不卡视频一区| 久久女同精品一区二区| 久久综合视频网| 久久久精品国产免费观看同学| 久久欧美中文字幕| 国产精品午夜电影| 国产精品久久久久7777按摩| 国产精品理论在线观看| 一区二区中文视频| 综合欧美亚洲日本| 一区二区日韩av| 日韩高清在线不卡| 美女任你摸久久| 国产乱一区二区| 成人免费视频一区| 91蜜桃免费观看视频| 日本精品裸体写真集在线观看| 欧美日韩视频在线一区二区 | 国产一区二区三区在线观看免费视频| 国产精品99久久久久久有的能看 | 午夜精品福利一区二区三区av| 亚洲午夜精品在线|