usb: gadget: g_dnl: fix g_dnl_set_serialnumber()
PATCH 1/2 usb: gadget: g_dnl: fix g_dnl_set_serialnumber()
instead of only copying if strlen(s) is less than 32 characters, let's just copy at most 31 characters regardless of the size of serial#. This will guarantee that we always have a serial number if serial# environment variable is set to anything.
Note that without a proper serial number, USB Command Verifier fails our test of Device Descriptor since we will claim to have a serial number without really providing one when requested.
--- drivers/usb/gadget/g_dnl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/gadget/g_dnl.c +1 -2
@@ -49,8 +49,7 @@ static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;void g_dnl_set_serialnumber (char *s) {memset (g_dnl_serial,0 ,MAX_STRING_SERIAL ); -if (strlen (s) <MAX_STRING_SERIAL ) -strncpy (g_dnl_serial, s,strlen (s)); +strncpy (g_dnl_serial, s,MAX_STRING_SERIAL -1 ); }static struct usb_device_descriptor device_desc = {
Signature · 1 line
2.11.0.295.gd7dffce1ce
PATCH 2/2 usb: gadget: f_dfu: set serial number if serial# is valid
With this patch, USB Command Verifier is happy with our DFU implementation on Chapter 9 tests.
--- drivers/usb/gadget/f_dfu.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/gadget/f_dfu.c +5 -0
@@ -691,6 +691,7 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f) {struct usb_composite_dev *cdev = c->cdev;struct f_dfu *f_dfu =func_to_dfu (f); +const char *s;int alt_num =dfu_get_alt_number ();int rv, id, i;
@@ -724,6 +725,10 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f) cdev->req->context = f_dfu; + s =getenv ("serial#" ); +if (s) +g_dnl_set_serialnumber ((char *)s); + error:return rv; }
Signature · 1 line
2.11.0.295.gd7dffce1ce
PATCH 2/2 usb: gadget: f_dfu: set serial number if serial# is valid
Quoted 21 lines · On Wed, 22 Feb 2017 11:22:38 +0200 Felipe Balbi <[email protected]>…
With this patch, USB Command Verifier is happy with our DFU implementation on Chapter 9 tests.
Signed-off-by Felipe Balbi <[email protected]>--- drivers/usb/gadget/f_dfu.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/gadget/f_dfu.c +1
-0@@ -691,6 +691,7 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f) {struct usb_composite_dev *cdev = c->cdev;struct f_dfu *f_dfu =func_to_dfu (f); +const char *s;int alt_num =dfu_get_alt_number ();int rv, id, i;
drivers/usb/gadget/f_dfu.c static int dfu_bind(struct usb_configuration *c, · line 734
Quoted 10 lines
drivers/usb/gadget/f_dfu.c +4
-0@@ -724,6 +725,10 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f) cdev->req->context = f_dfu; + s =getenv ("serial#" ); +if (s) +g_dnl_set_serialnumber ((char *)s); + error:return rv; }
Test HW: BBB (am335x) - with tests/py/dfu
Test SW: test/py/dfu
I've applied it to u-boot-dfu tree.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
PATCH 1/2 usb: gadget: g_dnl: fix g_dnl_set_serialnumber()
In reply to Felipe BalbiQuoted 19 lines · On Wed, 22 Feb 2017 11:22:37 +0200 Felipe Balbi <[email protected]>…
instead of only copying if strlen(s) is less than 32 characters, let's just copy at most 31 characters regardless of the size of serial#. This will guarantee that we always have a serial number if serial# environment variable is set to anything.
Note that without a proper serial number, USB Command Verifier fails our test of Device Descriptor since we will claim to have a serial number without really providing one when requested.
Signed-off-by Felipe Balbi <[email protected]>--- drivers/usb/gadget/g_dnl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/usb/gadget/g_dnl.c +0
-0
drivers/usb/gadget/g_dnl.c static const char manufacturer[] = · line 55
Quoted 9 lines
drivers/usb/gadget/g_dnl.c +1
-2@@ -49,8 +49,7 @@ static const char manufacturer[] =CONFIG_G_DNL_MANUFACTURER ;void g_dnl_set_serialnumber (char *s) {memset (g_dnl_serial,0 ,MAX_STRING_SERIAL ); -if (strlen (s) <MAX_STRING_SERIAL ) -strncpy (g_dnl_serial, s,strlen (s)); +strncpy (g_dnl_serial, s,MAX_STRING_SERIAL -1 ); }static struct usb_device_descriptor device_desc = {
Test HW: BBB (am335x) - with tests/py/dfu
Test SW: test/py/dfu
I've applied it to u-boot-dfu tree.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de