Skip to content

Commit

Permalink
usb: gadget: push iSerialNumber into gadgets
Browse files Browse the repository at this point in the history
This patch pushes the iSerialNumber module argument from composite into
each gadget. Once the user uses the module paramter, the string is
overwritten with the final value.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Sep 10, 2012
1 parent 276e2e4 commit 1cf0d26
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
20 changes: 13 additions & 7 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ static char *iProduct;
module_param(iProduct, charp, S_IRUGO);
MODULE_PARM_DESC(iProduct, "USB Product string");

static char *iSerialNumber;
module_param(iSerialNumber, charp, S_IRUGO);
MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");

static char composite_manufacturer[50];

/*-------------------------------------------------------------------------*/
Expand Down Expand Up @@ -925,7 +921,7 @@ static int get_string(struct usb_composite_dev *cdev,
else if (cdev->product_override == id)
str = iProduct ?: composite->iProduct;
else if (cdev->serial_override == id)
str = iSerialNumber ?: composite->iSerialNumber;
str = composite->iSerialNumber;
else
str = NULL;
if (str) {
Expand Down Expand Up @@ -1411,6 +1407,7 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
__le16 idVendor;
__le16 idProduct;
__le16 bcdDevice;
u8 iSerialNumber;

/*
* these variables may have been set in
Expand All @@ -1419,6 +1416,7 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
idVendor = new->idVendor;
idProduct = new->idProduct;
bcdDevice = new->bcdDevice;
iSerialNumber = new->iSerialNumber;

*new = *old;
if (idVendor)
Expand All @@ -1427,6 +1425,8 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
new->idProduct = idProduct;
if (bcdDevice)
new->bcdDevice = bcdDevice;
if (iSerialNumber)
new->iSerialNumber = iSerialNumber;
}

static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv)
Expand Down Expand Up @@ -1505,8 +1505,7 @@ static int composite_bind(struct usb_gadget *gadget,
cdev->product_override =
override_id(cdev, &cdev->desc.iProduct);

if (iSerialNumber ||
(!cdev->desc.iSerialNumber && composite->iSerialNumber))
if (composite->iSerialNumber)
cdev->serial_override =
override_id(cdev, &cdev->desc.iSerialNumber);

Expand Down Expand Up @@ -1691,6 +1690,8 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
struct usb_composite_overwrite *covr)
{
struct usb_device_descriptor *desc = &cdev->desc;
struct usb_gadget_strings *gstr = cdev->driver->strings[0];
struct usb_string *dev_str = gstr->strings;

if (covr->idVendor)
desc->idVendor = cpu_to_le16(covr->idVendor);
Expand All @@ -1700,4 +1701,9 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,

if (covr->bcdDevice)
desc->bcdDevice = cpu_to_le16(covr->bcdDevice);

if (covr->serial_number) {
desc->iSerialNumber = dev_str[USB_GADGET_SERIAL_IDX].id;
dev_str[USB_GADGET_SERIAL_IDX].s = covr->serial_number;
}
}
21 changes: 21 additions & 0 deletions drivers/usb/gadget/mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ static const struct usb_descriptor_header *otg_desc[] = {
NULL,
};

static struct usb_string strings_dev[] = {
[USB_GADGET_MANUFACTURER_IDX].s = "",
[USB_GADGET_PRODUCT_IDX].s = "",
[USB_GADGET_SERIAL_IDX].s = "",
{ } /* end of list */
};

static struct usb_gadget_strings stringtab_dev = {
.language = 0x0409, /* en-us */
.strings = strings_dev,
};

static struct usb_gadget_strings *dev_strings[] = {
&stringtab_dev,
NULL,
};

/****************************** Configurations ******************************/

Expand Down Expand Up @@ -141,6 +157,10 @@ static int __init msg_bind(struct usb_composite_dev *cdev)
{
int status;

status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0)
return status;

status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
if (status < 0)
return status;
Expand All @@ -160,6 +180,7 @@ static __refdata struct usb_composite_driver msg_driver = {
.iProduct = DRIVER_DESC,
.max_speed = USB_SPEED_SUPER,
.needs_serial = 1,
.strings = dev_strings,
.bind = msg_bind,
};

Expand Down
6 changes: 1 addition & 5 deletions drivers/usb/gadget/printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ static struct printer_dev usb_printer_gadget;
* parameters are in UTF-8 (superset of ASCII's 7 bit characters).
*/

static char *iSerialNum;
module_param(iSerialNum, charp, S_IRUGO);
module_param_named(iSerialNum, coverwrite.serial_number, charp, S_IRUGO);
MODULE_PARM_DESC(iSerialNum, "1");

static char *iPNPstring;
Expand Down Expand Up @@ -1170,9 +1169,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
init_utsname()->sysname, init_utsname()->release,
gadget->name);

if (iSerialNum)
strlcpy(serial_num, iSerialNum, sizeof serial_num);

if (iPNPstring)
strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);

Expand Down
7 changes: 6 additions & 1 deletion include/linux/usb/composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ struct usb_composite_overwrite {
u16 idVendor;
u16 idProduct;
u16 bcdDevice;
char *serial_number;
};
#define USB_GADGET_COMPOSITE_OPTIONS() \
static struct usb_composite_overwrite coverwrite; \
Expand All @@ -411,7 +412,11 @@ struct usb_composite_overwrite {
MODULE_PARM_DESC(idProduct, "USB Product ID"); \
\
module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \
MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)")
MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); \
\
module_param_named(iSerialNumber, coverwrite.serial_number, charp, \
S_IRUGO); \
MODULE_PARM_DESC(iSerialNumber, "SerialNumber string")

void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
struct usb_composite_overwrite *covr);
Expand Down

0 comments on commit 1cf0d26

Please sign in to comment.