MFp4 //depot/projects/usb@157974
Add support for setting and getting the USB template value through libusb20 and usbconfig. Submitted by: Hans Petter Selasky
This commit is contained in:
parent
e280503373
commit
f78fa6b67e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=188987
@ -698,6 +698,30 @@ returned.
|
|||||||
.
|
.
|
||||||
.Sh USB BACKEND OPERATIONS
|
.Sh USB BACKEND OPERATIONS
|
||||||
.
|
.
|
||||||
|
.Fn libusb20_be_get_template pbackend ptemp
|
||||||
|
This function will return the currently selected global USB device
|
||||||
|
side mode template into the integer pointer
|
||||||
|
.Fa ptemp .
|
||||||
|
This function returns zero on success else a LIBUSB20_ERROR value is
|
||||||
|
returned.
|
||||||
|
.
|
||||||
|
.Pp
|
||||||
|
.
|
||||||
|
.Fn libusb20_be_set_template pbackend temp
|
||||||
|
This function will set the global USB device side mode template to
|
||||||
|
.Fa temp .
|
||||||
|
The new template is not activated until after the next USB
|
||||||
|
enumeration.
|
||||||
|
The template number decides how the USB device will present itself to
|
||||||
|
the USB Host, like Mass Storage Device, USB Ethernet Device. Also see
|
||||||
|
the
|
||||||
|
.Xr usb2_template 4
|
||||||
|
module.
|
||||||
|
This function returns zero on success else a LIBUSB20_ERROR value is
|
||||||
|
returned.
|
||||||
|
.
|
||||||
|
.Pp
|
||||||
|
.
|
||||||
.Fn libusb20_be_get_dev_quirk pbackend index pquirk
|
.Fn libusb20_be_get_dev_quirk pbackend index pquirk
|
||||||
This function will return the device quirk according to
|
This function will return the device quirk according to
|
||||||
.Fa index
|
.Fa index
|
||||||
|
@ -1165,6 +1165,23 @@ libusb20_be_get_perm(struct libusb20_backend *pbe, mode_t *mode)
|
|||||||
return (pbe->methods->root_get_perm(pbe, mode));
|
return (pbe->methods->root_get_perm(pbe, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
libusb20_be_set_template(struct libusb20_backend *pbe, int temp)
|
||||||
|
{
|
||||||
|
return (pbe->methods->root_set_template(pbe, temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
libusb20_be_get_template(struct libusb20_backend *pbe, int *ptemp)
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
if (ptemp == NULL)
|
||||||
|
ptemp = &temp;
|
||||||
|
|
||||||
|
return (pbe->methods->root_get_template(pbe, ptemp));
|
||||||
|
}
|
||||||
|
|
||||||
struct libusb20_device *
|
struct libusb20_device *
|
||||||
libusb20_be_device_foreach(struct libusb20_backend *pbe, struct libusb20_device *pdev)
|
libusb20_be_device_foreach(struct libusb20_backend *pbe, struct libusb20_device *pdev)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +70,8 @@ typedef int (libusb20_root_get_perm_t)(struct libusb20_backend *pbe, mode_t *mod
|
|||||||
typedef int (libusb20_root_set_owner_t)(struct libusb20_backend *pbe, uid_t user, gid_t group);
|
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 int (libusb20_root_set_perm_t)(struct libusb20_backend *pbe, mode_t mode);
|
||||||
typedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe);
|
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);
|
||||||
|
|
||||||
#define LIBUSB20_DEFINE(n,field) \
|
#define LIBUSB20_DEFINE(n,field) \
|
||||||
libusb20_##field##_t *field;
|
libusb20_##field##_t *field;
|
||||||
@ -105,6 +107,8 @@ typedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe);
|
|||||||
m(n, root_get_owner) \
|
m(n, root_get_owner) \
|
||||||
m(n, root_set_perm) \
|
m(n, root_set_perm) \
|
||||||
m(n, root_get_perm) \
|
m(n, root_get_perm) \
|
||||||
|
m(n, root_set_template) \
|
||||||
|
m(n, root_get_template) \
|
||||||
/* mandatory device methods */ \
|
/* mandatory device methods */ \
|
||||||
m(n, open_device) \
|
m(n, open_device) \
|
||||||
m(n, close_device) \
|
m(n, close_device) \
|
||||||
|
@ -72,6 +72,8 @@ static libusb20_root_set_owner_t ugen20_root_set_owner;
|
|||||||
static libusb20_root_get_owner_t ugen20_root_get_owner;
|
static libusb20_root_get_owner_t ugen20_root_get_owner;
|
||||||
static libusb20_root_set_perm_t ugen20_root_set_perm;
|
static libusb20_root_set_perm_t ugen20_root_set_perm;
|
||||||
static libusb20_root_get_perm_t ugen20_root_get_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;
|
||||||
|
|
||||||
const struct libusb20_backend_methods libusb20_ugen20_backend = {
|
const struct libusb20_backend_methods libusb20_ugen20_backend = {
|
||||||
LIBUSB20_BACKEND(LIBUSB20_DECLARE, ugen20)
|
LIBUSB20_BACKEND(LIBUSB20_DECLARE, ugen20)
|
||||||
@ -1179,3 +1181,15 @@ ugen20_root_get_perm(struct libusb20_backend *pbe, mode_t *mode)
|
|||||||
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, 0, 0, 0, 0,
|
return (ugen20_be_do_perm(USB_GET_ROOT_PERM, 0, 0, 0, 0,
|
||||||
NULL, NULL, mode));
|
NULL, NULL, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ugen20_root_set_template(struct libusb20_backend *pbe, int temp)
|
||||||
|
{
|
||||||
|
return (ugen20_be_ioctl(USB_SET_TEMPLATE, &temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ugen20_root_get_template(struct libusb20_backend *pbe, int *ptemp)
|
||||||
|
{
|
||||||
|
return (ugen20_be_ioctl(USB_GET_TEMPLATE, ptemp));
|
||||||
|
}
|
||||||
|
@ -1377,6 +1377,15 @@ usb2_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
|
|||||||
case USB_DEV_QUIRK_REMOVE:
|
case USB_DEV_QUIRK_REMOVE:
|
||||||
err = usb2_quirk_ioctl_p(cmd, data, fflag, td);
|
err = usb2_quirk_ioctl_p(cmd, data, fflag, td);
|
||||||
break;
|
break;
|
||||||
|
case USB_GET_TEMPLATE:
|
||||||
|
*(int *)data = usb2_template;
|
||||||
|
break;
|
||||||
|
case USB_SET_TEMPLATE:
|
||||||
|
err = priv_check(curthread, PRIV_ROOT);
|
||||||
|
if (err)
|
||||||
|
break;
|
||||||
|
usb2_template = *(int *)data;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
err = ENOTTY;
|
err = ENOTTY;
|
||||||
break;
|
break;
|
||||||
|
@ -155,6 +155,10 @@ struct usb2_device {
|
|||||||
char product[64]; /* product string */
|
char product[64]; /* product string */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* globals */
|
||||||
|
|
||||||
|
extern int usb2_template;
|
||||||
|
|
||||||
/* function prototypes */
|
/* function prototypes */
|
||||||
|
|
||||||
struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
|
struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
|
||||||
|
@ -267,6 +267,8 @@ struct usb2_gen_quirk {
|
|||||||
#define USB_SET_PORT_DISABLE _IOW ('U', 144, int)
|
#define USB_SET_PORT_DISABLE _IOW ('U', 144, int)
|
||||||
#define USB_SET_POWER_MODE _IOW ('U', 145, int)
|
#define USB_SET_POWER_MODE _IOW ('U', 145, int)
|
||||||
#define USB_GET_POWER_MODE _IOR ('U', 146, int)
|
#define USB_GET_POWER_MODE _IOR ('U', 146, int)
|
||||||
|
#define USB_SET_TEMPLATE _IOW ('U', 147, int)
|
||||||
|
#define USB_GET_TEMPLATE _IOR ('U', 148, int)
|
||||||
|
|
||||||
/* Modem device */
|
/* Modem device */
|
||||||
#define USB_GET_CM_OVER_DATA _IOR ('U', 180, int)
|
#define USB_GET_CM_OVER_DATA _IOR ('U', 180, int)
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
struct options {
|
struct options {
|
||||||
const char *quirkname;
|
const char *quirkname;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
|
int template;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
@ -65,6 +66,8 @@ struct options {
|
|||||||
uint8_t got_set_alt:1;
|
uint8_t got_set_alt:1;
|
||||||
uint8_t got_set_owner:1;
|
uint8_t got_set_owner:1;
|
||||||
uint8_t got_set_perm:1;
|
uint8_t got_set_perm:1;
|
||||||
|
uint8_t got_set_template:1;
|
||||||
|
uint8_t got_get_template:1;
|
||||||
uint8_t got_suspend:1;
|
uint8_t got_suspend:1;
|
||||||
uint8_t got_resume:1;
|
uint8_t got_resume:1;
|
||||||
uint8_t got_reset:1;
|
uint8_t got_reset:1;
|
||||||
@ -99,6 +102,8 @@ enum {
|
|||||||
T_SET_ALT,
|
T_SET_ALT,
|
||||||
T_SET_OWNER,
|
T_SET_OWNER,
|
||||||
T_SET_PERM,
|
T_SET_PERM,
|
||||||
|
T_SET_TEMPLATE,
|
||||||
|
T_GET_TEMPLATE,
|
||||||
T_ADD_DEVICE_QUIRK,
|
T_ADD_DEVICE_QUIRK,
|
||||||
T_REMOVE_DEVICE_QUIRK,
|
T_REMOVE_DEVICE_QUIRK,
|
||||||
T_SHOW_IFACE_DRIVER,
|
T_SHOW_IFACE_DRIVER,
|
||||||
@ -130,6 +135,8 @@ static const struct token token[] = {
|
|||||||
{"set_alt", T_SET_ALT, 1},
|
{"set_alt", T_SET_ALT, 1},
|
||||||
{"set_owner", T_SET_OWNER, 1},
|
{"set_owner", T_SET_OWNER, 1},
|
||||||
{"set_perm", T_SET_PERM, 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},
|
{"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5},
|
||||||
{"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5},
|
{"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5},
|
||||||
{"dump_quirk_names", T_DUMP_QUIRK_NAMES, 0},
|
{"dump_quirk_names", T_DUMP_QUIRK_NAMES, 0},
|
||||||
@ -283,6 +290,8 @@ usage(void)
|
|||||||
" set_alt <alt_index>" "\n"
|
" set_alt <alt_index>" "\n"
|
||||||
" set_owner <user:group>" "\n"
|
" set_owner <user:group>" "\n"
|
||||||
" set_perm <mode>" "\n"
|
" set_perm <mode>" "\n"
|
||||||
|
" set_template <template>" "\n"
|
||||||
|
" get_template" "\n"
|
||||||
" add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
|
" add_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
|
||||||
" remove_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
|
" remove_dev_quirk_vplh <vid> <pid> <lo_rev> <hi_rev> <quirk>" "\n"
|
||||||
" dump_quirk_names" "\n"
|
" dump_quirk_names" "\n"
|
||||||
@ -358,6 +367,20 @@ flush_command(struct libusb20_backend *pbe, struct options *opt)
|
|||||||
be_dev_add_quirk(pbe,
|
be_dev_add_quirk(pbe,
|
||||||
opt->vid, opt->pid, opt->lo_rev, opt->hi_rev, opt->quirkname);
|
opt->vid, opt->pid, opt->lo_rev, opt->hi_rev, opt->quirkname);
|
||||||
}
|
}
|
||||||
|
if (opt->got_set_template) {
|
||||||
|
opt->got_any--;
|
||||||
|
if (libusb20_be_set_template(pbe, opt->template)) {
|
||||||
|
printf("Setting USB template %u failed, "
|
||||||
|
"continuing.\n", opt->template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (opt->got_get_template) {
|
||||||
|
opt->got_any--;
|
||||||
|
if (libusb20_be_get_template(pbe, &opt->template))
|
||||||
|
printf("USB template: <unknown>\n");
|
||||||
|
else
|
||||||
|
printf("USB template: %u\n", opt->template);
|
||||||
|
}
|
||||||
if (opt->got_any == 0) {
|
if (opt->got_any == 0) {
|
||||||
/*
|
/*
|
||||||
* do not scan through all the devices if there are no valid
|
* do not scan through all the devices if there are no valid
|
||||||
@ -691,6 +714,16 @@ main(int argc, char **argv)
|
|||||||
opt->got_any++;
|
opt->got_any++;
|
||||||
n++;
|
n++;
|
||||||
break;
|
break;
|
||||||
|
case T_SET_TEMPLATE:
|
||||||
|
opt->template = a_mode(argv[n + 1]);
|
||||||
|
opt->got_set_template = 1;
|
||||||
|
opt->got_any++;
|
||||||
|
n++;
|
||||||
|
break;
|
||||||
|
case T_GET_TEMPLATE:
|
||||||
|
opt->got_get_template = 1;
|
||||||
|
opt->got_any++;
|
||||||
|
break;
|
||||||
case T_DUMP_DEVICE_DESC:
|
case T_DUMP_DEVICE_DESC:
|
||||||
opt->got_dump_device_desc = 1;
|
opt->got_dump_device_desc = 1;
|
||||||
opt->got_any++;
|
opt->got_any++;
|
||||||
|
Loading…
Reference in New Issue
Block a user