License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-05-14 17:55:07 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005-2007 Takahiro Hirofuchi
|
|
|
|
*/
|
|
|
|
|
2011-06-20 12:44:37 +07:00
|
|
|
#include "usbip_common.h"
|
|
|
|
#include "vhci_driver.h"
|
2014-01-08 02:05:56 +07:00
|
|
|
#include <limits.h>
|
|
|
|
#include <netdb.h>
|
2014-03-08 19:53:26 +07:00
|
|
|
#include <libudev.h>
|
2017-05-22 17:20:16 +07:00
|
|
|
#include <dirent.h>
|
2014-03-08 19:53:28 +07:00
|
|
|
#include "sysfs_utils.h"
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2011-06-20 12:44:35 +07:00
|
|
|
#undef PROGNAME
|
|
|
|
#define PROGNAME "libusbip"
|
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
struct usbip_vhci_driver *vhci_driver;
|
2014-03-08 19:53:26 +07:00
|
|
|
struct udev *udev_context;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2013-02-22 18:13:29 +07:00
|
|
|
static struct usbip_imported_device *
|
|
|
|
imported_device_init(struct usbip_imported_device *idev, char *busid)
|
2011-05-14 17:55:07 +07:00
|
|
|
{
|
2014-03-08 19:53:26 +07:00
|
|
|
struct udev_device *sudev;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2014-03-08 19:53:26 +07:00
|
|
|
sudev = udev_device_new_from_subsystem_sysname(udev_context,
|
|
|
|
"usb", busid);
|
2011-05-14 17:55:07 +07:00
|
|
|
if (!sudev) {
|
2014-03-08 19:53:26 +07:00
|
|
|
dbg("udev_device_new_from_subsystem_sysname failed: %s", busid);
|
2011-05-14 17:55:07 +07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
read_usb_device(sudev, &idev->udev);
|
2014-03-08 19:53:26 +07:00
|
|
|
udev_device_unref(sudev);
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
return idev;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-08 19:53:28 +07:00
|
|
|
static int parse_status(const char *value)
|
2011-05-14 17:55:07 +07:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char *c;
|
|
|
|
|
|
|
|
/* skip a header line */
|
2012-03-23 21:55:25 +07:00
|
|
|
c = strchr(value, '\n');
|
|
|
|
if (!c)
|
|
|
|
return -1;
|
|
|
|
c++;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
while (*c != '\0') {
|
|
|
|
int port, status, speed, devid;
|
2017-12-08 04:16:49 +07:00
|
|
|
int sockfd;
|
2011-05-14 17:55:07 +07:00
|
|
|
char lbusid[SYSFS_BUS_ID_SIZE];
|
2017-05-22 17:20:18 +07:00
|
|
|
struct usbip_imported_device *idev;
|
2017-06-08 12:04:10 +07:00
|
|
|
char hub[3];
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2017-12-08 04:16:49 +07:00
|
|
|
ret = sscanf(c, "%2s %d %d %d %x %u %31s\n",
|
2017-06-08 12:04:10 +07:00
|
|
|
hub, &port, &status, &speed,
|
2017-12-08 04:16:49 +07:00
|
|
|
&devid, &sockfd, lbusid);
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
if (ret < 5) {
|
2011-06-20 12:44:38 +07:00
|
|
|
dbg("sscanf failed: %d", ret);
|
2011-05-14 17:55:07 +07:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2017-06-08 12:04:10 +07:00
|
|
|
dbg("hub %s port %d status %d speed %d devid %x",
|
|
|
|
hub, port, status, speed, devid);
|
2017-12-08 04:16:49 +07:00
|
|
|
dbg("sockfd %u lbusid %s", sockfd, lbusid);
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
/* if a device is connected, look at it */
|
2017-05-22 17:20:18 +07:00
|
|
|
idev = &vhci_driver->idev[port];
|
|
|
|
memset(idev, 0, sizeof(*idev));
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2017-06-08 12:04:10 +07:00
|
|
|
if (strncmp("hs", hub, 2) == 0)
|
|
|
|
idev->hub = HUB_SPEED_HIGH;
|
|
|
|
else /* strncmp("ss", hub, 2) == 0 */
|
|
|
|
idev->hub = HUB_SPEED_SUPER;
|
|
|
|
|
2017-05-22 17:20:18 +07:00
|
|
|
idev->port = port;
|
|
|
|
idev->status = status;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2017-05-22 17:20:18 +07:00
|
|
|
idev->devid = devid;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2017-05-22 17:20:18 +07:00
|
|
|
idev->busnum = (devid >> 16);
|
|
|
|
idev->devnum = (devid & 0x0000ffff);
|
|
|
|
|
|
|
|
if (idev->status != VDEV_ST_NULL
|
|
|
|
&& idev->status != VDEV_ST_NOTASSIGNED) {
|
|
|
|
idev = imported_device_init(idev, lbusid);
|
|
|
|
if (!idev) {
|
|
|
|
dbg("imported_device_init failed");
|
|
|
|
return -1;
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go to the next line */
|
2012-03-23 21:55:25 +07:00
|
|
|
c = strchr(c, '\n');
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
c++;
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
dbg("exit");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:09:04 +07:00
|
|
|
#define MAX_STATUS_NAME 18
|
2017-05-22 17:20:17 +07:00
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
static int refresh_imported_device_list(void)
|
|
|
|
{
|
2014-03-08 19:53:28 +07:00
|
|
|
const char *attr_status;
|
2017-05-22 17:20:17 +07:00
|
|
|
char status[MAX_STATUS_NAME+1] = "status";
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < vhci_driver->ncontrollers; i++) {
|
|
|
|
if (i > 0)
|
|
|
|
snprintf(status, sizeof(status), "status.%d", i);
|
|
|
|
|
|
|
|
attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device,
|
|
|
|
status);
|
|
|
|
if (!attr_status) {
|
|
|
|
err("udev_device_get_sysattr_value failed");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2017-05-22 17:20:17 +07:00
|
|
|
dbg("controller %d", i);
|
|
|
|
|
|
|
|
ret = parse_status(attr_status);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2017-05-22 17:20:17 +07:00
|
|
|
return 0;
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2018-05-25 21:23:46 +07:00
|
|
|
static int get_nports(struct udev_device *hc_device)
|
2011-05-14 17:55:07 +07:00
|
|
|
{
|
2017-04-06 05:03:23 +07:00
|
|
|
const char *attr_nports;
|
2011-05-14 17:55:07 +07:00
|
|
|
|
2018-05-25 21:23:46 +07:00
|
|
|
attr_nports = udev_device_get_sysattr_value(hc_device, "nports");
|
2017-04-06 05:03:23 +07:00
|
|
|
if (!attr_nports) {
|
|
|
|
err("udev_device_get_sysattr_value nports failed");
|
2011-05-14 17:55:07 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-04-06 05:03:23 +07:00
|
|
|
return (int)strtoul(attr_nports, NULL, 10);
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2017-05-22 17:20:16 +07:00
|
|
|
static int vhci_hcd_filter(const struct dirent *dirent)
|
|
|
|
{
|
2018-09-21 03:29:42 +07:00
|
|
|
return !strncmp(dirent->d_name, "vhci_hcd.", 9);
|
2017-05-22 17:20:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_ncontrollers(void)
|
|
|
|
{
|
|
|
|
struct dirent **namelist;
|
|
|
|
struct udev_device *platform;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
platform = udev_device_get_parent(vhci_driver->hc_device);
|
|
|
|
if (platform == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
n = scandir(udev_device_get_syspath(platform), &namelist, vhci_hcd_filter, NULL);
|
|
|
|
if (n < 0)
|
|
|
|
err("scandir failed");
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
free(namelist[i]);
|
|
|
|
free(namelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-02-13 09:47:56 +07:00
|
|
|
/*
|
|
|
|
* Read the given port's record.
|
|
|
|
*
|
|
|
|
* To avoid buffer overflow we will read the entire line and
|
|
|
|
* validate each part's size. The initial buffer is padded by 4 to
|
|
|
|
* accommodate the 2 spaces, 1 newline and an additional character
|
|
|
|
* which is needed to properly validate the 3rd part without it being
|
|
|
|
* truncated to an acceptable length.
|
|
|
|
*/
|
|
|
|
static int read_record(int rhport, char *host, unsigned long host_len,
|
|
|
|
char *port, unsigned long port_len, char *busid)
|
2014-01-08 02:05:56 +07:00
|
|
|
{
|
2014-02-13 09:47:56 +07:00
|
|
|
int part;
|
2014-01-08 02:05:56 +07:00
|
|
|
FILE *file;
|
|
|
|
char path[PATH_MAX+1];
|
2014-02-13 09:47:56 +07:00
|
|
|
char *buffer, *start, *end;
|
|
|
|
char delim[] = {' ', ' ', '\n'};
|
|
|
|
int max_len[] = {(int)host_len, (int)port_len, SYSFS_BUS_ID_SIZE};
|
|
|
|
size_t buffer_len = host_len + port_len + SYSFS_BUS_ID_SIZE + 4;
|
|
|
|
|
|
|
|
buffer = malloc(buffer_len);
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2014-01-08 02:05:56 +07:00
|
|
|
|
|
|
|
snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport);
|
|
|
|
|
|
|
|
file = fopen(path, "r");
|
|
|
|
if (!file) {
|
|
|
|
err("fopen");
|
2014-02-13 09:47:56 +07:00
|
|
|
free(buffer);
|
2014-01-08 02:05:56 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-13 09:47:56 +07:00
|
|
|
if (fgets(buffer, buffer_len, file) == NULL) {
|
|
|
|
err("fgets");
|
|
|
|
free(buffer);
|
2014-01-08 02:05:56 +07:00
|
|
|
fclose(file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
2014-02-13 09:47:56 +07:00
|
|
|
/* validate the length of each of the 3 parts */
|
|
|
|
start = buffer;
|
|
|
|
for (part = 0; part < 3; part++) {
|
|
|
|
end = strchr(start, delim[part]);
|
|
|
|
if (end == NULL || (end - start) > max_len[part]) {
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(buffer, "%s %s %s\n", host, port, busid) != 3) {
|
|
|
|
err("sscanf");
|
|
|
|
free(buffer);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
2014-01-08 02:05:56 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int usbip_vhci_driver_open(void)
|
|
|
|
{
|
2018-05-25 21:23:46 +07:00
|
|
|
int nports;
|
|
|
|
struct udev_device *hc_device;
|
|
|
|
|
2014-03-08 19:53:26 +07:00
|
|
|
udev_context = udev_new();
|
|
|
|
if (!udev_context) {
|
|
|
|
err("udev_new failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
/* will be freed in usbip_driver_close() */
|
2018-05-25 21:23:46 +07:00
|
|
|
hc_device =
|
2014-03-08 19:53:28 +07:00
|
|
|
udev_device_new_from_subsystem_sysname(udev_context,
|
|
|
|
USBIP_VHCI_BUS_TYPE,
|
2017-06-08 12:04:08 +07:00
|
|
|
USBIP_VHCI_DEVICE_NAME);
|
2018-05-25 21:23:46 +07:00
|
|
|
if (!hc_device) {
|
2014-03-08 19:53:28 +07:00
|
|
|
err("udev_device_new_from_subsystem_sysname failed");
|
2011-05-14 17:55:07 +07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2018-05-25 21:23:46 +07:00
|
|
|
nports = get_nports(hc_device);
|
|
|
|
if (nports <= 0) {
|
2017-05-22 17:20:15 +07:00
|
|
|
err("no available ports");
|
|
|
|
goto err;
|
2018-05-25 21:23:46 +07:00
|
|
|
}
|
|
|
|
dbg("available ports: %d", nports);
|
|
|
|
|
|
|
|
vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) +
|
|
|
|
nports * sizeof(struct usbip_imported_device));
|
|
|
|
if (!vhci_driver) {
|
|
|
|
err("vhci_driver allocation failed");
|
2017-05-22 17:20:15 +07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2018-05-25 21:23:46 +07:00
|
|
|
vhci_driver->nports = nports;
|
|
|
|
vhci_driver->hc_device = hc_device;
|
2017-05-22 17:20:16 +07:00
|
|
|
vhci_driver->ncontrollers = get_ncontrollers();
|
|
|
|
dbg("available controllers: %d", vhci_driver->ncontrollers);
|
|
|
|
|
|
|
|
if (vhci_driver->ncontrollers <=0) {
|
|
|
|
err("no available usb controllers");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
if (refresh_imported_device_list())
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2018-05-25 21:23:46 +07:00
|
|
|
udev_device_unref(hc_device);
|
2014-03-08 19:53:28 +07:00
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
if (vhci_driver)
|
|
|
|
free(vhci_driver);
|
|
|
|
|
|
|
|
vhci_driver = NULL;
|
2014-03-08 19:53:26 +07:00
|
|
|
|
|
|
|
udev_unref(udev_context);
|
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-15 02:28:27 +07:00
|
|
|
void usbip_vhci_driver_close(void)
|
2011-05-14 17:55:07 +07:00
|
|
|
{
|
|
|
|
if (!vhci_driver)
|
|
|
|
return;
|
|
|
|
|
2014-03-08 19:53:28 +07:00
|
|
|
udev_device_unref(vhci_driver->hc_device);
|
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
free(vhci_driver);
|
|
|
|
|
|
|
|
vhci_driver = NULL;
|
2014-03-08 19:53:26 +07:00
|
|
|
|
|
|
|
udev_unref(udev_context);
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int usbip_vhci_refresh_device_list(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (refresh_imported_device_list())
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
2011-06-20 12:44:38 +07:00
|
|
|
dbg("failed to refresh device list");
|
2011-05-14 17:55:07 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 12:04:10 +07:00
|
|
|
int usbip_vhci_get_free_port(uint32_t speed)
|
2011-05-14 17:55:07 +07:00
|
|
|
{
|
|
|
|
for (int i = 0; i < vhci_driver->nports; i++) {
|
2017-11-30 05:24:22 +07:00
|
|
|
|
|
|
|
switch (speed) {
|
|
|
|
case USB_SPEED_SUPER:
|
|
|
|
if (vhci_driver->idev[i].hub != HUB_SPEED_SUPER)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (vhci_driver->idev[i].hub != HUB_SPEED_HIGH)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
2017-06-08 12:04:10 +07:00
|
|
|
|
2011-05-14 17:55:07 +07:00
|
|
|
if (vhci_driver->idev[i].status == VDEV_ST_NULL)
|
2017-06-08 12:04:10 +07:00
|
|
|
return vhci_driver->idev[i].port;
|
2011-05-14 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
|
|
|
|
uint32_t speed) {
|
|
|
|
char buff[200]; /* what size should be ? */
|
2014-03-08 19:53:28 +07:00
|
|
|
char attach_attr_path[SYSFS_PATH_MAX];
|
|
|
|
char attr_attach[] = "attach";
|
|
|
|
const char *path;
|
2011-05-14 17:55:07 +07:00
|
|
|
int ret;
|
|
|
|
|
2014-02-27 18:36:31 +07:00
|
|
|
snprintf(buff, sizeof(buff), "%u %d %u %u",
|
2011-05-14 17:55:07 +07:00
|
|
|
port, sockfd, devid, speed);
|
|
|
|
dbg("writing: %s", buff);
|
|
|
|
|
2014-03-08 19:53:28 +07:00
|
|
|
path = udev_device_get_syspath(vhci_driver->hc_device);
|
|
|
|
snprintf(attach_attr_path, sizeof(attach_attr_path), "%s/%s",
|
|
|
|
path, attr_attach);
|
|
|
|
dbg("attach attribute path: %s", attach_attr_path);
|
|
|
|
|
|
|
|
ret = write_sysfs_attribute(attach_attr_path, buff, strlen(buff));
|
2011-05-14 17:55:07 +07:00
|
|
|
if (ret < 0) {
|
2014-03-08 19:53:28 +07:00
|
|
|
dbg("write_sysfs_attribute failed");
|
2011-05-14 17:55:07 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-20 12:44:38 +07:00
|
|
|
dbg("attached port: %d", port);
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long get_devid(uint8_t busnum, uint8_t devnum)
|
|
|
|
{
|
|
|
|
return (busnum << 16) | devnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* will be removed */
|
|
|
|
int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,
|
|
|
|
uint8_t devnum, uint32_t speed)
|
|
|
|
{
|
|
|
|
int devid = get_devid(busnum, devnum);
|
|
|
|
|
|
|
|
return usbip_vhci_attach_device2(port, sockfd, devid, speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
int usbip_vhci_detach_device(uint8_t port)
|
|
|
|
{
|
2014-03-08 19:53:28 +07:00
|
|
|
char detach_attr_path[SYSFS_PATH_MAX];
|
|
|
|
char attr_detach[] = "detach";
|
2011-05-14 17:55:07 +07:00
|
|
|
char buff[200]; /* what size should be ? */
|
2014-03-08 19:53:28 +07:00
|
|
|
const char *path;
|
2011-05-14 17:55:07 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
snprintf(buff, sizeof(buff), "%u", port);
|
|
|
|
dbg("writing: %s", buff);
|
|
|
|
|
2014-03-08 19:53:28 +07:00
|
|
|
path = udev_device_get_syspath(vhci_driver->hc_device);
|
|
|
|
snprintf(detach_attr_path, sizeof(detach_attr_path), "%s/%s",
|
|
|
|
path, attr_detach);
|
|
|
|
dbg("detach attribute path: %s", detach_attr_path);
|
|
|
|
|
|
|
|
ret = write_sysfs_attribute(detach_attr_path, buff, strlen(buff));
|
2011-05-14 17:55:07 +07:00
|
|
|
if (ret < 0) {
|
2014-03-08 19:53:28 +07:00
|
|
|
dbg("write_sysfs_attribute failed");
|
2011-05-14 17:55:07 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-20 12:44:38 +07:00
|
|
|
dbg("detached port: %d", port);
|
2011-05-14 17:55:07 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-08 02:05:56 +07:00
|
|
|
|
|
|
|
int usbip_vhci_imported_device_dump(struct usbip_imported_device *idev)
|
|
|
|
{
|
|
|
|
char product_name[100];
|
|
|
|
char host[NI_MAXHOST] = "unknown host";
|
|
|
|
char serv[NI_MAXSERV] = "unknown port";
|
|
|
|
char remote_busid[SYSFS_BUS_ID_SIZE];
|
|
|
|
int ret;
|
|
|
|
int read_record_error = 0;
|
|
|
|
|
|
|
|
if (idev->status == VDEV_ST_NULL || idev->status == VDEV_ST_NOTASSIGNED)
|
|
|
|
return 0;
|
|
|
|
|
2014-02-13 09:47:56 +07:00
|
|
|
ret = read_record(idev->port, host, sizeof(host), serv, sizeof(serv),
|
|
|
|
remote_busid);
|
2014-01-08 02:05:56 +07:00
|
|
|
if (ret) {
|
|
|
|
err("read_record");
|
|
|
|
read_record_error = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Port %02d: <%s> at %s\n", idev->port,
|
|
|
|
usbip_status_string(idev->status),
|
|
|
|
usbip_speed_string(idev->udev.speed));
|
|
|
|
|
|
|
|
usbip_names_get_product(product_name, sizeof(product_name),
|
|
|
|
idev->udev.idVendor, idev->udev.idProduct);
|
|
|
|
|
|
|
|
printf(" %s\n", product_name);
|
|
|
|
|
|
|
|
if (!read_record_error) {
|
|
|
|
printf("%10s -> usbip://%s:%s/%s\n", idev->udev.busid,
|
|
|
|
host, serv, remote_busid);
|
|
|
|
printf("%10s -> remote bus/dev %03d/%03d\n", " ",
|
|
|
|
idev->busnum, idev->devnum);
|
|
|
|
} else {
|
|
|
|
printf("%10s -> unknown host, remote port and remote busid\n",
|
|
|
|
idev->udev.busid);
|
|
|
|
printf("%10s -> remote bus/dev %03d/%03d\n", " ",
|
|
|
|
idev->busnum, idev->devnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|