diff options
author | Aras Vaichas <arasv@magellan-technology.com> | 2006-02-18 15:31:23 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-20 17:49:58 -0500 |
commit | 1afc64a3d68174fe524f11d92e045a30eacc927e (patch) | |
tree | 04b9889b1a606b27ed9d91923f09031ef566ab73 /drivers/usb | |
parent | 329af28b141ab4ae847aff1362864c4cc332641f (diff) |
[PATCH] USB: ethernet gadget driver section fixups
This patch allows you to set the iSerialNumber field in the
usb_device_descriptor structure for your USB ethernet gadget.
It also changes the parameters shown through sysfs so they're
no longer declared as __initdata, preventing potential oopses.
That's most useful for the Ethernet addresses, which may in
some cases be random "locally administered" addresses.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/ether.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 0d9d9bbb73f0..c3d8e5c5bf28 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -182,33 +182,37 @@ struct eth_dev { | |||
182 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). | 182 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). |
183 | */ | 183 | */ |
184 | 184 | ||
185 | static ushort __initdata idVendor; | 185 | static ushort idVendor; |
186 | module_param(idVendor, ushort, S_IRUGO); | 186 | module_param(idVendor, ushort, S_IRUGO); |
187 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); | 187 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); |
188 | 188 | ||
189 | static ushort __initdata idProduct; | 189 | static ushort idProduct; |
190 | module_param(idProduct, ushort, S_IRUGO); | 190 | module_param(idProduct, ushort, S_IRUGO); |
191 | MODULE_PARM_DESC(idProduct, "USB Product ID"); | 191 | MODULE_PARM_DESC(idProduct, "USB Product ID"); |
192 | 192 | ||
193 | static ushort __initdata bcdDevice; | 193 | static ushort bcdDevice; |
194 | module_param(bcdDevice, ushort, S_IRUGO); | 194 | module_param(bcdDevice, ushort, S_IRUGO); |
195 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); | 195 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); |
196 | 196 | ||
197 | static char *__initdata iManufacturer; | 197 | static char *iManufacturer; |
198 | module_param(iManufacturer, charp, S_IRUGO); | 198 | module_param(iManufacturer, charp, S_IRUGO); |
199 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); | 199 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); |
200 | 200 | ||
201 | static char *__initdata iProduct; | 201 | static char *iProduct; |
202 | module_param(iProduct, charp, S_IRUGO); | 202 | module_param(iProduct, charp, S_IRUGO); |
203 | MODULE_PARM_DESC(iProduct, "USB Product string"); | 203 | MODULE_PARM_DESC(iProduct, "USB Product string"); |
204 | 204 | ||
205 | static char *iSerialNumber; | ||
206 | module_param(iSerialNumber, charp, S_IRUGO); | ||
207 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber"); | ||
208 | |||
205 | /* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */ | 209 | /* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */ |
206 | static char *__initdata dev_addr; | 210 | static char *dev_addr; |
207 | module_param(dev_addr, charp, S_IRUGO); | 211 | module_param(dev_addr, charp, S_IRUGO); |
208 | MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); | 212 | MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); |
209 | 213 | ||
210 | /* this address is invisible to ifconfig */ | 214 | /* this address is invisible to ifconfig */ |
211 | static char *__initdata host_addr; | 215 | static char *host_addr; |
212 | module_param(host_addr, charp, S_IRUGO); | 216 | module_param(host_addr, charp, S_IRUGO); |
213 | MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); | 217 | MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); |
214 | 218 | ||
@@ -403,6 +407,7 @@ static inline int BITRATE(struct usb_gadget *g) | |||
403 | #define STRING_CDC 7 | 407 | #define STRING_CDC 7 |
404 | #define STRING_SUBSET 8 | 408 | #define STRING_SUBSET 8 |
405 | #define STRING_RNDIS 9 | 409 | #define STRING_RNDIS 9 |
410 | #define STRING_SERIALNUMBER 10 | ||
406 | 411 | ||
407 | /* holds our biggest descriptor (or RNDIS response) */ | 412 | /* holds our biggest descriptor (or RNDIS response) */ |
408 | #define USB_BUFSIZ 256 | 413 | #define USB_BUFSIZ 256 |
@@ -870,6 +875,7 @@ static inline void __init hs_subset_descriptors(void) | |||
870 | 875 | ||
871 | static char manufacturer [50]; | 876 | static char manufacturer [50]; |
872 | static char product_desc [40] = DRIVER_DESC; | 877 | static char product_desc [40] = DRIVER_DESC; |
878 | static char serial_number [20]; | ||
873 | 879 | ||
874 | #ifdef DEV_CONFIG_CDC | 880 | #ifdef DEV_CONFIG_CDC |
875 | /* address that the host will use ... usually assigned at random */ | 881 | /* address that the host will use ... usually assigned at random */ |
@@ -880,6 +886,7 @@ static char ethaddr [2 * ETH_ALEN + 1]; | |||
880 | static struct usb_string strings [] = { | 886 | static struct usb_string strings [] = { |
881 | { STRING_MANUFACTURER, manufacturer, }, | 887 | { STRING_MANUFACTURER, manufacturer, }, |
882 | { STRING_PRODUCT, product_desc, }, | 888 | { STRING_PRODUCT, product_desc, }, |
889 | { STRING_SERIALNUMBER, serial_number, }, | ||
883 | { STRING_DATA, "Ethernet Data", }, | 890 | { STRING_DATA, "Ethernet Data", }, |
884 | #ifdef DEV_CONFIG_CDC | 891 | #ifdef DEV_CONFIG_CDC |
885 | { STRING_CDC, "CDC Ethernet", }, | 892 | { STRING_CDC, "CDC Ethernet", }, |
@@ -2162,7 +2169,7 @@ static u8 __init nibble (unsigned char c) | |||
2162 | return 0; | 2169 | return 0; |
2163 | } | 2170 | } |
2164 | 2171 | ||
2165 | static void __init get_ether_addr (const char *str, u8 *dev_addr) | 2172 | static int __init get_ether_addr(const char *str, u8 *dev_addr) |
2166 | { | 2173 | { |
2167 | if (str) { | 2174 | if (str) { |
2168 | unsigned i; | 2175 | unsigned i; |
@@ -2177,9 +2184,10 @@ static void __init get_ether_addr (const char *str, u8 *dev_addr) | |||
2177 | dev_addr [i] = num; | 2184 | dev_addr [i] = num; |
2178 | } | 2185 | } |
2179 | if (is_valid_ether_addr (dev_addr)) | 2186 | if (is_valid_ether_addr (dev_addr)) |
2180 | return; | 2187 | return 0; |
2181 | } | 2188 | } |
2182 | random_ether_addr(dev_addr); | 2189 | random_ether_addr(dev_addr); |
2190 | return 1; | ||
2183 | } | 2191 | } |
2184 | 2192 | ||
2185 | static int __init | 2193 | static int __init |
@@ -2277,6 +2285,10 @@ eth_bind (struct usb_gadget *gadget) | |||
2277 | strlcpy (manufacturer, iManufacturer, sizeof manufacturer); | 2285 | strlcpy (manufacturer, iManufacturer, sizeof manufacturer); |
2278 | if (iProduct) | 2286 | if (iProduct) |
2279 | strlcpy (product_desc, iProduct, sizeof product_desc); | 2287 | strlcpy (product_desc, iProduct, sizeof product_desc); |
2288 | if (iSerialNumber) { | ||
2289 | device_desc.iSerialNumber = STRING_SERIALNUMBER, | ||
2290 | strlcpy(serial_number, iSerialNumber, sizeof serial_number); | ||
2291 | } | ||
2280 | 2292 | ||
2281 | /* all we really need is bulk IN/OUT */ | 2293 | /* all we really need is bulk IN/OUT */ |
2282 | usb_ep_autoconfig_reset (gadget); | 2294 | usb_ep_autoconfig_reset (gadget); |
@@ -2386,9 +2398,13 @@ autoconf_fail: | |||
2386 | * The host side address is used with CDC and RNDIS, and commonly | 2398 | * The host side address is used with CDC and RNDIS, and commonly |
2387 | * ends up in a persistent config database. | 2399 | * ends up in a persistent config database. |
2388 | */ | 2400 | */ |
2389 | get_ether_addr(dev_addr, net->dev_addr); | 2401 | if (get_ether_addr(dev_addr, net->dev_addr)) |
2402 | dev_warn(&gadget->dev, | ||
2403 | "using random %s ethernet address\n", "self"); | ||
2390 | if (cdc || rndis) { | 2404 | if (cdc || rndis) { |
2391 | get_ether_addr(host_addr, dev->host_mac); | 2405 | if (get_ether_addr(host_addr, dev->host_mac)) |
2406 | dev_warn(&gadget->dev, | ||
2407 | "using random %s ethernet address\n", "host"); | ||
2392 | #ifdef DEV_CONFIG_CDC | 2408 | #ifdef DEV_CONFIG_CDC |
2393 | snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", | 2409 | snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", |
2394 | dev->host_mac [0], dev->host_mac [1], | 2410 | dev->host_mac [0], dev->host_mac [1], |