/*
* USB device properties and persistent device path
*
* Copyright (c) 2005 SUSE Linux Products GmbH, Germany
* Author: Hannes Reinecke <hare@suse.de>
*
* Copyright (C) 2005-2011 Kay Sievers <kay@vrfy.org>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "alloc-util.h"
#include "fd-util.h"
#include "string-util.h"
#include "udev.h"
switch (if_class_num) {
case 1:
type = "audio";
break;
case 2: /* CDC-Control */
break;
case 3:
type = "hid";
break;
case 5: /* Physical */
break;
case 6:
type = "media";
break;
case 7:
type = "printer";
break;
case 8:
type = "storage";
break;
case 9:
type = "hub";
break;
case 0x0a: /* CDC-Data */
break;
break;
case 0x0d: /* Content Security */
break;
case 0x0e:
type = "video";
break;
case 0xdc: /* Diagnostic Device */
break;
case 0xe0: /* Wireless Controller */
break;
case 0xfe: /* Application-specific */
break;
case 0xff: /* Vendor-specific */
break;
default:
break;
}
}
int type_num = 0;
char *eptr;
switch (type_num) {
case 1: /* RBC devices */
type = "rbc";
break;
case 2:
type = "atapi";
break;
case 3:
type = "tape";
break;
case 4: /* UFI */
type = "floppy";
break;
case 6: /* Transparent SPC-2 devices */
type = "scsi";
break;
default:
break;
}
}
return type_num;
}
int type_num;
char *eptr;
switch (type_num) {
case 0:
case 0xe:
type = "disk";
break;
case 1:
type = "tape";
break;
case 4:
case 7:
case 0xf:
type = "optical";
break;
case 5:
type = "cd";
break;
default:
break;
}
}
}
unsigned strpos = 0;
struct usb_interface_descriptor {
} _packed_;
return log_oom();
if (fd < 0)
return -EIO;
ifs_str[0] = '\0';
break;
continue;
continue;
continue;
strpos += 7;
}
if (strpos > 0) {
}
return 0;
}
/*
* A unique USB identification is generated like this:
*
* 1.) Get the USB device type from InterfaceClass and InterfaceSubClass
* 2.) If the device type is 'Mass-Storage/SPC-2' or 'Mass-Storage/RBC',
* use the SCSI vendor and model as USB-Vendor and USB-model.
* 3.) Otherwise, use the USB manufacturer and product as
* USB-Vendor and USB-model. Any non-printable characters
* in those strings will be skipped; a slash '/' will be converted
* into a full stop '.'.
* 4.) If that fails, too, we will use idVendor and idProduct
* as USB-Vendor and USB-model.
* 5.) The USB identification is the USB-vendor and USB-model
* string concatenated with an underscore '_'.
* 6.) If the device supplies a serial number, this number
* is concatenated with the identification with an underscore '_'.
*/
const char *vendor_id;
const char *product_id;
int if_class_num;
int protocol = 0;
size_t l;
char *s;
/* shortcut, if we are called directly for a "usb_device" type */
goto fallback;
}
/* usb interface directory */
if (dev_interface == NULL) {
log_debug("unable to access usb_interface device of '%s'",
return EXIT_FAILURE;
}
if (!if_class) {
log_debug("%s: cannot get bInterfaceClass attribute",
return EXIT_FAILURE;
}
if (if_class_num == 8) {
/* mass storage */
if (if_subclass != NULL)
} else {
}
log_debug("%s: if_class %d protocol %d",
/* usb device directory */
if (!dev_usb) {
log_debug("unable to find parent 'usb' device of '%s'",
return EXIT_FAILURE;
}
/* all interfaces of the device in a single string */
/* mass storage : SCSI or ATAPI */
/* get scsi device */
log_debug("unable to find parent 'scsi' device of '%s'",
goto fallback;
}
goto fallback;
}
/* Generic SPC-2 device */
if (!scsi_vendor) {
log_debug("%s: cannot get SCSI vendor attribute",
goto fallback;
}
if (!scsi_model) {
log_debug("%s: cannot get SCSI model attribute",
goto fallback;
}
if (!scsi_type) {
log_debug("%s: cannot get SCSI type attribute",
goto fallback;
}
if (!scsi_rev) {
log_debug("%s: cannot get SCSI revision attribute",
goto fallback;
}
/*
* some broken devices have the same identifiers
* for all luns, export the target:lun number
*/
}
/* fallback to USB vendor & device */
if (vendor_str[0] == '\0') {
if (!usb_vendor)
if (!usb_vendor) {
log_debug("No USB vendor information available");
return EXIT_FAILURE;
}
}
if (model_str[0] == '\0') {
if (!usb_model)
if (!usb_model)
return EXIT_FAILURE;
}
if (revision_str[0] == '\0') {
const char *usb_rev;
if (usb_rev) {
}
}
if (serial_str[0] == '\0') {
const char *usb_serial;
if (usb_serial) {
const unsigned char *p;
for (p = (unsigned char *)usb_serial; *p != '\0'; p++)
if (*p < 0x20 || *p > 0x7f || *p == ',') {
usb_serial = NULL;
break;
}
}
if (usb_serial) {
}
}
s = serial;
if (!isempty(serial_str))
if (!isempty(instance_str))
if (!isempty(serial_str))
if (!isempty(instance_str))
if (!isempty(packed_if_str))
return EXIT_SUCCESS;
}
.name = "usb_id",
.cmd = builtin_usb_id,
.help = "USB device properties",
.run_once = true,
};