2006-08-10 03:35:12 +08:00
|
|
|
/*
|
|
|
|
* AIRcable USB Bluetooth Dongle Driver.
|
|
|
|
*
|
2010-05-06 05:45:24 +08:00
|
|
|
* Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
|
2006-08-10 03:35:12 +08:00
|
|
|
* Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com)
|
2010-05-06 05:45:24 +08:00
|
|
|
*
|
2006-08-10 03:35:12 +08:00
|
|
|
* 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 device works as an standard CDC device, it has 2 interfaces, the first
|
|
|
|
* one is for firmware access and the second is the serial one.
|
|
|
|
* The protocol is very simply, there are two posibilities reading or writing.
|
2007-05-09 13:14:03 +08:00
|
|
|
* When writing the first urb must have a Header that starts with 0x20 0x29 the
|
2006-08-10 03:35:12 +08:00
|
|
|
* next two bytes must say how much data will be sended.
|
|
|
|
* When reading the process is almost equal except that the header starts with
|
|
|
|
* 0x00 0x20.
|
|
|
|
*
|
2011-03-31 09:57:33 +08:00
|
|
|
* The device simply need some stuff to understand data coming from the usb
|
2006-08-10 03:35:12 +08:00
|
|
|
* buffer: The First and Second byte is used for a Header, the Third and Fourth
|
|
|
|
* tells the device the amount of information the package holds.
|
|
|
|
* Packages are 60 bytes long Header Stuff.
|
2007-05-09 13:14:03 +08:00
|
|
|
* When writing to the device the first two bytes of the header are 0x20 0x29
|
2006-08-10 03:35:12 +08:00
|
|
|
* When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange
|
|
|
|
* situation, when too much data arrives to the device because it sends the data
|
|
|
|
* but with out the header. I will use a simply hack to override this situation,
|
|
|
|
* if there is data coming that does not contain any header, then that is data
|
|
|
|
* that must go directly to the tty, as there is no documentation about if there
|
|
|
|
* is any other control code, I will simply check for the first
|
|
|
|
* one.
|
|
|
|
*
|
|
|
|
* The driver registers himself with the USB-serial core and the USB Core. I had
|
2011-03-31 09:57:33 +08:00
|
|
|
* to implement a probe function against USB-serial, because other way, the
|
2006-08-10 03:35:12 +08:00
|
|
|
* driver was attaching himself to both interfaces. I have tryed with different
|
|
|
|
* configurations of usb_serial_driver with out exit, only the probe function
|
|
|
|
* could handle this correctly.
|
|
|
|
*
|
|
|
|
* I have taken some info from a Greg Kroah-Hartman article:
|
|
|
|
* http://www.linuxjournal.com/article/6573
|
|
|
|
* And from Linux Device Driver Kit CD, which is a great work, the authors taken
|
|
|
|
* the work to recompile lots of information an knowladge in drivers development
|
|
|
|
* and made it all avaible inside a cd.
|
|
|
|
* URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
#include <asm/unaligned.h>
|
2006-08-10 03:35:12 +08:00
|
|
|
#include <linux/tty.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-04 04:09:31 +08:00
|
|
|
#include <linux/module.h>
|
2006-08-10 03:35:12 +08:00
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/serial.h>
|
|
|
|
|
2012-01-13 07:02:20 +08:00
|
|
|
static bool debug;
|
2006-08-10 03:35:12 +08:00
|
|
|
|
|
|
|
/* Vendor and Product ID */
|
|
|
|
#define AIRCABLE_VID 0x16CA
|
|
|
|
#define AIRCABLE_USB_PID 0x1502
|
|
|
|
|
|
|
|
/* Protocol Stuff */
|
|
|
|
#define HCI_HEADER_LENGTH 0x4
|
|
|
|
#define TX_HEADER_0 0x20
|
|
|
|
#define TX_HEADER_1 0x29
|
|
|
|
#define RX_HEADER_0 0x00
|
|
|
|
#define RX_HEADER_1 0x20
|
|
|
|
#define HCI_COMPLETE_FRAME 64
|
|
|
|
|
|
|
|
/* rx_flags */
|
|
|
|
#define THROTTLED 0x01
|
|
|
|
#define ACTUALLY_THROTTLED 0x02
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
2010-05-06 05:45:24 +08:00
|
|
|
#define DRIVER_VERSION "v2.0"
|
|
|
|
#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>, Johan Hovold <jhovold@gmail.com>"
|
2006-08-10 03:35:12 +08:00
|
|
|
#define DRIVER_DESC "AIRcable USB Driver"
|
|
|
|
|
|
|
|
/* ID table that will be registered with USB core */
|
2010-01-10 22:34:24 +08:00
|
|
|
static const struct usb_device_id id_table[] = {
|
2006-08-10 03:35:12 +08:00
|
|
|
{ USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
static int aircable_prepare_write_buffer(struct usb_serial_port *port,
|
2010-05-06 05:58:13 +08:00
|
|
|
void *dest, size_t size)
|
2006-08-10 03:35:12 +08:00
|
|
|
{
|
2010-05-06 05:58:13 +08:00
|
|
|
int count;
|
|
|
|
unsigned char *buf = dest;
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
count = kfifo_out_locked(&port->write_fifo, buf + HCI_HEADER_LENGTH,
|
|
|
|
size - HCI_HEADER_LENGTH, &port->lock);
|
2006-08-10 03:35:12 +08:00
|
|
|
buf[0] = TX_HEADER_0;
|
|
|
|
buf[1] = TX_HEADER_1;
|
2010-05-06 05:45:24 +08:00
|
|
|
put_unaligned_le16(count, &buf[2]);
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2010-05-19 06:01:33 +08:00
|
|
|
return count + HCI_HEADER_LENGTH;
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int aircable_probe(struct usb_serial *serial,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
2008-04-29 21:35:39 +08:00
|
|
|
struct usb_host_interface *iface_desc = serial->interface->
|
|
|
|
cur_altsetting;
|
2006-08-10 03:35:12 +08:00
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
2008-04-29 21:35:39 +08:00
|
|
|
int num_bulk_out = 0;
|
2006-08-10 03:35:12 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
|
|
|
|
endpoint = &iface_desc->endpoint[i].desc;
|
2006-10-27 00:02:45 +08:00
|
|
|
if (usb_endpoint_is_bulk_out(endpoint)) {
|
2006-08-10 03:35:12 +08:00
|
|
|
dbg("found bulk out on endpoint %d", i);
|
|
|
|
++num_bulk_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_bulk_out == 0) {
|
|
|
|
dbg("Invalid interface, discarding");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
static int aircable_process_packet(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, int has_headers,
|
|
|
|
char *packet, int len)
|
2006-08-10 03:35:12 +08:00
|
|
|
{
|
2010-05-06 05:45:24 +08:00
|
|
|
if (has_headers) {
|
|
|
|
len -= HCI_HEADER_LENGTH;
|
|
|
|
packet += HCI_HEADER_LENGTH;
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
2010-05-06 05:45:24 +08:00
|
|
|
if (len <= 0) {
|
|
|
|
dbg("%s - malformed packet", __func__);
|
|
|
|
return 0;
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
tty_insert_flip_string(tty, packet, len);
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
return len;
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
static void aircable_process_read_urb(struct urb *urb)
|
2006-08-10 03:35:12 +08:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
2010-05-06 05:45:24 +08:00
|
|
|
char *data = (char *)urb->transfer_buffer;
|
2006-08-10 03:35:12 +08:00
|
|
|
struct tty_struct *tty;
|
2010-05-06 05:45:24 +08:00
|
|
|
int has_headers;
|
|
|
|
int count;
|
|
|
|
int len;
|
|
|
|
int i;
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2008-10-13 17:39:46 +08:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2010-05-06 05:45:24 +08:00
|
|
|
if (!tty)
|
|
|
|
return;
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
has_headers = (urb->actual_length > 2 && data[0] == RX_HEADER_0);
|
2006-08-10 03:35:12 +08:00
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < urb->actual_length; i += HCI_COMPLETE_FRAME) {
|
|
|
|
len = min_t(int, urb->actual_length - i, HCI_COMPLETE_FRAME);
|
|
|
|
count += aircable_process_packet(tty, port, has_headers,
|
|
|
|
&data[i], len);
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
|
|
|
|
2010-05-06 05:45:24 +08:00
|
|
|
if (count)
|
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
tty_kref_put(tty);
|
2006-08-10 03:35:12 +08:00
|
|
|
}
|
|
|
|
|
2006-12-18 04:50:24 +08:00
|
|
|
static struct usb_driver aircable_driver = {
|
|
|
|
.name = "aircable",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table,
|
|
|
|
.no_dynamic_id = 1,
|
|
|
|
};
|
|
|
|
|
2006-08-10 03:35:12 +08:00
|
|
|
static struct usb_serial_driver aircable_device = {
|
2006-12-18 05:05:09 +08:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "aircable",
|
|
|
|
},
|
2006-12-18 04:50:24 +08:00
|
|
|
.usb_driver = &aircable_driver,
|
2006-08-10 03:35:12 +08:00
|
|
|
.id_table = id_table,
|
|
|
|
.num_ports = 1,
|
2010-05-06 05:45:24 +08:00
|
|
|
.bulk_out_size = HCI_COMPLETE_FRAME,
|
2006-08-10 03:35:12 +08:00
|
|
|
.probe = aircable_probe,
|
2010-05-06 05:45:24 +08:00
|
|
|
.process_read_urb = aircable_process_read_urb,
|
|
|
|
.prepare_write_buffer = aircable_prepare_write_buffer,
|
|
|
|
.throttle = usb_serial_generic_throttle,
|
|
|
|
.unthrottle = usb_serial_generic_unthrottle,
|
2006-08-10 03:35:12 +08:00
|
|
|
};
|
|
|
|
|
2008-04-29 21:35:39 +08:00
|
|
|
static int __init aircable_init(void)
|
2006-08-10 03:35:12 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
retval = usb_serial_register(&aircable_device);
|
|
|
|
if (retval)
|
|
|
|
goto failed_serial_register;
|
|
|
|
retval = usb_register(&aircable_driver);
|
|
|
|
if (retval)
|
|
|
|
goto failed_usb_register;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_usb_register:
|
2009-02-01 18:54:54 +08:00
|
|
|
usb_serial_deregister(&aircable_device);
|
|
|
|
failed_serial_register:
|
2006-08-10 03:35:12 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-04-29 21:35:39 +08:00
|
|
|
static void __exit aircable_exit(void)
|
2006-08-10 03:35:12 +08:00
|
|
|
{
|
|
|
|
usb_deregister(&aircable_driver);
|
|
|
|
usb_serial_deregister(&aircable_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_VERSION(DRIVER_VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(aircable_init);
|
|
|
|
module_exit(aircable_exit);
|
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug enabled or not");
|