2017-11-03 04:28:30 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-09-17 09:34:27 -06:00
|
|
|
/*
|
|
|
|
* Wireless USB - Cable Based Association
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Intel Corporation
|
|
|
|
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
|
2008-09-17 09:34:42 -06:00
|
|
|
* Copyright (C) 2008 Cambridge Silicon Radio Ltd.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* WUSB devices have to be paired (associated in WUSB lingo) so
|
2008-09-17 09:34:27 -06:00
|
|
|
* that they can connect to the system.
|
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* One way of pairing is using CBA-Cable Based Association. First
|
|
|
|
* time you plug the device with a cable, association is done between
|
|
|
|
* host and device and subsequent times, you can connect wirelessly
|
|
|
|
* without having to associate again. That's the idea.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
|
|
|
* This driver does nothing Earth shattering. It just provides an
|
|
|
|
* interface to chat with the wire-connected device so we can get a
|
|
|
|
* CDID (device ID) that might have been previously associated to a
|
|
|
|
* CHID (host ID) and to set up a new <CHID,CDID,CK> triplet
|
|
|
|
* (connection context), with the CK being the secret, or connection
|
|
|
|
* key. This is the pairing data.
|
|
|
|
*
|
|
|
|
* When a device with the CBA capability connects, the probe routine
|
|
|
|
* just creates a bunch of sysfs files that a user space enumeration
|
|
|
|
* manager uses to allow it to connect wirelessly to the system or not.
|
|
|
|
*
|
|
|
|
* The process goes like this:
|
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 1. Device plugs, cbaf is loaded, notifications happen.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 2. The connection manager (CM) sees a device with CBAF capability
|
|
|
|
* (the wusb_chid etc. files in /sys/devices/blah/OURDEVICE).
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 3. The CM writes the host name, supported band groups, and the CHID
|
|
|
|
* (host ID) into the wusb_host_name, wusb_host_band_groups and
|
|
|
|
* wusb_chid files. These get sent to the device and the CDID (if
|
|
|
|
* any) for this host is requested.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 4. The CM can verify that the device's supported band groups
|
|
|
|
* (wusb_device_band_groups) are compatible with the host.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 5. The CM reads the wusb_cdid file.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 6. The CM looks up its database
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 6.1 If it has a matching CHID,CDID entry, the device has been
|
|
|
|
* authorized before (paired) and nothing further needs to be
|
|
|
|
* done.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 6.2 If the CDID is zero (or the CM doesn't find a matching CDID in
|
|
|
|
* its database), the device is assumed to be not known. The CM
|
|
|
|
* may associate the host with device by: writing a randomly
|
|
|
|
* generated CDID to wusb_cdid and then a random CK to wusb_ck
|
|
|
|
* (this uploads the new CC to the device).
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* CMD may choose to prompt the user before associating with a new
|
|
|
|
* device.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* 7. Device is unplugged.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* When the device tries to connect wirelessly, it will present its
|
|
|
|
* CDID to the WUSB host controller. The CM will query the
|
|
|
|
* database. If the CHID/CDID pair found, it will (with a 4-way
|
|
|
|
* handshake) challenge the device to demonstrate it has the CK secret
|
|
|
|
* key (from our database) without actually exchanging it. Once
|
|
|
|
* satisfied, crypto keys are derived from the CK, the device is
|
|
|
|
* connected and all communication is encrypted.
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* References:
|
|
|
|
* [WUSB-AM] Association Models Supplement to the Certified Wireless
|
|
|
|
* Universal Serial Bus Specification, version 1.0.
|
2008-09-17 09:34:27 -06:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/random.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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2008-09-17 09:34:27 -06:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/uwb.h>
|
|
|
|
#include <linux/usb/wusb.h>
|
|
|
|
#include <linux/usb/association.h>
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
#define CBA_NAME_LEN 0x40 /* [WUSB-AM] table 4-7 */
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
/* An instance of a Cable-Based-Association-Framework device */
|
|
|
|
struct cbaf {
|
|
|
|
struct usb_device *usb_dev;
|
|
|
|
struct usb_interface *usb_iface;
|
|
|
|
void *buffer;
|
|
|
|
size_t buffer_size;
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
struct wusb_ckhdid chid;
|
|
|
|
char host_name[CBA_NAME_LEN];
|
2008-09-17 09:34:27 -06:00
|
|
|
u16 host_band_groups;
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
struct wusb_ckhdid cdid;
|
|
|
|
char device_name[CBA_NAME_LEN];
|
2008-09-17 09:34:27 -06:00
|
|
|
u16 device_band_groups;
|
2008-09-17 09:34:42 -06:00
|
|
|
|
|
|
|
struct wusb_ckhdid ck;
|
2008-09-17 09:34:27 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that a CBAF USB-interface has what we need
|
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* According to [WUSB-AM], CBA devices should provide at least two
|
|
|
|
* interfaces:
|
|
|
|
* - RETRIEVE_HOST_INFO
|
|
|
|
* - ASSOCIATE
|
2008-09-17 09:34:27 -06:00
|
|
|
*
|
2008-09-17 09:34:42 -06:00
|
|
|
* If the device doesn't provide these interfaces, we do not know how
|
|
|
|
* to deal with it.
|
2008-09-17 09:34:27 -06:00
|
|
|
*/
|
|
|
|
static int cbaf_check(struct cbaf *cbaf)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct device *dev = &cbaf->usb_iface->dev;
|
|
|
|
struct wusb_cbaf_assoc_info *assoc_info;
|
|
|
|
struct wusb_cbaf_assoc_request *assoc_request;
|
|
|
|
size_t assoc_size;
|
|
|
|
void *itr, *top;
|
2008-09-17 09:34:42 -06:00
|
|
|
int ar_rhi = 0, ar_assoc = 0;
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
result = usb_control_msg(
|
|
|
|
cbaf->usb_dev, usb_rcvctrlpipe(cbaf->usb_dev, 0),
|
|
|
|
CBAF_REQ_GET_ASSOCIATION_INFORMATION,
|
|
|
|
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber,
|
2013-12-09 12:19:08 -07:00
|
|
|
cbaf->buffer, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT);
|
2008-09-17 09:34:27 -06:00
|
|
|
if (result < 0) {
|
2008-09-17 09:34:42 -06:00
|
|
|
dev_err(dev, "Cannot get available association types: %d\n",
|
2008-09-17 09:34:27 -06:00
|
|
|
result);
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
assoc_info = cbaf->buffer;
|
|
|
|
if (result < sizeof(*assoc_info)) {
|
2008-09-17 09:34:42 -06:00
|
|
|
dev_err(dev, "Not enough data to decode association info "
|
2008-09-17 09:34:27 -06:00
|
|
|
"header (%zu vs %zu bytes required)\n",
|
|
|
|
(size_t)result, sizeof(*assoc_info));
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
assoc_size = le16_to_cpu(assoc_info->Length);
|
|
|
|
if (result < assoc_size) {
|
2008-09-17 09:34:42 -06:00
|
|
|
dev_err(dev, "Not enough data to decode association info "
|
2008-09-17 09:34:27 -06:00
|
|
|
"(%zu vs %zu bytes required)\n",
|
|
|
|
(size_t)assoc_size, sizeof(*assoc_info));
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* From now on, we just verify, but won't error out unless we
|
|
|
|
* don't find the AR_TYPE_WUSB_{RETRIEVE_HOST_INFO,ASSOCIATE}
|
|
|
|
* types.
|
|
|
|
*/
|
|
|
|
itr = cbaf->buffer + sizeof(*assoc_info);
|
|
|
|
top = cbaf->buffer + assoc_size;
|
2008-09-17 09:34:42 -06:00
|
|
|
dev_dbg(dev, "Found %u association requests (%zu bytes)\n",
|
2008-09-17 09:34:27 -06:00
|
|
|
assoc_info->NumAssociationRequests, assoc_size);
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
while (itr < top) {
|
|
|
|
u16 ar_type, ar_subtype;
|
|
|
|
u32 ar_size;
|
|
|
|
const char *ar_name;
|
|
|
|
|
|
|
|
assoc_request = itr;
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
if (top - itr < sizeof(*assoc_request)) {
|
2014-01-04 00:07:52 -07:00
|
|
|
dev_err(dev, "Not enough data to decode association "
|
2008-09-17 09:34:27 -06:00
|
|
|
"request (%zu vs %zu bytes needed)\n",
|
|
|
|
top - itr, sizeof(*assoc_request));
|
|
|
|
break;
|
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
ar_type = le16_to_cpu(assoc_request->AssociationTypeId);
|
|
|
|
ar_subtype = le16_to_cpu(assoc_request->AssociationSubTypeId);
|
|
|
|
ar_size = le32_to_cpu(assoc_request->AssociationTypeInfoSize);
|
2008-09-17 09:34:42 -06:00
|
|
|
ar_name = "unknown";
|
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
switch (ar_type) {
|
|
|
|
case AR_TYPE_WUSB:
|
2008-09-17 09:34:42 -06:00
|
|
|
/* Verify we have what is mandated by [WUSB-AM]. */
|
2008-09-17 09:34:27 -06:00
|
|
|
switch (ar_subtype) {
|
|
|
|
case AR_TYPE_WUSB_RETRIEVE_HOST_INFO:
|
2008-09-17 09:34:42 -06:00
|
|
|
ar_name = "RETRIEVE_HOST_INFO";
|
|
|
|
ar_rhi = 1;
|
2008-09-17 09:34:27 -06:00
|
|
|
break;
|
|
|
|
case AR_TYPE_WUSB_ASSOCIATE:
|
|
|
|
/* send assoc data */
|
2008-09-17 09:34:42 -06:00
|
|
|
ar_name = "ASSOCIATE";
|
|
|
|
ar_assoc = 1;
|
2008-09-17 09:34:27 -06:00
|
|
|
break;
|
2013-10-08 17:01:37 -06:00
|
|
|
}
|
2008-09-17 09:34:27 -06:00
|
|
|
break;
|
2013-10-08 17:01:37 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
|
|
|
dev_dbg(dev, "Association request #%02u: 0x%04x/%04x "
|
2008-09-17 09:34:27 -06:00
|
|
|
"(%zu bytes): %s\n",
|
|
|
|
assoc_request->AssociationDataIndex, ar_type,
|
|
|
|
ar_subtype, (size_t)ar_size, ar_name);
|
|
|
|
|
|
|
|
itr += sizeof(*assoc_request);
|
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
|
|
|
if (!ar_rhi) {
|
2008-09-17 09:34:27 -06:00
|
|
|
dev_err(dev, "Missing RETRIEVE_HOST_INFO association "
|
|
|
|
"request\n");
|
2008-09-17 09:34:42 -06:00
|
|
|
return -EINVAL;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
if (!ar_assoc) {
|
2008-09-17 09:34:27 -06:00
|
|
|
dev_err(dev, "Missing ASSOCIATE association request\n");
|
2008-09-17 09:34:42 -06:00
|
|
|
return -EINVAL;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
return 0;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wusb_cbaf_host_info cbaf_host_info_defaults = {
|
|
|
|
.AssociationTypeId_hdr = WUSB_AR_AssociationTypeId,
|
2014-01-03 22:49:04 -07:00
|
|
|
.AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB),
|
2008-09-17 09:34:27 -06:00
|
|
|
.AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId,
|
|
|
|
.AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_RETRIEVE_HOST_INFO),
|
|
|
|
.CHID_hdr = WUSB_AR_CHID,
|
|
|
|
.LangID_hdr = WUSB_AR_LangID,
|
|
|
|
.HostFriendlyName_hdr = WUSB_AR_HostFriendlyName,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Send WUSB host information (CHID and name) to a CBAF device */
|
|
|
|
static int cbaf_send_host_info(struct cbaf *cbaf)
|
|
|
|
{
|
|
|
|
struct wusb_cbaf_host_info *hi;
|
2008-09-17 09:34:42 -06:00
|
|
|
size_t name_len;
|
2008-09-17 09:34:27 -06:00
|
|
|
size_t hi_size;
|
|
|
|
|
|
|
|
hi = cbaf->buffer;
|
|
|
|
memset(hi, 0, sizeof(*hi));
|
|
|
|
*hi = cbaf_host_info_defaults;
|
|
|
|
hi->CHID = cbaf->chid;
|
|
|
|
hi->LangID = 0; /* FIXME: I guess... */
|
2008-09-17 09:34:42 -06:00
|
|
|
strlcpy(hi->HostFriendlyName, cbaf->host_name, CBA_NAME_LEN);
|
|
|
|
name_len = strlen(cbaf->host_name);
|
|
|
|
hi->HostFriendlyName_hdr.len = cpu_to_le16(name_len);
|
|
|
|
hi_size = sizeof(*hi) + name_len;
|
|
|
|
|
2014-01-03 22:49:04 -07:00
|
|
|
return usb_control_msg(cbaf->usb_dev,
|
|
|
|
usb_sndctrlpipe(cbaf->usb_dev, 0),
|
2008-09-17 09:34:27 -06:00
|
|
|
CBAF_REQ_SET_ASSOCIATION_RESPONSE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0x0101,
|
|
|
|
cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber,
|
2013-12-09 12:19:08 -07:00
|
|
|
hi, hi_size, USB_CTRL_SET_TIMEOUT);
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
/*
|
|
|
|
* Get device's information (CDID) associated to CHID
|
|
|
|
*
|
|
|
|
* The device will return it's information (CDID, name, bandgroups)
|
|
|
|
* associated to the CHID we have set before, or 0 CDID and default
|
|
|
|
* name and bandgroup if no CHID set or unknown.
|
|
|
|
*/
|
|
|
|
static int cbaf_cdid_get(struct cbaf *cbaf)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct device *dev = &cbaf->usb_iface->dev;
|
|
|
|
struct wusb_cbaf_device_info *di;
|
|
|
|
size_t needed;
|
|
|
|
|
|
|
|
di = cbaf->buffer;
|
|
|
|
result = usb_control_msg(
|
|
|
|
cbaf->usb_dev, usb_rcvctrlpipe(cbaf->usb_dev, 0),
|
|
|
|
CBAF_REQ_GET_ASSOCIATION_REQUEST,
|
|
|
|
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0x0200, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber,
|
2013-12-09 12:19:08 -07:00
|
|
|
di, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT);
|
2008-09-17 09:34:42 -06:00
|
|
|
if (result < 0) {
|
2014-01-03 22:49:04 -07:00
|
|
|
dev_err(dev, "Cannot request device information: %d\n",
|
|
|
|
result);
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
needed = result < sizeof(*di) ? sizeof(*di) : le32_to_cpu(di->Length);
|
|
|
|
if (result < needed) {
|
|
|
|
dev_err(dev, "Not enough data in DEVICE_INFO reply (%zu vs "
|
|
|
|
"%zu bytes needed)\n", (size_t)result, needed);
|
2011-06-04 00:10:21 -06:00
|
|
|
return -ENOENT;
|
2008-09-17 09:34:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN);
|
|
|
|
cbaf->cdid = di->CDID;
|
|
|
|
cbaf->device_band_groups = le16_to_cpu(di->BandGroups);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_chid_show(struct device *dev,
|
2008-09-17 09:34:27 -06:00
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
char pr_chid[WUSB_CKHDID_STRSIZE];
|
|
|
|
|
|
|
|
ckhdid_printf(pr_chid, sizeof(pr_chid), &cbaf->chid);
|
2008-09-17 09:34:42 -06:00
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", pr_chid);
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
static ssize_t cbaf_wusb_chid_store(struct device *dev,
|
2008-09-17 09:34:27 -06:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
result = sscanf(buf,
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
2008-09-17 09:34:42 -06:00
|
|
|
"%02hhx %02hhx %02hhx %02hhx",
|
2008-09-17 09:34:27 -06:00
|
|
|
&cbaf->chid.data[0] , &cbaf->chid.data[1],
|
|
|
|
&cbaf->chid.data[2] , &cbaf->chid.data[3],
|
|
|
|
&cbaf->chid.data[4] , &cbaf->chid.data[5],
|
|
|
|
&cbaf->chid.data[6] , &cbaf->chid.data[7],
|
|
|
|
&cbaf->chid.data[8] , &cbaf->chid.data[9],
|
|
|
|
&cbaf->chid.data[10], &cbaf->chid.data[11],
|
|
|
|
&cbaf->chid.data[12], &cbaf->chid.data[13],
|
2008-09-17 09:34:42 -06:00
|
|
|
&cbaf->chid.data[14], &cbaf->chid.data[15]);
|
|
|
|
|
|
|
|
if (result != 16)
|
2008-09-17 09:34:27 -06:00
|
|
|
return -EINVAL;
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
result = cbaf_send_host_info(cbaf);
|
|
|
|
if (result < 0)
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
|
|
|
result = cbaf_cdid_get(cbaf);
|
|
|
|
if (result < 0)
|
2011-06-04 00:10:21 -06:00
|
|
|
return result;
|
2008-09-17 09:34:42 -06:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(wusb_chid, 0600, cbaf_wusb_chid_show, cbaf_wusb_chid_store);
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_host_name_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", cbaf->host_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_host_name_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
result = sscanf(buf, "%63s", cbaf->host_name);
|
|
|
|
if (result != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(wusb_host_name, 0600, cbaf_wusb_host_name_show,
|
|
|
|
cbaf_wusb_host_name_store);
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_host_band_groups_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "0x%04x\n", cbaf->host_band_groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_host_band_groups_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
u16 band_groups = 0;
|
|
|
|
|
|
|
|
result = sscanf(buf, "%04hx", &band_groups);
|
|
|
|
if (result != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
cbaf->host_band_groups = band_groups;
|
|
|
|
|
|
|
|
return size;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
|
|
|
|
static DEVICE_ATTR(wusb_host_band_groups, 0600,
|
|
|
|
cbaf_wusb_host_band_groups_show,
|
|
|
|
cbaf_wusb_host_band_groups_store);
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
static const struct wusb_cbaf_device_info cbaf_device_info_defaults = {
|
|
|
|
.Length_hdr = WUSB_AR_Length,
|
|
|
|
.CDID_hdr = WUSB_AR_CDID,
|
|
|
|
.BandGroups_hdr = WUSB_AR_BandGroups,
|
|
|
|
.LangID_hdr = WUSB_AR_LangID,
|
|
|
|
.DeviceFriendlyName_hdr = WUSB_AR_DeviceFriendlyName,
|
|
|
|
};
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
static ssize_t cbaf_wusb_cdid_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-09-17 09:34:27 -06:00
|
|
|
{
|
2008-09-17 09:34:42 -06:00
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
char pr_cdid[WUSB_CKHDID_STRSIZE];
|
2008-09-17 09:34:27 -06:00
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
ckhdid_printf(pr_cdid, sizeof(pr_cdid), &cbaf->cdid);
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", pr_cdid);
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
static ssize_t cbaf_wusb_cdid_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
2008-09-17 09:34:27 -06:00
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
2008-09-17 09:34:42 -06:00
|
|
|
struct wusb_ckhdid cdid;
|
2008-09-17 09:34:27 -06:00
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
result = sscanf(buf,
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx",
|
|
|
|
&cdid.data[0] , &cdid.data[1],
|
|
|
|
&cdid.data[2] , &cdid.data[3],
|
|
|
|
&cdid.data[4] , &cdid.data[5],
|
|
|
|
&cdid.data[6] , &cdid.data[7],
|
|
|
|
&cdid.data[8] , &cdid.data[9],
|
|
|
|
&cdid.data[10], &cdid.data[11],
|
|
|
|
&cdid.data[12], &cdid.data[13],
|
|
|
|
&cdid.data[14], &cdid.data[15]);
|
|
|
|
if (result != 16)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
cbaf->cdid = cdid;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(wusb_cdid, 0600, cbaf_wusb_cdid_show, cbaf_wusb_cdid_store);
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_device_band_groups_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "0x%04x\n", cbaf->device_band_groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(wusb_device_band_groups, 0600,
|
|
|
|
cbaf_wusb_device_band_groups_show,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
static ssize_t cbaf_wusb_device_name_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", cbaf->device_name);
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
static DEVICE_ATTR(wusb_device_name, 0600, cbaf_wusb_device_name_show, NULL);
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
static const struct wusb_cbaf_cc_data cbaf_cc_data_defaults = {
|
|
|
|
.AssociationTypeId_hdr = WUSB_AR_AssociationTypeId,
|
2014-01-03 22:49:04 -07:00
|
|
|
.AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB),
|
2008-09-17 09:34:27 -06:00
|
|
|
.AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId,
|
|
|
|
.AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_ASSOCIATE),
|
|
|
|
.Length_hdr = WUSB_AR_Length,
|
2014-01-03 22:49:04 -07:00
|
|
|
.Length = cpu_to_le32(sizeof(struct wusb_cbaf_cc_data)),
|
2008-09-17 09:34:27 -06:00
|
|
|
.ConnectionContext_hdr = WUSB_AR_ConnectionContext,
|
|
|
|
.BandGroups_hdr = WUSB_AR_BandGroups,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct wusb_cbaf_cc_data_fail cbaf_cc_data_fail_defaults = {
|
|
|
|
.AssociationTypeId_hdr = WUSB_AR_AssociationTypeId,
|
|
|
|
.AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId,
|
|
|
|
.Length_hdr = WUSB_AR_Length,
|
|
|
|
.AssociationStatus_hdr = WUSB_AR_AssociationStatus,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2008-09-17 09:34:42 -06:00
|
|
|
* Send a new CC to the device.
|
2008-09-17 09:34:27 -06:00
|
|
|
*/
|
|
|
|
static int cbaf_cc_upload(struct cbaf *cbaf)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct device *dev = &cbaf->usb_iface->dev;
|
|
|
|
struct wusb_cbaf_cc_data *ccd;
|
|
|
|
char pr_cdid[WUSB_CKHDID_STRSIZE];
|
|
|
|
|
|
|
|
ccd = cbaf->buffer;
|
|
|
|
*ccd = cbaf_cc_data_defaults;
|
|
|
|
ccd->CHID = cbaf->chid;
|
|
|
|
ccd->CDID = cbaf->cdid;
|
|
|
|
ccd->CK = cbaf->ck;
|
|
|
|
ccd->BandGroups = cpu_to_le16(cbaf->host_band_groups);
|
2008-09-17 09:34:42 -06:00
|
|
|
|
|
|
|
dev_dbg(dev, "Trying to upload CC:\n");
|
|
|
|
ckhdid_printf(pr_cdid, sizeof(pr_cdid), &ccd->CHID);
|
|
|
|
dev_dbg(dev, " CHID %s\n", pr_cdid);
|
|
|
|
ckhdid_printf(pr_cdid, sizeof(pr_cdid), &ccd->CDID);
|
|
|
|
dev_dbg(dev, " CDID %s\n", pr_cdid);
|
|
|
|
dev_dbg(dev, " Bandgroups 0x%04x\n", cbaf->host_band_groups);
|
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
result = usb_control_msg(
|
|
|
|
cbaf->usb_dev, usb_sndctrlpipe(cbaf->usb_dev, 0),
|
|
|
|
CBAF_REQ_SET_ASSOCIATION_RESPONSE,
|
|
|
|
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
0x0201, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber,
|
2013-12-09 12:19:08 -07:00
|
|
|
ccd, sizeof(*ccd), USB_CTRL_SET_TIMEOUT);
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:42 -06:00
|
|
|
static ssize_t cbaf_wusb_ck_store(struct device *dev,
|
2008-09-17 09:34:27 -06:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t result;
|
|
|
|
struct usb_interface *iface = to_usb_interface(dev);
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
|
|
|
|
result = sscanf(buf,
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
|
|
|
"%02hhx %02hhx %02hhx %02hhx "
|
2008-09-17 09:34:42 -06:00
|
|
|
"%02hhx %02hhx %02hhx %02hhx",
|
2008-09-17 09:34:27 -06:00
|
|
|
&cbaf->ck.data[0] , &cbaf->ck.data[1],
|
|
|
|
&cbaf->ck.data[2] , &cbaf->ck.data[3],
|
|
|
|
&cbaf->ck.data[4] , &cbaf->ck.data[5],
|
|
|
|
&cbaf->ck.data[6] , &cbaf->ck.data[7],
|
|
|
|
&cbaf->ck.data[8] , &cbaf->ck.data[9],
|
|
|
|
&cbaf->ck.data[10], &cbaf->ck.data[11],
|
|
|
|
&cbaf->ck.data[12], &cbaf->ck.data[13],
|
|
|
|
&cbaf->ck.data[14], &cbaf->ck.data[15]);
|
2008-09-17 09:34:42 -06:00
|
|
|
if (result != 16)
|
2008-09-17 09:34:27 -06:00
|
|
|
return -EINVAL;
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
result = cbaf_cc_upload(cbaf);
|
|
|
|
if (result < 0)
|
2008-09-17 09:34:42 -06:00
|
|
|
return result;
|
|
|
|
|
|
|
|
return size;
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
2008-09-17 09:34:42 -06:00
|
|
|
static DEVICE_ATTR(wusb_ck, 0600, NULL, cbaf_wusb_ck_store);
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
static struct attribute *cbaf_dev_attrs[] = {
|
2008-09-17 09:34:42 -06:00
|
|
|
&dev_attr_wusb_host_name.attr,
|
|
|
|
&dev_attr_wusb_host_band_groups.attr,
|
|
|
|
&dev_attr_wusb_chid.attr,
|
2008-09-17 09:34:27 -06:00
|
|
|
&dev_attr_wusb_cdid.attr,
|
2008-09-17 09:34:42 -06:00
|
|
|
&dev_attr_wusb_device_name.attr,
|
|
|
|
&dev_attr_wusb_device_band_groups.attr,
|
|
|
|
&dev_attr_wusb_ck.attr,
|
2008-09-17 09:34:27 -06:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-08-04 06:06:45 -06:00
|
|
|
static const struct attribute_group cbaf_dev_attr_group = {
|
2008-09-17 09:34:27 -06:00
|
|
|
.name = NULL, /* we want them in the same directory */
|
|
|
|
.attrs = cbaf_dev_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cbaf_probe(struct usb_interface *iface,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct cbaf *cbaf;
|
|
|
|
struct device *dev = &iface->dev;
|
2008-09-17 09:34:42 -06:00
|
|
|
int result = -ENOMEM;
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
cbaf = kzalloc(sizeof(*cbaf), GFP_KERNEL);
|
2008-09-17 09:34:42 -06:00
|
|
|
if (cbaf == NULL)
|
2008-09-17 09:34:27 -06:00
|
|
|
goto error_kzalloc;
|
|
|
|
cbaf->buffer = kmalloc(512, GFP_KERNEL);
|
|
|
|
if (cbaf->buffer == NULL)
|
|
|
|
goto error_kmalloc_buffer;
|
2008-09-17 09:34:42 -06:00
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
cbaf->buffer_size = 512;
|
|
|
|
cbaf->usb_dev = usb_get_dev(interface_to_usbdev(iface));
|
|
|
|
cbaf->usb_iface = usb_get_intf(iface);
|
|
|
|
result = cbaf_check(cbaf);
|
2008-09-17 09:34:42 -06:00
|
|
|
if (result < 0) {
|
2016-09-12 07:19:17 -06:00
|
|
|
dev_err(dev, "This device is not WUSB-CBAF compliant and is not supported yet.\n");
|
2008-09-17 09:34:27 -06:00
|
|
|
goto error_check;
|
2008-09-17 09:34:42 -06:00
|
|
|
}
|
|
|
|
|
2008-09-17 09:34:27 -06:00
|
|
|
result = sysfs_create_group(&dev->kobj, &cbaf_dev_attr_group);
|
|
|
|
if (result < 0) {
|
|
|
|
dev_err(dev, "Can't register sysfs attr group: %d\n", result);
|
|
|
|
goto error_create_group;
|
|
|
|
}
|
|
|
|
usb_set_intfdata(iface, cbaf);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_create_group:
|
|
|
|
error_check:
|
2013-10-18 15:49:38 -06:00
|
|
|
usb_put_intf(iface);
|
|
|
|
usb_put_dev(cbaf->usb_dev);
|
2008-09-17 09:34:27 -06:00
|
|
|
kfree(cbaf->buffer);
|
|
|
|
error_kmalloc_buffer:
|
|
|
|
kfree(cbaf);
|
|
|
|
error_kzalloc:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cbaf_disconnect(struct usb_interface *iface)
|
|
|
|
{
|
|
|
|
struct cbaf *cbaf = usb_get_intfdata(iface);
|
|
|
|
struct device *dev = &iface->dev;
|
|
|
|
sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group);
|
|
|
|
usb_set_intfdata(iface, NULL);
|
|
|
|
usb_put_intf(iface);
|
2013-10-18 15:49:38 -06:00
|
|
|
usb_put_dev(cbaf->usb_dev);
|
2008-09-17 09:34:27 -06:00
|
|
|
kfree(cbaf->buffer);
|
|
|
|
/* paranoia: clean up crypto keys */
|
2009-03-04 13:06:15 -07:00
|
|
|
kzfree(cbaf);
|
2008-09-17 09:34:27 -06:00
|
|
|
}
|
|
|
|
|
2010-01-10 07:33:45 -07:00
|
|
|
static const struct usb_device_id cbaf_id_table[] = {
|
2008-09-17 09:34:27 -06:00
|
|
|
{ USB_INTERFACE_INFO(0xef, 0x03, 0x01), },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, cbaf_id_table);
|
|
|
|
|
|
|
|
static struct usb_driver cbaf_driver = {
|
|
|
|
.name = "wusb-cbaf",
|
|
|
|
.id_table = cbaf_id_table,
|
|
|
|
.probe = cbaf_probe,
|
|
|
|
.disconnect = cbaf_disconnect,
|
|
|
|
};
|
|
|
|
|
2011-11-18 10:34:02 -07:00
|
|
|
module_usb_driver(cbaf_driver);
|
2008-09-17 09:34:27 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Wireless USB Cable Based Association");
|
|
|
|
MODULE_LICENSE("GPL");
|