2017-11-03 13:28:30 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-08-09 23:35:12 +04:00
|
|
|
/*
|
|
|
|
* AIRcable USB Bluetooth Dongle Driver.
|
|
|
|
*
|
2010-05-06 01:45:24 +04:00
|
|
|
* Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
|
2006-08-09 23:35:12 +04:00
|
|
|
* Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com)
|
2010-05-06 01:45:24 +04:00
|
|
|
*
|
2006-08-09 23:35:12 +04:00
|
|
|
* 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.
|
2014-01-02 17:59:24 +04:00
|
|
|
* The protocol is very simply, there are two possibilities reading or writing.
|
2007-05-09 09:14:03 +04:00
|
|
|
* When writing the first urb must have a Header that starts with 0x20 0x29 the
|
2014-01-02 17:59:24 +04:00
|
|
|
* next two bytes must say how much data will be sent.
|
2006-08-09 23:35:12 +04:00
|
|
|
* When reading the process is almost equal except that the header starts with
|
|
|
|
* 0x00 0x20.
|
|
|
|
*
|
2011-03-31 05:57:33 +04:00
|
|
|
* The device simply need some stuff to understand data coming from the usb
|
2006-08-09 23:35:12 +04: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 09:14:03 +04:00
|
|
|
* When writing to the device the first two bytes of the header are 0x20 0x29
|
2006-08-09 23:35:12 +04: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.
|
|
|
|
*
|
|
|
|
* 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
|
2014-01-02 17:59:24 +04:00
|
|
|
* the work to recompile lots of information an knowledge in drivers development
|
|
|
|
* and made it all available inside a cd.
|
2006-08-09 23:35:12 +04:00
|
|
|
* URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
#include <asm/unaligned.h>
|
2006-08-09 23:35:12 +04: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 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2011-07-04 00:09:31 +04:00
|
|
|
#include <linux/module.h>
|
2006-08-09 23:35:12 +04:00
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/serial.h>
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>, Johan Hovold <jhovold@gmail.com>"
|
2006-08-09 23:35:12 +04:00
|
|
|
#define DRIVER_DESC "AIRcable USB Driver"
|
|
|
|
|
|
|
|
/* ID table that will be registered with USB core */
|
2010-01-10 17:34:24 +03:00
|
|
|
static const struct usb_device_id id_table[] = {
|
2006-08-09 23:35:12 +04:00
|
|
|
{ USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
static int aircable_prepare_write_buffer(struct usb_serial_port *port,
|
2010-05-06 01:58:13 +04:00
|
|
|
void *dest, size_t size)
|
2006-08-09 23:35:12 +04:00
|
|
|
{
|
2010-05-06 01:58:13 +04:00
|
|
|
int count;
|
|
|
|
unsigned char *buf = dest;
|
2006-08-09 23:35:12 +04:00
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
count = kfifo_out_locked(&port->write_fifo, buf + HCI_HEADER_LENGTH,
|
|
|
|
size - HCI_HEADER_LENGTH, &port->lock);
|
2006-08-09 23:35:12 +04:00
|
|
|
buf[0] = TX_HEADER_0;
|
|
|
|
buf[1] = TX_HEADER_1;
|
2010-05-06 01:45:24 +04:00
|
|
|
put_unaligned_le16(count, &buf[2]);
|
2006-08-09 23:35:12 +04:00
|
|
|
|
2010-05-19 02:01:33 +04:00
|
|
|
return count + HCI_HEADER_LENGTH;
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
2017-03-16 19:13:36 +03:00
|
|
|
static int aircable_calc_num_ports(struct usb_serial *serial,
|
|
|
|
struct usb_serial_endpoints *epds)
|
2006-08-09 23:35:12 +04:00
|
|
|
{
|
2017-03-16 19:13:36 +03:00
|
|
|
/* Ignore the first interface, which has no bulk endpoints. */
|
|
|
|
if (epds->num_bulk_out == 0) {
|
|
|
|
dev_dbg(&serial->interface->dev,
|
|
|
|
"ignoring interface with no bulk-out endpoints\n");
|
2006-08-09 23:35:12 +04:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2017-03-16 19:13:36 +03:00
|
|
|
return 1;
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 18:53:04 +04:00
|
|
|
static int aircable_process_packet(struct usb_serial_port *port,
|
|
|
|
int has_headers, char *packet, int len)
|
2006-08-09 23:35:12 +04:00
|
|
|
{
|
2010-05-06 01:45:24 +04:00
|
|
|
if (has_headers) {
|
|
|
|
len -= HCI_HEADER_LENGTH;
|
|
|
|
packet += HCI_HEADER_LENGTH;
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
2010-05-06 01:45:24 +04:00
|
|
|
if (len <= 0) {
|
2012-05-16 03:27:08 +04:00
|
|
|
dev_dbg(&port->dev, "%s - malformed packet\n", __func__);
|
2010-05-06 01:45:24 +04:00
|
|
|
return 0;
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 18:53:04 +04:00
|
|
|
tty_insert_flip_string(&port->port, packet, len);
|
2006-08-09 23:35:12 +04:00
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
return len;
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
static void aircable_process_read_urb(struct urb *urb)
|
2006-08-09 23:35:12 +04:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
2010-05-06 01:45:24 +04:00
|
|
|
char *data = (char *)urb->transfer_buffer;
|
|
|
|
int has_headers;
|
|
|
|
int count;
|
|
|
|
int len;
|
|
|
|
int i;
|
2006-08-09 23:35:12 +04:00
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
has_headers = (urb->actual_length > 2 && data[0] == RX_HEADER_0);
|
2006-08-09 23:35:12 +04:00
|
|
|
|
2010-05-06 01:45:24 +04: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);
|
2013-01-03 18:53:04 +04:00
|
|
|
count += aircable_process_packet(port, has_headers,
|
2010-05-06 01:45:24 +04:00
|
|
|
&data[i], len);
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
2010-05-06 01:45:24 +04:00
|
|
|
if (count)
|
2013-01-03 18:53:06 +04:00
|
|
|
tty_flip_buffer_push(&port->port);
|
2006-08-09 23:35:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_serial_driver aircable_device = {
|
2006-12-18 00:05:09 +03:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "aircable",
|
|
|
|
},
|
2006-08-09 23:35:12 +04:00
|
|
|
.id_table = id_table,
|
2010-05-06 01:45:24 +04:00
|
|
|
.bulk_out_size = HCI_COMPLETE_FRAME,
|
2017-03-16 19:13:36 +03:00
|
|
|
.calc_num_ports = aircable_calc_num_ports,
|
2010-05-06 01:45:24 +04: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-09 23:35:12 +04:00
|
|
|
};
|
|
|
|
|
2012-02-23 23:56:17 +04:00
|
|
|
static struct usb_serial_driver * const serial_drivers[] = {
|
|
|
|
&aircable_device, NULL
|
|
|
|
};
|
|
|
|
|
2012-05-09 02:46:14 +04:00
|
|
|
module_usb_serial_driver(serial_drivers, id_table);
|
2006-08-09 23:35:12 +04:00
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
2017-11-03 20:12:08 +03:00
|
|
|
MODULE_LICENSE("GPL v2");
|