Change USB over to make_dev() for all device nodes, previously it hooked into

the devfs clone handler to open the (invisible) devices on the fly.

The /dev entries are layed out as follows,

 /dev/usbctl      = master device
 /dev/usb/0.1.0.5 = usb device, (<bus>.<dev>.<iface>.<endpoint>)
 /dev/ugen0.1 -> usb/0.1.0.0 = ugen link to ctrl endpoint

This also removes the custom permissions model from USB.  Bump
__FreeBSD_version to 800066.

Submitted by:	rink (earlier version)
This commit is contained in:
Andrew Thompson 2009-02-27 17:27:16 +00:00
parent 2ebdf04225
commit ee3e3ff5c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189110
25 changed files with 643 additions and 1941 deletions

View File

@ -514,72 +514,6 @@ returned.
.
.Pp
.
.Fn libusb20_dev_set_owner pdev uid gid
This function will set the ownership of the given USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_set_perm pdev mode
This function will set the permissions of the given USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_set_iface_owner pdev iface_index uid gid
This function will set the ownership of the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_set_iface_perm pdev iface_index mode
This function will set the permissions of the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_get_owner pdev puid pgid
This function will retrieve the current USB device ownership.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_get_perm pdev pmode
This function will retrieve the current USB device permissions.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_get_iface_owner pdev iface_index puid pgid
This function will retrieve the current USB interface ownership for
the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_get_iface_perm pdev iface_index pmode
This function will retrieve the current USB interface permissions for
the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_dev_get_device_desc pdev
This function returns a pointer to the decoded and host endian version
of the device descriptor.
@ -663,39 +597,6 @@ A timeout value can be specified which is passed on to the
.Xr 2 poll
function.
.
.Sh USB BUS OPERATIONS
.
.Fn libusb20_bus_set_owner pbackend bus_index uid gid
This function will set the ownership for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_bus_set_perm pbackend bus_index mode
This function will set the permissions for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_bus_get_owner pbackend bus_index puid pgid
This function will retrieve the ownership for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_bus_get_perm pbackend bus_index pmode
This function will retrieve the permissions for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.
.Sh USB BACKEND OPERATIONS
.
.Fn libusb20_be_get_template pbackend ptemp
@ -772,47 +673,6 @@ returned.
If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
returned.
.
.Pp
.
.Fn libusb20_be_set_owner pbackend uid gid
This function will set the ownership for the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_be_set_perm pbackend mode
This function will set the permissions for the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_be_get_owner pbackend puid pgid
This function will retrieve the ownership of the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_be_get_perm pbackend pmode
This function will retrieve the permissions of the given backend.
.
.
This function returns zero on success else a LIBUSB20_ERROR value is
returned.
.
.Pp
.
.Fn libusb20_be_alloc pmethods
This is an internal function to allocate a USB backend.
.
.Pp
.Fn libusb20_be_alloc_default void
.Fn libusb20_be_alloc_freebsd void
.Fn libusb20_be_alloc_linux void
These functions are used to allocate a specific USB backend or the
operating system default USB backend. Allocating a backend is a way to

View File

@ -970,86 +970,6 @@ libusb20_dev_get_bus_number(struct libusb20_device *pdev)
return (pdev->bus_number);
}
int
libusb20_dev_set_owner(struct libusb20_device *pdev, uid_t user, gid_t group)
{
return (pdev->beMethods->dev_set_owner(pdev, user, group));
}
int
libusb20_dev_set_perm(struct libusb20_device *pdev, mode_t mode)
{
return (pdev->beMethods->dev_set_perm(pdev, mode));
}
int
libusb20_dev_set_iface_owner(struct libusb20_device *pdev,
uint8_t iface_index, uid_t user, gid_t group)
{
return (pdev->beMethods->dev_set_iface_owner(
pdev, iface_index, user, group));
}
int
libusb20_dev_set_iface_perm(struct libusb20_device *pdev,
uint8_t iface_index, mode_t mode)
{
return (pdev->beMethods->dev_set_iface_perm(
pdev, iface_index, mode));
}
int
libusb20_dev_get_owner(struct libusb20_device *pdev, uid_t *user, gid_t *group)
{
uid_t a;
gid_t b;
if (user == NULL)
user = &a;
if (group == NULL)
group = &b;
return (pdev->beMethods->dev_get_owner(pdev, user, group));
}
int
libusb20_dev_get_perm(struct libusb20_device *pdev, mode_t *mode)
{
mode_t a;
if (mode == NULL)
mode = &a;
return (pdev->beMethods->dev_get_perm(pdev, mode));
}
int
libusb20_dev_get_iface_owner(struct libusb20_device *pdev,
uint8_t iface_index, uid_t *user, gid_t *group)
{
uid_t a;
gid_t b;
if (user == NULL)
user = &a;
if (group == NULL)
group = &b;
return (pdev->beMethods->dev_get_iface_owner(
pdev, iface_index, user, group));
}
int
libusb20_dev_get_iface_perm(struct libusb20_device *pdev,
uint8_t iface_index, mode_t *mode)
{
mode_t a;
if (mode == NULL)
mode = &a;
return (pdev->beMethods->dev_get_iface_perm(
pdev, iface_index, mode));
}
int
libusb20_dev_get_iface_desc(struct libusb20_device *pdev,
uint8_t iface_index, char *buf, uint8_t len)
@ -1061,45 +981,6 @@ libusb20_dev_get_iface_desc(struct libusb20_device *pdev,
pdev, iface_index, buf, len));
}
/* USB bus operations */
int
libusb20_bus_set_owner(struct libusb20_backend *pbe,
uint8_t bus, uid_t user, gid_t group)
{
return (pbe->methods->bus_set_owner(pbe, bus, user, group));
}
int
libusb20_bus_set_perm(struct libusb20_backend *pbe, uint8_t bus, mode_t mode)
{
return (pbe->methods->bus_set_perm(pbe, bus, mode));
}
int
libusb20_bus_get_owner(struct libusb20_backend *pbe,
uint8_t bus, uid_t *user, gid_t *group)
{
uid_t a;
gid_t b;
if (user == NULL)
user = &a;
if (group == NULL)
group = &b;
return (pbe->methods->bus_get_owner(pbe, bus, user, group));
}
int
libusb20_bus_get_perm(struct libusb20_backend *pbe, uint8_t bus, mode_t *mode)
{
mode_t a;
if (mode == NULL)
mode = &a;
return (pbe->methods->bus_get_perm(pbe, bus, mode));
}
/* USB backend operations */
int
@ -1130,41 +1011,6 @@ libusb20_be_remove_dev_quirk(struct libusb20_backend *pbe,
return (pbe->methods->root_remove_dev_quirk(pbe, pq));
}
int
libusb20_be_set_owner(struct libusb20_backend *pbe, uid_t user, gid_t group)
{
return (pbe->methods->root_set_owner(pbe, user, group));
}
int
libusb20_be_set_perm(struct libusb20_backend *pbe, mode_t mode)
{
return (pbe->methods->root_set_perm(pbe, mode));
}
int
libusb20_be_get_owner(struct libusb20_backend *pbe, uid_t *user, gid_t *group)
{
uid_t a;
gid_t b;
if (user == NULL)
user = &a;
if (group == NULL)
group = &b;
return (pbe->methods->root_get_owner(pbe, user, group));
}
int
libusb20_be_get_perm(struct libusb20_backend *pbe, mode_t *mode)
{
mode_t a;
if (mode == NULL)
mode = &a;
return (pbe->methods->root_get_perm(pbe, mode));
}
int
libusb20_be_set_template(struct libusb20_backend *pbe, int temp)
{

View File

@ -253,14 +253,6 @@ int libusb20_dev_reset(struct libusb20_device *pdev);
int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode);
uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev);
int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
int libusb20_dev_set_owner(struct libusb20_device *pdev, uid_t user, gid_t group);
int libusb20_dev_set_perm(struct libusb20_device *pdev, mode_t mode);
int libusb20_dev_set_iface_owner(struct libusb20_device *pdev, uint8_t iface_index, uid_t user, gid_t group);
int libusb20_dev_set_iface_perm(struct libusb20_device *pdev, uint8_t iface_index, mode_t mode);
int libusb20_dev_get_owner(struct libusb20_device *pdev, uid_t *user, gid_t *group);
int libusb20_dev_get_perm(struct libusb20_device *pdev, mode_t *mode);
int libusb20_dev_get_iface_owner(struct libusb20_device *pdev, uint8_t iface_index, uid_t *user, gid_t *group);
int libusb20_dev_get_iface_perm(struct libusb20_device *pdev, uint8_t iface_index, mode_t *mode);
int libusb20_dev_get_info(struct libusb20_device *pdev, struct usb2_device_info *pinfo);
int libusb20_dev_get_iface_desc(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len);
@ -276,23 +268,12 @@ void libusb20_dev_free(struct libusb20_device *pdev);
void libusb20_dev_set_debug(struct libusb20_device *pdev, int debug);
void libusb20_dev_wait_process(struct libusb20_device *pdev, int timeout);
/* USB bus operations */
int libusb20_bus_set_owner(struct libusb20_backend *pbe, uint8_t bus, uid_t user, gid_t group);
int libusb20_bus_set_perm(struct libusb20_backend *pbe, uint8_t bus, mode_t mode);
int libusb20_bus_get_owner(struct libusb20_backend *pbe, uint8_t bus, uid_t *user, gid_t *group);
int libusb20_bus_get_perm(struct libusb20_backend *pbe, uint8_t bus, mode_t *mode);
/* USB global operations */
int libusb20_be_get_dev_quirk(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq);
int libusb20_be_get_quirk_name(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq);
int libusb20_be_add_dev_quirk(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
int libusb20_be_remove_dev_quirk(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
int libusb20_be_set_owner(struct libusb20_backend *be, uid_t user, gid_t group);
int libusb20_be_set_perm(struct libusb20_backend *be, mode_t mode);
int libusb20_be_get_owner(struct libusb20_backend *be, uid_t *user, gid_t *group);
int libusb20_be_get_perm(struct libusb20_backend *be, mode_t *mode);
/* USB backend operations */

View File

@ -48,27 +48,11 @@ typedef int (libusb20_root_get_dev_quirk_t)(struct libusb20_backend *pbe, uint16
typedef int (libusb20_root_get_quirk_name_t)(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq);
typedef int (libusb20_root_add_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
typedef int (libusb20_root_remove_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
typedef int (libusb20_bus_get_owner_t)(struct libusb20_backend *pbe, uint8_t bus, uid_t *user, gid_t *group);
typedef int (libusb20_bus_get_perm_t)(struct libusb20_backend *pbe, uint8_t bus, mode_t *mode);
typedef int (libusb20_bus_set_owner_t)(struct libusb20_backend *pbe, uint8_t bus, uid_t user, gid_t group);
typedef int (libusb20_bus_set_perm_t)(struct libusb20_backend *pbe, uint8_t bus, mode_t mode);
typedef int (libusb20_close_device_t)(struct libusb20_device *pdev);
typedef int (libusb20_dev_get_iface_owner_t)(struct libusb20_device *pdev, uint8_t iface_index, uid_t *user, gid_t *group);
typedef int (libusb20_dev_get_iface_perm_t)(struct libusb20_device *pdev, uint8_t iface_index, mode_t *mode);
typedef int (libusb20_dev_get_owner_t)(struct libusb20_device *pdev, uid_t *user, gid_t *group);
typedef int (libusb20_dev_get_perm_t)(struct libusb20_device *pdev, mode_t *mode);
typedef int (libusb20_dev_get_info_t)(struct libusb20_device *pdev, struct usb2_device_info *pinfo);
typedef int (libusb20_dev_get_iface_desc_t)(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len);
typedef int (libusb20_dev_set_iface_owner_t)(struct libusb20_device *pdev, uint8_t iface_index, uid_t user, gid_t group);
typedef int (libusb20_dev_set_iface_perm_t)(struct libusb20_device *pdev, uint8_t iface_index, mode_t mode);
typedef int (libusb20_dev_set_owner_t)(struct libusb20_device *pdev, uid_t user, gid_t group);
typedef int (libusb20_dev_set_perm_t)(struct libusb20_device *pdev, mode_t mode);
typedef int (libusb20_init_backend_t)(struct libusb20_backend *pbe);
typedef int (libusb20_open_device_t)(struct libusb20_device *pdev, uint16_t transfer_count_max);
typedef int (libusb20_root_get_owner_t)(struct libusb20_backend *pbe, uid_t *user, gid_t *group);
typedef int (libusb20_root_get_perm_t)(struct libusb20_backend *pbe, mode_t *mode);
typedef int (libusb20_root_set_owner_t)(struct libusb20_backend *pbe, uid_t user, gid_t group);
typedef int (libusb20_root_set_perm_t)(struct libusb20_backend *pbe, mode_t mode);
typedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe);
typedef int (libusb20_root_set_template_t)(struct libusb20_backend *pbe, int temp);
typedef int (libusb20_root_get_template_t)(struct libusb20_backend *pbe, int *ptemp);
@ -85,28 +69,12 @@ typedef int (libusb20_root_get_template_t)(struct libusb20_backend *pbe, int *pt
/* optional backend methods */ \
m(n, init_backend) \
m(n, exit_backend) \
m(n, bus_set_owner) \
m(n, bus_get_owner) \
m(n, bus_set_perm) \
m(n, bus_get_perm) \
m(n, dev_get_info) \
m(n, dev_get_iface_owner) \
m(n, dev_get_iface_perm) \
m(n, dev_get_iface_desc) \
m(n, dev_get_owner) \
m(n, dev_get_perm) \
m(n, dev_set_iface_owner) \
m(n, dev_set_iface_perm) \
m(n, dev_set_owner) \
m(n, dev_set_perm) \
m(n, root_get_dev_quirk) \
m(n, root_get_quirk_name) \
m(n, root_add_dev_quirk) \
m(n, root_remove_dev_quirk) \
m(n, root_set_owner) \
m(n, root_get_owner) \
m(n, root_set_perm) \
m(n, root_get_perm) \
m(n, root_set_template) \
m(n, root_get_template) \
/* mandatory device methods */ \

View File

@ -50,28 +50,12 @@ static libusb20_open_device_t ugen20_open_device;
static libusb20_close_device_t ugen20_close_device;
static libusb20_get_backend_name_t ugen20_get_backend_name;
static libusb20_exit_backend_t ugen20_exit_backend;
static libusb20_bus_set_owner_t ugen20_bus_set_owner;
static libusb20_bus_get_owner_t ugen20_bus_get_owner;
static libusb20_bus_set_perm_t ugen20_bus_set_perm;
static libusb20_bus_get_perm_t ugen20_bus_get_perm;
static libusb20_dev_get_iface_owner_t ugen20_dev_get_iface_owner;
static libusb20_dev_get_iface_perm_t ugen20_dev_get_iface_perm;
static libusb20_dev_get_owner_t ugen20_dev_get_owner;
static libusb20_dev_get_perm_t ugen20_dev_get_perm;
static libusb20_dev_get_iface_desc_t ugen20_dev_get_iface_desc;
static libusb20_dev_get_info_t ugen20_dev_get_info;
static libusb20_dev_set_iface_owner_t ugen20_dev_set_iface_owner;
static libusb20_dev_set_iface_perm_t ugen20_dev_set_iface_perm;
static libusb20_dev_set_owner_t ugen20_dev_set_owner;
static libusb20_dev_set_perm_t ugen20_dev_set_perm;
static libusb20_root_get_dev_quirk_t ugen20_root_get_dev_quirk;
static libusb20_root_get_quirk_name_t ugen20_root_get_quirk_name;
static libusb20_root_add_dev_quirk_t ugen20_root_add_dev_quirk;
static libusb20_root_remove_dev_quirk_t ugen20_root_remove_dev_quirk;
static libusb20_root_set_owner_t ugen20_root_set_owner;
static libusb20_root_get_owner_t ugen20_root_get_owner;
static libusb20_root_set_perm_t ugen20_root_set_perm;
static libusb20_root_get_perm_t ugen20_root_get_perm;
static libusb20_root_set_template_t ugen20_root_set_template;
static libusb20_root_get_template_t ugen20_root_get_template;
@ -152,7 +136,7 @@ ugen20_enumerate(struct libusb20_device *pdev, const char *id)
pdev->bus_number = ugen20_path_convert_one(&tmp);
pdev->device_address = ugen20_path_convert_one(&tmp);
snprintf(buf, sizeof(buf), "/dev/ugen%u.%u",
snprintf(buf, sizeof(buf), "/dev/" USB_GENERIC_NAME "%u.%u",
pdev->bus_number, pdev->device_address);
f = open(buf, O_RDWR);
@ -218,7 +202,7 @@ ugen20_enumerate(struct libusb20_device *pdev, const char *id)
/* generate a nice description for printout */
snprintf(pdev->usb_desc, sizeof(pdev->usb_desc),
"ugen%u.%u: <%s %s> at usbus%u", pdev->bus_number,
USB_GENERIC_NAME "%u.%u: <%s %s> at usbus%u", pdev->bus_number,
pdev->device_address, devinfo.udi_product,
devinfo.udi_vendor, pdev->bus_number);
@ -284,7 +268,7 @@ ugen20_init_backend(struct libusb20_backend *pbe)
memset(&state, 0, sizeof(state));
state.f = open("/dev/usb", O_RDONLY);
state.f = open("/dev/" USB_DEVICE_NAME, O_RDONLY);
if (state.f < 0)
return (LIBUSB20_ERROR_OTHER);
@ -379,7 +363,7 @@ ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
int g;
int error;
snprintf(buf, sizeof(buf), "/dev/ugen%u.%u",
snprintf(buf, sizeof(buf), "/dev/" USB_GENERIC_NAME "%u.%u",
pdev->bus_number, pdev->device_address);
/*
@ -873,7 +857,7 @@ ugen20_be_ioctl(uint32_t cmd, void *data)
int f;
int error;
f = open("/dev/usb", O_RDONLY);
f = open("/dev/" USB_DEVICE_NAME, O_RDONLY);
if (f < 0)
return (LIBUSB20_ERROR_OTHER);
error = ioctl(f, cmd, data);
@ -888,75 +872,6 @@ ugen20_be_ioctl(uint32_t cmd, void *data)
return (error);
}
static int
ugen20_be_do_perm(uint32_t get_cmd, uint32_t set_cmd, uint8_t bus,
uint8_t dev, uint8_t iface, uid_t *uid,
gid_t *gid, mode_t *mode)
{
struct usb2_dev_perm perm;
int error;
memset(&perm, 0, sizeof(perm));
perm.bus_index = bus;
perm.dev_index = dev;
perm.iface_index = iface;
error = ugen20_be_ioctl(get_cmd, &perm);
if (error)
return (error);
if (set_cmd == 0) {
if (uid)
*uid = perm.user_id;
if (gid)
*gid = perm.group_id;
if (mode)
*mode = perm.mode;
return (0);
}
if (uid)
perm.user_id = *uid;
if (gid)
perm.group_id = *gid;
if (mode)
perm.mode = *mode;
return (ugen20_be_ioctl(set_cmd, &perm));
}
static int
ugen20_bus_set_owner(struct libusb20_backend *pbe,
uint8_t bus, uid_t user, gid_t group)
{
return (ugen20_be_do_perm(USB_GET_BUS_PERM, USB_SET_BUS_PERM,
bus, 0, 0, &user, &group, NULL));
}
static int
ugen20_bus_get_owner(struct libusb20_backend *pbe, uint8_t bus,
uid_t *user, gid_t *group)
{
return (ugen20_be_do_perm(USB_GET_BUS_PERM, 0,
bus, 0, 0, user, group, NULL));
}
static int
ugen20_bus_set_perm(struct libusb20_backend *pbe,
uint8_t bus, mode_t mode)
{
return (ugen20_be_do_perm(USB_GET_BUS_PERM, USB_SET_BUS_PERM,
bus, 0, 0, NULL, NULL, &mode));
}
static int
ugen20_bus_get_perm(struct libusb20_backend *pbe,
uint8_t bus, mode_t *mode)
{
return (ugen20_be_do_perm(USB_GET_BUS_PERM, 0,
bus, 0, 0, NULL, NULL, mode));
}
static int
ugen20_dev_get_iface_desc(struct libusb20_device *pdev,
uint8_t iface_index, char *buf, uint8_t len)
@ -985,59 +900,6 @@ ugen20_dev_get_info(struct libusb20_device *pdev,
return (0);
}
static int
ugen20_dev_get_iface_owner(struct libusb20_device *pdev,
uint8_t iface_index, uid_t *user, gid_t *group)
{
return (ugen20_be_do_perm(USB_GET_IFACE_PERM, 0,
pdev->bus_number, pdev->device_address, iface_index,
user, group, NULL));
}
static int
ugen20_dev_get_iface_perm(struct libusb20_device *pdev,
uint8_t iface_index, mode_t *mode)
{
return (ugen20_be_do_perm(USB_GET_IFACE_PERM, 0,
pdev->bus_number, pdev->device_address, iface_index,
NULL, NULL, mode));
}
static int
ugen20_dev_get_owner(struct libusb20_device *pdev,
uid_t *user, gid_t *group)
{
return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, 0,
pdev->bus_number, pdev->device_address, 0,
user, group, NULL));
}
static int
ugen20_dev_get_perm(struct libusb20_device *pdev, mode_t *mode)
{
return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, 0,
pdev->bus_number, pdev->device_address, 0,
NULL, NULL, mode));
}
static int
ugen20_dev_set_iface_owner(struct libusb20_device *pdev,
uint8_t iface_index, uid_t user, gid_t group)
{
return (ugen20_be_do_perm(USB_GET_IFACE_PERM, USB_SET_IFACE_PERM,
pdev->bus_number, pdev->device_address, iface_index,
&user, &group, NULL));
}
static int
ugen20_dev_set_iface_perm(struct libusb20_device *pdev,
uint8_t iface_index, mode_t mode)
{
return (ugen20_be_do_perm(USB_GET_IFACE_PERM, USB_SET_IFACE_PERM,
pdev->bus_number, pdev->device_address, iface_index,
NULL, NULL, &mode));
}
static int
ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
uint16_t quirk_index, struct libusb20_quirk *pq)
@ -1136,52 +998,6 @@ ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
return (error);
}
static int
ugen20_dev_set_owner(struct libusb20_device *pdev,
uid_t user, gid_t group)
{
return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, USB_SET_DEVICE_PERM,
pdev->bus_number, pdev->device_address, 0,
&user, &group, NULL));
}
static int
ugen20_dev_set_perm(struct libusb20_device *pdev, mode_t mode)
{
return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, USB_SET_DEVICE_PERM,
pdev->bus_number, pdev->device_address, 0,
NULL, NULL, &mode));
}
static int
ugen20_root_set_owner(struct libusb20_backend *pbe,
uid_t user, gid_t group)
{
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, USB_SET_ROOT_PERM, 0, 0, 0,
&user, &group, NULL));
}
static int
ugen20_root_get_owner(struct libusb20_backend *pbe, uid_t *user, gid_t *group)
{
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, 0, 0, 0, 0,
user, group, NULL));
}
static int
ugen20_root_set_perm(struct libusb20_backend *pbe, mode_t mode)
{
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, USB_SET_ROOT_PERM, 0, 0, 0,
NULL, NULL, &mode));
}
static int
ugen20_root_get_perm(struct libusb20_backend *pbe, mode_t *mode)
{
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, 0, 0, 0, 0,
NULL, NULL, mode));
}
static int
ugen20_root_set_template(struct libusb20_backend *pbe, int temp)
{

View File

@ -379,9 +379,9 @@ static void umidi_start_read(struct usb2_fifo *);
static void umidi_stop_read(struct usb2_fifo *);
static void umidi_start_write(struct usb2_fifo *);
static void umidi_stop_write(struct usb2_fifo *);
static int umidi_open(struct usb2_fifo *, int, struct thread *);
static int umidi_ioctl(struct usb2_fifo *, u_long cmd, void *, int, struct thread *);
static void umidi_close(struct usb2_fifo *, int, struct thread *);
static int umidi_open(struct usb2_fifo *, int);
static int umidi_ioctl(struct usb2_fifo *, u_long cmd, void *, int);
static void umidi_close(struct usb2_fifo *, int);
static void umidi_init(device_t dev);
static int32_t umidi_probe(device_t dev);
static int32_t umidi_detach(device_t dev);
@ -3585,7 +3585,7 @@ umidi_stop_write(struct usb2_fifo *fifo)
}
static int
umidi_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
umidi_open(struct usb2_fifo *fifo, int fflags)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
@ -3617,7 +3617,7 @@ umidi_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
umidi_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
umidi_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & FREAD) {
usb2_fifo_free_buffer(fifo);
@ -3630,7 +3630,7 @@ umidi_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
static int
umidi_ioctl(struct usb2_fifo *fifo, u_long cmd, void *data,
int fflags, struct thread *td)
int fflags)
{
return (ENODEV);
}
@ -3684,9 +3684,6 @@ umidi_probe(device_t dev)
(chan->max_cable == 0)) {
chan->max_cable = UMIDI_CABLES_MAX;
}
/* set interface permissions */
usb2_set_iface_perm(sc->sc_udev, chan->iface_index,
UID_ROOT, GID_OPERATOR, 0644);
for (n = 0; n < chan->max_cable; n++) {
@ -3694,7 +3691,8 @@ umidi_probe(device_t dev)
error = usb2_fifo_attach(sc->sc_udev, chan, &chan->mtx,
&umidi_fifo_methods, &sub->fifo, unit, n,
chan->iface_index);
chan->iface_index,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}

View File

@ -211,13 +211,10 @@ ubtbcmfw_attach(device_t dev)
goto detach;
}
/* Set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&ubtbcmfw_fifo_methods, &sc->sc_fifo,
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex);
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error != 0) {
device_printf(dev, "could not attach fifo. %s\n",
usb2_errstr(error));
@ -369,7 +366,7 @@ ubtbcmfw_stop_write(struct usb2_fifo *fifo)
*/
static int
ubtbcmfw_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
ubtbcmfw_open(struct usb2_fifo *fifo, int fflags)
{
struct ubtbcmfw_softc *sc = fifo->priv_sc0;
struct usb2_xfer *xfer;
@ -398,7 +395,7 @@ ubtbcmfw_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
*/
static void
ubtbcmfw_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
ubtbcmfw_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & (FREAD | FWRITE))
usb2_fifo_free_buffer(fifo);
@ -410,7 +407,7 @@ ubtbcmfw_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
static int
ubtbcmfw_ioctl(struct usb2_fifo *fifo, u_long cmd, void *data,
int fflags, struct thread *td)
int fflags)
{
struct ubtbcmfw_softc *sc = fifo->priv_sc0;
int error = 0;

View File

@ -399,13 +399,11 @@ uscanner_attach(device_t dev)
"error=%s\n", usb2_errstr(error));
goto detach;
}
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&uscanner_fifo_methods, &sc->sc_fifo,
unit, 0 - 1, uaa->info.bIfaceIndex);
unit, 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}
@ -553,7 +551,7 @@ uscanner_write_clear_stall_callback(struct usb2_xfer *xfer)
* uscanner character device opening method.
*/
static int
uscanner_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
uscanner_open(struct usb2_fifo *fifo, int fflags)
{
struct uscanner_softc *sc;
@ -585,7 +583,7 @@ uscanner_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
uscanner_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
uscanner_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & (FREAD | FWRITE)) {
usb2_fifo_free_buffer(fifo);

View File

@ -447,7 +447,7 @@ uhid_set_report(struct uhid_softc *sc, uint8_t type,
}
static int
uhid_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
uhid_open(struct usb2_fifo *fifo, int fflags)
{
struct uhid_softc *sc = fifo->priv_sc0;
@ -474,7 +474,7 @@ uhid_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
uhid_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
uhid_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & (FREAD | FWRITE)) {
usb2_fifo_free_buffer(fifo);
@ -483,7 +483,7 @@ uhid_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
static int
uhid_ioctl(struct usb2_fifo *fifo, u_long cmd, void *addr,
int fflags, struct thread *td)
int fflags)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct usb2_gen_descriptor *ugd;
@ -734,13 +734,11 @@ uhid_attach(device_t dev)
sc->sc_fsize);
sc->sc_fsize = UHID_BSIZE;
}
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&uhid_fifo_methods, &sc->sc_fifo,
unit, 0 - 1, uaa->info.bIfaceIndex);
unit, 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}

View File

@ -583,13 +583,10 @@ ums_attach(device_t dev)
sc->sc_status.dy = 0;
sc->sc_status.dz = 0;
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
err = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&ums_fifo_methods, &sc->sc_fifo,
unit, 0 - 1, uaa->info.bIfaceIndex);
unit, 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (err) {
goto detach;
}
@ -697,7 +694,7 @@ ums_reset_buf(struct ums_softc *sc)
}
static int
ums_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
ums_open(struct usb2_fifo *fifo, int fflags)
{
struct ums_softc *sc = fifo->priv_sc0;
@ -724,7 +721,7 @@ ums_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
ums_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
ums_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & FREAD) {
usb2_fifo_free_buffer(fifo);
@ -732,8 +729,7 @@ ums_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static int
ums_ioctl(struct usb2_fifo *fifo, u_long cmd, void *addr,
int fflags, struct thread *td)
ums_ioctl(struct usb2_fifo *fifo, u_long cmd, void *addr, int fflags)
{
struct ums_softc *sc = fifo->priv_sc0;
mousemode_t mode;

View File

@ -139,13 +139,10 @@ ufm_attach(device_t dev)
device_set_usb2_desc(dev);
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&ufm_fifo_methods, &sc->sc_fifo,
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex);
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}
@ -169,7 +166,7 @@ ufm_detach(device_t dev)
}
static int
ufm_open(struct usb2_fifo *dev, int fflags, struct thread *td)
ufm_open(struct usb2_fifo *dev, int fflags)
{
if ((fflags & (FWRITE | FREAD)) != (FWRITE | FREAD)) {
return (EACCES);
@ -300,7 +297,7 @@ ufm_get_stat(struct ufm_softc *sc, void *addr)
static int
ufm_ioctl(struct usb2_fifo *fifo, u_long cmd, void *addr,
int fflags, struct thread *td)
int fflags)
{
struct ufm_softc *sc = fifo->priv_sc0;
int error = 0;

View File

@ -395,7 +395,7 @@ ulpt_stop_write(struct usb2_fifo *fifo)
}
static int
ulpt_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
ulpt_open(struct usb2_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
@ -404,11 +404,11 @@ ulpt_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
if (sc->sc_fflags == 0) {
ulpt_reset(sc);
}
return (unlpt_open(fifo, fflags, td));
return (unlpt_open(fifo, fflags));
}
static int
unlpt_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
unlpt_open(struct usb2_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
@ -446,7 +446,7 @@ unlpt_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
ulpt_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
ulpt_close(struct usb2_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
@ -459,7 +459,7 @@ ulpt_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
static int
ulpt_ioctl(struct usb2_fifo *fifo, u_long cmd, void *data,
int fflags, struct thread *td)
int fflags)
{
return (ENODEV);
}
@ -595,19 +595,17 @@ ulpt_attach(device_t dev)
}
#endif
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&ulpt_fifo_methods, &sc->sc_fifo,
unit, 0 - 1, uaa->info.bIfaceIndex);
unit, 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&unlpt_fifo_methods, &sc->sc_fifo_noreset,
unit, 0 - 1, uaa->info.bIfaceIndex);
unit, 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}

View File

@ -228,13 +228,11 @@ urio_attach(device_t dev)
DPRINTF("error=%s\n", usb2_errstr(error));
goto detach;
}
/* set interface permissions */
usb2_set_iface_perm(uaa->device, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx,
&urio_fifo_methods, &sc->sc_fifo,
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex);
device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex,
UID_ROOT, GID_OPERATOR, 0644);
if (error) {
goto detach;
}
@ -370,7 +368,7 @@ urio_stop_write(struct usb2_fifo *fifo)
}
static int
urio_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
urio_open(struct usb2_fifo *fifo, int fflags)
{
struct urio_softc *sc = fifo->priv_sc0;
@ -403,7 +401,7 @@ urio_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
}
static void
urio_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
urio_close(struct usb2_fifo *fifo, int fflags)
{
if (fflags & (FREAD | FWRITE)) {
usb2_fifo_free_buffer(fifo);
@ -412,7 +410,7 @@ urio_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
static int
urio_ioctl(struct usb2_fifo *fifo, u_long cmd, void *addr,
int fflags, struct thread *td)
int fflags)
{
struct usb2_ctl_request ur;
struct RioCommand *rio_cmd;

View File

@ -69,7 +69,6 @@ struct usb2_bus {
* This mutex protects the USB hardware:
*/
struct mtx bus_mtx;
struct usb2_perm perm;
struct usb2_xfer_queue intr_q;
struct usb2_callout power_wdog; /* power management */

View File

@ -177,16 +177,6 @@ typedef void (usb2_callback_t)(struct usb2_xfer *);
/* structures */
/*
* This structure contains permissions.
*/
struct usb2_perm {
uint32_t uid;
uint32_t gid;
uint16_t mode;
};
/*
* Common queue structure for USB transfers.
*/
@ -383,25 +373,6 @@ struct usb2_attach_arg {
uint8_t use_generic; /* hint for generic drivers */
};
/* Structure used when referring an USB device */
struct usb2_location {
struct usb2_bus *bus;
struct usb2_device *udev;
struct usb2_interface *iface;
struct usb2_fifo *rxfifo;
struct usb2_fifo *txfifo;
uint32_t devloc; /* original devloc */
uint16_t bus_index; /* bus index */
uint8_t dev_index; /* device index */
uint8_t iface_index; /* interface index */
uint8_t fifo_index; /* FIFO index */
uint8_t is_read; /* set if location has read access */
uint8_t is_write; /* set if location has write access */
uint8_t is_uref; /* set if USB refcount decr. needed */
uint8_t is_usbfs; /* set if USB-FS is active */
};
/* external variables */
MALLOC_DECLARE(M_USB);
@ -449,13 +420,8 @@ uint8_t usb2_transfer_pending(struct usb2_xfer *xfer);
void usb2_transfer_start(struct usb2_xfer *xfer);
void usb2_transfer_stop(struct usb2_xfer *xfer);
void usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup);
usb2_error_t usb2_ref_device(struct file *fp, struct usb2_location *ploc,
uint32_t devloc);
void usb2_unref_device(struct usb2_location *ploc);
void usb2_set_parent_iface(struct usb2_device *udev, uint8_t iface_index,
uint8_t parent_index);
void usb2_set_iface_perm(struct usb2_device *udev, uint8_t iface_index,
uint32_t uid, uint32_t gid, uint16_t mode);
uint8_t usb2_get_bus_index(struct usb2_device *udev);
uint8_t usb2_get_device_index(struct usb2_device *udev);
void usb2_set_power_mode(struct usb2_device *udev, uint8_t power_mode);

File diff suppressed because it is too large Load Diff

View File

@ -41,9 +41,9 @@
struct usb2_fifo;
struct usb2_mbuf;
typedef int (usb2_fifo_open_t)(struct usb2_fifo *fifo, int fflags, struct thread *td);
typedef void (usb2_fifo_close_t)(struct usb2_fifo *fifo, int fflags, struct thread *td);
typedef int (usb2_fifo_ioctl_t)(struct usb2_fifo *fifo, u_long cmd, void *addr, int fflags, struct thread *td);
typedef int (usb2_fifo_open_t)(struct usb2_fifo *fifo, int fflags);
typedef void (usb2_fifo_close_t)(struct usb2_fifo *fifo, int fflags);
typedef int (usb2_fifo_ioctl_t)(struct usb2_fifo *fifo, u_long cmd, void *addr, int fflags);
typedef void (usb2_fifo_cmd_t)(struct usb2_fifo *fifo);
typedef void (usb2_fifo_filter_t)(struct usb2_fifo *fifo, struct usb2_mbuf *m);
@ -81,6 +81,39 @@ struct usb2_fifo_methods {
const char *postfix[4];
};
/*
* Private per-device information.
*/
struct usb2_cdev_privdata {
struct usb2_bus *bus;
struct usb2_device *udev;
struct usb2_interface *iface;
struct usb2_fifo *rxfifo;
struct usb2_fifo *txfifo;
int bus_index; /* bus index */
int dev_index; /* device index */
int iface_index; /* interface index */
int ep_addr; /* endpoint address */
uint8_t fifo_index; /* FIFO index */
uint8_t is_read; /* location has read access */
uint8_t is_write; /* location has write access */
uint8_t is_uref; /* USB refcount decr. needed */
uint8_t is_usbfs; /* USB-FS is active */
int fflags;
};
struct usb2_fs_privdata {
int bus_index;
int dev_index;
int iface_index;
int ep_addr;
int mode;
int fifo_index;
struct cdev *cdev;
LIST_ENTRY(usb2_fs_privdata) pd_next;
};
/*
* Most of the fields in the "usb2_fifo" structure are used by the
* generic USB access layer.
@ -99,7 +132,7 @@ struct usb2_fifo {
struct usb2_xfer *xfer[2];
struct usb2_xfer **fs_xfer;
struct mtx *priv_mtx; /* client data */
struct file *curr_file; /* set if FIFO is opened by a FILE */
int opened; /* set if FIFO is opened by a FILE */
void *priv_sc0; /* client data */
void *priv_sc1; /* client data */
void *queue_data;
@ -126,8 +159,11 @@ struct usb2_fifo {
struct usb2_fifo_sc {
struct usb2_fifo *fp[2];
struct cdev* dev;
};
extern struct cdevsw usb2_devsw;
int usb2_fifo_wait(struct usb2_fifo *fifo);
void usb2_fifo_signal(struct usb2_fifo *fifo);
int usb2_fifo_alloc_buffer(struct usb2_fifo *f, uint32_t bufsize,
@ -136,7 +172,7 @@ void usb2_fifo_free_buffer(struct usb2_fifo *f);
int usb2_fifo_attach(struct usb2_device *udev, void *priv_sc,
struct mtx *priv_mtx, struct usb2_fifo_methods *pm,
struct usb2_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
uint8_t iface_index);
uint8_t iface_index, uid_t uid, gid_t gid, int mode);
void usb2_fifo_detach(struct usb2_fifo_sc *f_sc);
uint32_t usb2_fifo_put_bytes_max(struct usb2_fifo *fifo);
void usb2_fifo_put_data(struct usb2_fifo *fifo, struct usb2_page_cache *pc,
@ -155,13 +191,9 @@ void usb2_fifo_get_data_error(struct usb2_fifo *fifo);
uint8_t usb2_fifo_opened(struct usb2_fifo *fifo);
void usb2_fifo_free(struct usb2_fifo *f);
void usb2_fifo_reset(struct usb2_fifo *f);
int usb2_check_thread_perm(struct usb2_device *udev, struct thread *td,
int fflags, uint8_t iface_index, uint8_t ep_index);
void usb2_fifo_wakeup(struct usb2_fifo *f);
struct usb2_symlink *usb2_alloc_symlink(const char *target,
const char *fmt,...);
struct usb2_symlink *usb2_alloc_symlink(const char *target);
void usb2_free_symlink(struct usb2_symlink *ps);
uint32_t usb2_lookup_symlink(const char *src_ptr, uint8_t src_len);
int usb2_read_symlink(uint8_t *user_ptr, uint32_t startentry,
uint32_t user_len);

View File

@ -74,6 +74,10 @@ static usb2_error_t usb2_fill_iface_data(struct usb2_device *, uint8_t,
uint8_t);
static void usb2_notify_addq(const char *type, struct usb2_device *);
static void usb2_fifo_free_wrap(struct usb2_device *, uint8_t, uint8_t);
static struct cdev *usb2_make_dev(struct usb2_device *, int, int, int);
static void usb2_cdev_create(struct usb2_device *);
static void usb2_cdev_free(struct usb2_device *);
static void usb2_cdev_cleanup(void *);
/* This variable is global to allow easy access to it: */
@ -274,6 +278,7 @@ static void
usb2_fill_pipe_data(struct usb2_device *udev, uint8_t iface_index,
struct usb2_endpoint_descriptor *edesc, struct usb2_pipe *pipe)
{
bzero(pipe, sizeof(*pipe));
(udev->bus->methods->pipe_init) (udev, edesc, pipe);
@ -416,6 +421,7 @@ usb2_fill_iface_data(struct usb2_device *udev,
iface->idesc = id;
iface->alt_index = alt_index;
iface->parent_iface_index = USB_IFACE_INDEX_ANY;
iface->ep_in_mask = iface->ep_out_mask = 0;
nendpt = id->bNumEndpoints;
DPRINTFN(5, "found idesc nendpt=%d\n", nendpt);
@ -439,6 +445,14 @@ usb2_fill_iface_data(struct usb2_device *udev,
found:
ed = (void *)desc;
/* Fill in the endpoint bitmasks */
if (ed->bEndpointAddress & UE_DIR_IN)
iface->ep_in_mask |=
1 << UE_GET_ADDR(ed->bEndpointAddress);
else
iface->ep_out_mask |=
1 << UE_GET_ADDR(ed->bEndpointAddress);
/* find a free pipe */
while (pipe != pipe_end) {
if (pipe->edesc == NULL) {
@ -488,7 +502,6 @@ usb2_free_iface_data(struct usb2_device *udev)
iface->idesc = NULL;
iface->alt_index = 0;
iface->parent_iface_index = USB_IFACE_INDEX_ANY;
iface->perm.mode = 0; /* disable permissions */
iface++;
}
@ -543,6 +556,7 @@ usb2_set_config_index(struct usb2_device *udev, uint8_t index)
usb2_fifo_free_wrap(udev, USB_IFACE_INDEX_ANY, 0);
/* free all configuration data structures */
usb2_cdev_free(udev);
usb2_free_iface_data(udev);
if (index == USB_UNCONFIG_INDEX) {
@ -652,10 +666,13 @@ usb2_set_config_index(struct usb2_device *udev, uint8_t index)
goto done;
}
}
/* create device nodes for each endpoint */
usb2_cdev_create(udev);
done:
DPRINTF("error=%s\n", usb2_errstr(err));
if (err) {
usb2_cdev_free(udev);
usb2_free_iface_data(udev);
}
if (do_unlock) {
@ -713,6 +730,7 @@ usb2_set_alt_interface_index(struct usb2_device *udev,
* Free all generic FIFOs for this interface, except control
* endpoint FIFOs:
*/
usb2_cdev_free(udev);
usb2_fifo_free_wrap(udev, iface_index, 0);
err = usb2_fill_iface_data(udev, iface_index, alt_index);
@ -722,6 +740,9 @@ usb2_set_alt_interface_index(struct usb2_device *udev,
err = usb2_req_set_alt_interface_no(udev, NULL, iface_index,
iface->idesc->bAlternateSetting);
/* create device nodes for each endpoint */
usb2_cdev_create(udev);
done:
if (do_unlock) {
sx_unlock(udev->default_sx + 1);
@ -1354,6 +1375,8 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
usb2_cv_init(udev->default_cv, "WCTRL");
usb2_cv_init(udev->default_cv + 1, "UGONE");
LIST_INIT(&udev->pd_list);
/* initialise our mutex */
mtx_init(udev->default_mtx, "USB device mutex", NULL, MTX_DEF);
@ -1423,6 +1446,14 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
/* set device index */
udev->device_index = device_index;
/* Create the control endpoint device */
udev->default_dev = usb2_make_dev(udev, 0 , 0, FREAD|FWRITE);
/* Create a link from /dev/ugenX.X to the default endpoint */
snprintf(udev->ugen_name, sizeof(udev->ugen_name),
USB_GENERIC_NAME "%u.%u", device_get_unit(bus->bdev),
device_index);
make_dev_alias(udev->default_dev, udev->ugen_name);
if (udev->flags.usb2_mode == USB_MODE_HOST) {
err = usb2_req_set_address(udev, NULL, device_index);
@ -1673,21 +1704,9 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
usb2_bus_port_set_device(bus, parent_hub ?
parent_hub->hub->ports + port_index : NULL, udev, device_index);
/* make a symlink for UGEN */
if (snprintf((char *)scratch_ptr, scratch_size,
USB_DEVICE_NAME "%u.%u.0.0",
device_get_unit(udev->bus->bdev),
udev->device_index)) {
/* ignore */
}
udev->ugen_symlink =
usb2_alloc_symlink((char *)scratch_ptr, "ugen%u.%u",
device_get_unit(udev->bus->bdev),
udev->device_index);
printf("ugen%u.%u: <%s> at %s\n",
device_get_unit(udev->bus->bdev),
udev->device_index, udev->manufacturer,
/* Link and announce the ugen device name */
udev->ugen_symlink = usb2_alloc_symlink(udev->ugen_name);
printf("%s: <%s> at %s\n", udev->ugen_name, udev->manufacturer,
device_get_nameunit(udev->bus->bdev));
usb2_notify_addq("+", udev);
@ -1700,6 +1719,100 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
return (udev);
}
static struct cdev *
usb2_make_dev(struct usb2_device *udev, int iface_index, int ep, int mode)
{
struct usb2_fs_privdata* pd;
char devname[20];
/* Store information to locate ourselves again later */
pd = malloc(sizeof(struct usb2_fs_privdata), M_USBDEV,
M_WAITOK | M_ZERO);
pd->bus_index = device_get_unit(udev->bus->bdev);
pd->dev_index = udev->device_index;
pd->iface_index = iface_index;
pd->ep_addr = ep;
pd->mode = mode;
/* Now, create the device itself */
snprintf(devname, sizeof(devname), "%u.%u.%u.%u",
pd->bus_index, pd->dev_index,
pd->iface_index, pd->ep_addr);
pd->cdev = make_dev(&usb2_devsw, 0, UID_ROOT,
GID_OPERATOR, 0600, USB_DEVICE_DIR "/%s", devname);
pd->cdev->si_drv1 = pd;
return (pd->cdev);
}
static void
usb2_cdev_create(struct usb2_device *udev)
{
struct usb2_interface *iface;
struct usb2_fs_privdata* pd;
struct cdev *dev;
uint8_t niface;
int i, ep, mode, inmode, outmode;
KASSERT(LIST_FIRST(&udev->pd_list) == NULL, ("stale cdev entries"));
DPRINTFN(2, "Creating device nodes\n");
usb2_interface_count(udev, &niface);
if (niface == 0)
return; /* nothing to do */
if (usb2_get_mode(udev) == USB_MODE_DEVICE) {
inmode = FWRITE;
outmode = FREAD;
} else { /* USB_MODE_HOST */
inmode = FREAD;
outmode = FWRITE;
}
for (i = 0; i < niface; i++) {
iface = usb2_get_iface(udev, i);
if (iface == NULL)
break;
/* Create all available endpoints except EP0 */
for (ep = 1; ep < 16; ep++) {
mode = 0;
mode |= iface->ep_in_mask & (1 << ep) ? inmode : 0;
mode |= iface->ep_out_mask & (1 << ep) ? outmode : 0;
if (mode == 0)
continue; /* no IN or OUT endpoint */
dev = usb2_make_dev(udev, i , ep, mode);
pd = dev->si_drv1;
LIST_INSERT_HEAD(&udev->pd_list, pd, pd_next);
}
}
}
static void
usb2_cdev_free(struct usb2_device *udev)
{
struct usb2_fs_privdata* pd;
DPRINTFN(2, "Freeing device nodes\n");
while ((pd = LIST_FIRST(&udev->pd_list)) != NULL) {
KASSERT(pd->cdev->si_drv1 == pd, ("privdata corrupt"));
KASSERT(pd->ep_addr > 0, ("freeing EP0"));
destroy_dev_sched_cb(pd->cdev, usb2_cdev_cleanup, pd);
pd->cdev = NULL;
LIST_REMOVE(pd, pd_next);
}
}
static void
usb2_cdev_cleanup(void* arg)
{
free(arg, M_USBDEV);
}
/*------------------------------------------------------------------------*
* usb2_free_device
*
@ -1708,26 +1821,16 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
void
usb2_free_device(struct usb2_device *udev)
{
struct usb2_bus *bus;
struct usb2_bus *bus = udev->bus;;
if (udev == NULL) {
/* already freed */
return;
}
DPRINTFN(4, "udev=%p port=%d\n", udev, udev->port_no);
usb2_notify_addq("-", udev);
bus = udev->bus;
printf("%s: <%s> at %s (disconnected)\n", udev->ugen_name,
udev->manufacturer, device_get_nameunit(bus->bdev));
printf("ugen%u.%u: <%s> at %s (disconnected)\n",
device_get_unit(bus->bdev),
udev->device_index, udev->manufacturer,
device_get_nameunit(bus->bdev));
/*
* Destroy UGEN symlink, if any
*/
/* Destroy UGEN symlink, if any */
if (udev->ugen_symlink) {
usb2_free_symlink(udev->ugen_symlink);
udev->ugen_symlink = NULL;
@ -1759,7 +1862,10 @@ usb2_free_device(struct usb2_device *udev)
/*
* Free all interface related data and FIFOs, if any.
*/
usb2_cdev_free(udev);
usb2_free_iface_data(udev);
destroy_dev_sched_cb(udev->default_dev, usb2_cdev_cleanup,
udev->default_dev->si_drv1);
/* unsetup any leftover default USB transfers */
usb2_transfer_unsetup(udev->default_xfer, USB_DEFAULT_XFER_MAX);
@ -1783,6 +1889,7 @@ usb2_free_device(struct usb2_device *udev)
usb2_cv_destroy(udev->default_cv + 1);
mtx_destroy(udev->default_mtx);
KASSERT(LIST_FIRST(&udev->pd_list) == NULL, ("leaked cdev entries"));
/* free device */
free(udev, M_USB);
@ -2112,7 +2219,7 @@ usb2_notify_addq(const char *type, struct usb2_device *udev)
if (udev->parent_hub) {
snprintf(data, 1024,
"%s"
"ugen%u.%u "
"%s "
"vendor=0x%04x "
"product=0x%04x "
"devclass=0x%02x "
@ -2121,22 +2228,20 @@ usb2_notify_addq(const char *type, struct usb2_device *udev)
"at "
"port=%u "
"on "
"ugen%u.%u\n",
"%s\n",
type,
device_get_unit(udev->bus->bdev),
udev->device_index,
udev->ugen_name,
UGETW(udev->ddesc.idVendor),
UGETW(udev->ddesc.idProduct),
udev->ddesc.bDeviceClass,
udev->ddesc.bDeviceSubClass,
udev->serial,
udev->port_no,
device_get_unit(udev->bus->bdev),
udev->parent_hub->device_index);
udev->parent_hub->ugen_name);
} else {
snprintf(data, 1024,
"%s"
"ugen%u.%u "
"%s "
"vendor=0x%04x "
"product=0x%04x "
"devclass=0x%02x "
@ -2146,8 +2251,7 @@ usb2_notify_addq(const char *type, struct usb2_device *udev)
"on "
"%s\n",
type,
device_get_unit(udev->bus->bdev),
udev->device_index,
udev->ugen_name,
UGETW(udev->ddesc.idVendor),
UGETW(udev->ddesc.idProduct),
udev->ddesc.bDeviceClass,

View File

@ -61,11 +61,12 @@ struct usb2_pipe {
* The following structure defines an USB interface.
*/
struct usb2_interface {
struct usb2_perm perm; /* interface permissions */
struct usb2_interface_descriptor *idesc;
device_t subdev;
uint8_t alt_index;
uint8_t parent_iface_index;
uint16_t ep_in_mask; /* bitmask of IN endpoints */
uint16_t ep_out_mask; /* bitmask of OUT endpoints */
};
/*
@ -101,12 +102,12 @@ struct usb2_power_save {
struct usb2_device {
struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall
* messages */
struct usb2_perm perm;
struct sx default_sx[2];
struct mtx default_mtx[1];
struct cv default_cv[2];
struct usb2_interface ifaces[USB_IFACE_MAX];
struct usb2_pipe default_pipe; /* Control Endpoint 0 */
struct cdev *default_dev; /* Control Endpoint 0 device node */
struct usb2_pipe pipes[USB_EP_MAX];
struct usb2_power_save pwr_save;/* power save data */
@ -120,10 +121,16 @@ struct usb2_device {
struct usb2_temp_data *usb2_template_ptr;
struct usb2_pipe *pipe_curr; /* current clear stall pipe */
struct usb2_fifo *fifo[USB_FIFO_MAX];
char ugen_name[20]; /* name of ugenX.X device */
struct usb2_symlink *ugen_symlink; /* our generic symlink */
LIST_HEAD(,usb2_fs_privdata) pd_list;
uint32_t plugtime; /* copy of "ticks" */
uint16_t ep_rd_opened; /* bitmask of endpoints opened */
uint16_t ep_wr_opened; /* from the device nodes. */
uint16_t refcount;
#define USB_DEV_REF_MAX 0xffff

View File

@ -149,7 +149,7 @@ ugen_transfer_setup(struct usb2_fifo *f,
}
static int
ugen_open(struct usb2_fifo *f, int fflags, struct thread *td)
ugen_open(struct usb2_fifo *f, int fflags)
{
struct usb2_pipe *pipe = f->priv_sc0;
struct usb2_endpoint_descriptor *ed = pipe->edesc;
@ -183,7 +183,7 @@ ugen_open(struct usb2_fifo *f, int fflags, struct thread *td)
}
static void
ugen_close(struct usb2_fifo *f, int fflags, struct thread *td)
ugen_close(struct usb2_fifo *f, int fflags)
{
DPRINTFN(6, "flag=0x%x\n", fflags);
@ -872,10 +872,6 @@ ugen_check_request(struct usb2_device *udev, struct usb2_device_request *req)
if (pipe == NULL) {
return (EINVAL);
}
if (usb2_check_thread_perm(udev, curthread, FREAD | FWRITE,
pipe->iface_index, req->wIndex[0] & UE_ADDR)) {
return (EPERM);
}
if ((req->bRequest == UR_CLEAR_FEATURE) &&
(UGETW(req->wValue) == UF_ENDPOINT_HALT)) {
usb2_clear_data_toggle(udev, pipe);
@ -1367,8 +1363,7 @@ ugen_fifo_in_use(struct usb2_fifo *f, int fflags)
}
static int
ugen_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags,
struct thread *td)
ugen_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
{
struct usb2_config usb2_config[1];
struct usb2_device_request req;
@ -1458,11 +1453,6 @@ ugen_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags,
}
iface_index = pipe->iface_index;
error = usb2_check_thread_perm(f->udev, curthread, fflags,
iface_index, u.popen->ep_no);
if (error) {
break;
}
bzero(usb2_config, sizeof(usb2_config));
usb2_config[0].type = ed->bmAttributes & UE_XFERTYPE;
@ -1948,8 +1938,7 @@ ugen_iface_ioctl(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
}
static int
ugen_ioctl_post(struct usb2_fifo *f, u_long cmd, void *addr, int fflags,
struct thread *td)
ugen_ioctl_post(struct usb2_fifo *f, u_long cmd, void *addr, int fflags)
{
union {
struct usb2_interface_descriptor *idesc;

View File

@ -36,7 +36,8 @@
#include <dev/usb/usb_endian.h>
#include <dev/usb/usb.h>
#define USB_DEVICE_NAME "usb"
#define USB_DEVICE_NAME "usbctl"
#define USB_DEVICE_DIR "usb"
#define USB_GENERIC_NAME "ugen"
struct usb2_read_dir {
@ -180,18 +181,6 @@ struct usb2_fs_clear_stall_sync {
uint8_t ep_index;
};
struct usb2_dev_perm {
/* Access information */
uint32_t user_id;
uint32_t group_id;
uint16_t mode;
/* Device location */
uint16_t bus_index;
uint16_t dev_index;
uint16_t iface_index;
};
struct usb2_gen_quirk {
uint16_t index; /* Quirk Index */
uint16_t vid; /* Vendor ID */
@ -248,14 +237,7 @@ struct usb2_gen_quirk {
#define USB_IFACE_DRIVER_DETACH _IOW ('U', 125, int)
#define USB_GET_PLUGTIME _IOR ('U', 126, uint32_t)
#define USB_READ_DIR _IOW ('U', 127, struct usb2_read_dir)
#define USB_SET_ROOT_PERM _IOW ('U', 128, struct usb2_dev_perm)
#define USB_SET_BUS_PERM _IOW ('U', 129, struct usb2_dev_perm)
#define USB_SET_DEVICE_PERM _IOW ('U', 130, struct usb2_dev_perm)
#define USB_SET_IFACE_PERM _IOW ('U', 131, struct usb2_dev_perm)
#define USB_GET_ROOT_PERM _IOWR('U', 132, struct usb2_dev_perm)
#define USB_GET_BUS_PERM _IOWR('U', 133, struct usb2_dev_perm)
#define USB_GET_DEVICE_PERM _IOWR('U', 134, struct usb2_dev_perm)
#define USB_GET_IFACE_PERM _IOWR('U', 135, struct usb2_dev_perm)
/* 128 - 135 unused */
#define USB_SET_TX_FORCE_SHORT _IOW ('U', 136, int)
#define USB_SET_TX_TIMEOUT _IOW ('U', 137, int)
#define USB_GET_TX_FRAME_SIZE _IOR ('U', 138, int)

View File

@ -57,7 +57,7 @@
* is created, otherwise 1.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 800065 /* Master, propagated to newvers */
#define __FreeBSD_version 800066 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>

View File

@ -262,107 +262,6 @@ dump_be_dev_quirks(struct libusb20_backend *pbe)
return;
}
void
dump_be_access(struct libusb20_backend *pbe)
{
struct group *gr;
struct passwd *pw;
const char *owner;
const char *group;
uid_t uid;
gid_t gid;
mode_t mode;
if (libusb20_be_get_owner(pbe, &uid, &gid)) {
err(1, "could not get owner");
}
if (libusb20_be_get_perm(pbe, &mode)) {
err(1, "could not get permission");
}
owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
if (mode || 1) {
printf("Global Access: %s:%s 0%o\n", owner, group, mode);
} else {
printf("Global Access: <not set>\n");
}
return;
}
void
dump_device_access(struct libusb20_device *pdev, uint8_t iface)
{
struct group *gr;
struct passwd *pw;
const char *owner;
const char *group;
uid_t uid;
gid_t gid;
mode_t mode;
if (libusb20_dev_get_owner(pdev, &uid, &gid)) {
err(1, "could not get owner");
}
if (libusb20_dev_get_perm(pdev, &mode)) {
err(1, "could not get permission");
}
if (mode) {
owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
printf(" " "Device Access: %s:%s 0%o\n", owner, group, mode);
} else {
printf(" " "Device Access: <not set>\n");
}
if (iface == 0xFF) {
for (iface = 0; iface != 0xFF; iface++) {
if (dump_device_iface_access(pdev, iface)) {
break;
}
}
} else {
if (dump_device_iface_access(pdev, iface)) {
err(1, "could not get interface access info");
}
}
return;
}
int
dump_device_iface_access(struct libusb20_device *pdev, uint8_t iface)
{
struct group *gr;
struct passwd *pw;
const char *owner;
const char *group;
uid_t uid;
gid_t gid;
mode_t mode;
int error;
if ((error = libusb20_dev_get_iface_owner(pdev, iface, &uid, &gid))) {
return (error);
}
if ((error = libusb20_dev_get_iface_perm(pdev, iface, &mode))) {
return (error);
}
if (mode) {
owner = (pw = getpwuid(uid)) ? pw->pw_name : "UNKNOWN";
group = (gr = getgrgid(gid)) ? gr->gr_name : "UNKNOWN";
printf(" " "Interface %u Access: %s:%s 0%o\n",
iface, owner, group, mode);
} else {
printf(" " "Interface %u Access: <not set>\n", iface);
}
return (0);
}
void
dump_device_desc(struct libusb20_device *pdev)
{

View File

@ -28,10 +28,7 @@ const char *dump_mode(uint8_t value);
const char *dump_speed(uint8_t value);
const char *dump_power_mode(uint8_t value);
void dump_device_info(struct libusb20_device *pdev, uint8_t show_drv);
void dump_be_access(struct libusb20_backend *pbe);
void dump_be_quirk_names(struct libusb20_backend *pbe);
void dump_be_dev_quirks(struct libusb20_backend *pbe);
void dump_device_access(struct libusb20_device *pdev, uint8_t iface);
int dump_device_iface_access(struct libusb20_device *pdev, uint8_t iface);
void dump_device_desc(struct libusb20_device *pdev);
void dump_config(struct libusb20_device *pdev, uint8_t all_cfg);

View File

@ -64,8 +64,6 @@ struct options {
uint8_t got_iface:1;
uint8_t got_set_config:1;
uint8_t got_set_alt:1;
uint8_t got_set_owner:1;
uint8_t got_set_perm:1;
uint8_t got_set_template:1;
uint8_t got_get_template:1;
uint8_t got_suspend:1;
@ -80,7 +78,6 @@ struct options {
uint8_t got_dump_curr_config:1;
uint8_t got_dump_all_config:1;
uint8_t got_dump_info:1;
uint8_t got_dump_access:1;
uint8_t got_show_iface_driver:1;
uint8_t got_remove_device_quirk:1;
uint8_t got_add_device_quirk:1;
@ -100,8 +97,6 @@ enum {
T_IFACE,
T_SET_CONFIG,
T_SET_ALT,
T_SET_OWNER,
T_SET_PERM,
T_SET_TEMPLATE,
T_GET_TEMPLATE,
T_ADD_DEVICE_QUIRK,
@ -113,7 +108,6 @@ enum {
T_DUMP_CURR_CONFIG_DESC,
T_DUMP_ALL_CONFIG_DESC,
T_DUMP_STRING,
T_DUMP_ACCESS,
T_DUMP_INFO,
T_SUSPEND,
T_RESUME,
@ -133,8 +127,6 @@ static const struct token token[] = {
{"-i", T_IFACE, 1},
{"set_config", T_SET_CONFIG, 1},
{"set_alt", T_SET_ALT, 1},
{"set_owner", T_SET_OWNER, 1},
{"set_perm", T_SET_PERM, 1},
{"set_template", T_SET_TEMPLATE, 1},
{"get_template", T_GET_TEMPLATE, 0},
{"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5},
@ -145,7 +137,6 @@ static const struct token token[] = {
{"dump_curr_config_desc", T_DUMP_CURR_CONFIG_DESC, 0},
{"dump_all_config_desc", T_DUMP_ALL_CONFIG_DESC, 0},
{"dump_string", T_DUMP_STRING, 1},
{"dump_access", T_DUMP_ACCESS, 0},
{"dump_info", T_DUMP_INFO, 0},
{"show_ifdrv", T_SHOW_IFACE_DRIVER, 0},
{"suspend", T_SUSPEND, 0},
@ -238,43 +229,19 @@ num_id(const char *name, const char *type)
return (val);
}
static gid_t
a_gid(const char *s)
static int
get_int(const char *s)
{
struct group *gr;
if (*s == '\0') {
/* empty group ID */
return ((gid_t)-1);
}
return ((gr = getgrnam(s)) ? gr->gr_gid : num_id(s, "group"));
}
static uid_t
a_uid(const char *s)
{
struct passwd *pw;
if (*s == '\0') {
/* empty user ID */
return ((uid_t)-1);
}
return ((pw = getpwnam(s)) ? pw->pw_uid : num_id(s, "user"));
}
static mode_t
a_mode(const char *s)
{
uint16_t val;
int val;
char *ep;
errno = 0;
val = strtoul(s, &ep, 8);
val = strtoul(s, &ep, 0);
if (errno) {
err(1, "%s", s);
}
if (*ep != '\0') {
errx(1, "illegal permissions: %s", s);
errx(1, "illegal number: %s", s);
}
return val;
}
@ -288,8 +255,6 @@ usage(void)
"commands:" "\n"
" set_config <cfg_index>" "\n"
" set_alt <alt_index>" "\n"
" set_owner <user:group>" "\n"
" set_perm <mode>" "\n"
" set_template <template>" "\n"
" get_template" "\n"
" add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
@ -300,7 +265,6 @@ usage(void)
" dump_curr_config_desc" "\n"
" dump_all_config_desc" "\n"
" dump_string <index>" "\n"
" dump_access" "\n"
" dump_info" "\n"
" show_ifdrv" "\n"
" suspend" "\n"
@ -345,10 +309,6 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
"'power_save', 'power_on' and 'power_off' "
"at the same time!");
}
if (opt->got_dump_access) {
opt->got_any--;
dump_be_access(pbe);
}
if (opt->got_dump_quirk_names) {
opt->got_any--;
dump_be_quirk_names(pbe);
@ -400,62 +360,6 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
}
matches++;
/* do owner and permissions first */
if (opt->got_bus && opt->got_addr && opt->got_iface) {
if (opt->got_set_owner) {
if (libusb20_dev_set_iface_owner(pdev,
opt->iface, opt->uid, opt->gid)) {
err(1, "setting owner and group failed\n");
}
}
if (opt->got_set_perm) {
if (libusb20_dev_set_iface_perm(pdev,
opt->iface, opt->mode)) {
err(1, "setting mode failed\n");
}
}
} else if (opt->got_bus && opt->got_addr) {
if (opt->got_set_owner) {
if (libusb20_dev_set_owner(pdev,
opt->uid, opt->gid)) {
err(1, "setting owner and group failed\n");
}
}
if (opt->got_set_perm) {
if (libusb20_dev_set_perm(pdev,
opt->mode)) {
err(1, "setting mode failed\n");
}
}
} else if (opt->got_bus) {
if (opt->got_set_owner) {
if (libusb20_bus_set_owner(pbe, opt->bus,
opt->uid, opt->gid)) {
err(1, "setting owner and group failed\n");
}
}
if (opt->got_set_perm) {
if (libusb20_bus_set_perm(pbe, opt->bus,
opt->mode)) {
err(1, "setting mode failed\n");
}
}
} else {
if (opt->got_set_owner) {
if (libusb20_be_set_owner(pbe,
opt->uid, opt->gid)) {
err(1, "setting owner and group failed\n");
}
}
if (opt->got_set_perm) {
if (libusb20_be_set_perm(pbe,
opt->mode)) {
err(1, "setting mode failed\n");
}
}
}
if (libusb20_dev_open(pdev, 0)) {
err(1, "could not open device");
}
@ -558,18 +462,12 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
(opt->got_dump_device_desc ||
opt->got_dump_curr_config ||
opt->got_dump_all_config ||
opt->got_dump_info ||
opt->got_dump_access);
opt->got_dump_info);
if (opt->got_list || dump_any) {
dump_device_info(pdev,
opt->got_show_iface_driver);
}
if (opt->got_dump_access) {
printf("\n");
dump_device_access(pdev, opt->got_iface ?
opt->iface : 0xFF);
}
if (opt->got_dump_device_desc) {
printf("\n");
dump_device_desc(pdev);
@ -695,27 +593,8 @@ main(int argc, char **argv)
opt->got_any++;
n++;
break;
case T_SET_OWNER:
cp = argv[n + 1];
cp = strchr(cp, ':');
if (cp == NULL) {
err(1, "missing colon in '%s'!", argv[n + 1]);
}
*(cp++) = '\0';
opt->gid = a_gid(cp);
opt->uid = a_uid(argv[n + 1]);
opt->got_set_owner = 1;
opt->got_any++;
n++;
break;
case T_SET_PERM:
opt->mode = a_mode(argv[n + 1]);
opt->got_set_perm = 1;
opt->got_any++;
n++;
break;
case T_SET_TEMPLATE:
opt->template = a_mode(argv[n + 1]);
opt->template = get_int(argv[n + 1]);
opt->got_set_template = 1;
opt->got_any++;
n++;
@ -749,10 +628,6 @@ main(int argc, char **argv)
opt->got_any++;
n++;
break;
case T_DUMP_ACCESS:
opt->got_dump_access = 1;
opt->got_any += 2;
break;
case T_SUSPEND:
opt->got_suspend = 1;
opt->got_any++;