diff --git a/ChangeLog b/ChangeLog index 4b2061a..c8bd20d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2017-10-06 NIIBE Yutaka + + * src/configure: Allow not specifying VIDPID. + + * src/main.c [GNU_LINUX_EMULATION] (main): Handle "--vidpid" + option to assign vendor ID and product ID of USB. + + * src/usb_desc.c [GNU_LINUX_EMULATION] (device_desc): Export. + + * GNUK_USB_DEVICE_ID (0000:0000): New. + 2017-10-05 NIIBE Yutaka * src/stack-def.h (SIZE_1, SIZE_3): Tweak the size. diff --git a/GNUK_USB_DEVICE_ID b/GNUK_USB_DEVICE_ID index b62527f..003f4ee 100644 --- a/GNUK_USB_DEVICE_ID +++ b/GNUK_USB_DEVICE_ID @@ -1,4 +1,5 @@ # VID:PID bcdDev Product_STRING Vendor_STRING +0000:0000 0200 Gnuk Emulation Free Software Initiative of Japan 234b:0000 0200 Gnuk Token Free Software Initiative of Japan 20a0:4211 0200 Nitrokey Start Nitrokey ########## ## ########## ################# diff --git a/src/configure b/src/configure index d51ff7d..9e04f94 100755 --- a/src/configure +++ b/src/configure @@ -162,11 +162,6 @@ EOF exit 0 fi -if test "$vidpid" = "none"; then - echo "Please specify Vendor ID and Product ID by --vidpid option." >&2 - exit 1 -fi - BOARD_HEADER_FILE=board-$(echo $target | tr '_[:upper:]' '-[:lower:]').h echo "Header file is: $BOARD_HEADER_FILE" ln -sf "../chopstx/board/$BOARD_HEADER_FILE" board.h @@ -227,6 +222,17 @@ else libs="" fi +if test "$emulation" = "yes"; then + if test "$vidpid" = "none"; then + vidpid=0000:0000 + fi +else + if test "$vidpid" = "none"; then + echo "Please specify Vendor ID and Product ID by --vidpid option." >&2 + exit 1 + fi +fi + # --enable-debug option if test "$debug" = "yes"; then DEBUG_MAKE_OPTION="ENABLE_DEBUG=1" diff --git a/src/main.c b/src/main.c index aa54935..1cdaee1 100644 --- a/src/main.c +++ b/src/main.c @@ -233,12 +233,34 @@ main (int argc, const char *argv[]) #ifdef GNU_LINUX_EMULATION #define FLASH_IMAGE_NAME ".gnuk-flash-image" - if (argc >= 3 || (argc == 2 && !strcmp (argv[1], "--help"))) + if (argc >= 4 || (argc == 2 && !strcmp (argv[1], "--help"))) { - fprintf (stdout, "Usage: %s [flash-image-file]", argv[0]); + fprintf (stdout, "Usage: %s [--vidpid=Vxxx:Pxxx] [flash-image-file]", + argv[0]); exit (0); } + if (argc >= 2 && !strncmp (argv[1], "--vidpid=", 9)) + { + extern uint8_t device_desc[]; + uint32_t id; + char *p; + + id = (uint32_t)strtol (&argv[1][9], &p, 16); + device_desc[8] = (id & 0xff); + device_desc[9] = (id >> 8); + + if (p && p[0] == ':') + { + id = (uint32_t)strtol (&p[1], NULL, 16); + device_desc[10] = (id & 0xff); + device_desc[11] = (id >> 8); + } + + argc--; + argv++; + } + if (argc == 1) { char *p = getenv ("HOME"); diff --git a/src/usb_desc.c b/src/usb_desc.c index a5a1594..8031088 100644 --- a/src/usb_desc.c +++ b/src/usb_desc.c @@ -59,7 +59,10 @@ static const uint8_t hid_report_desc[] = { #define USB_CCID_DATA_SIZE 64 /* USB Standard Device Descriptor */ -static const uint8_t device_desc[] = { +#if !defined(GNU_LINUX_EMULATION) +static const +#endif +uint8_t device_desc[] = { 18, /* bLength */ DEVICE_DESCRIPTOR, /* bDescriptorType */ 0x10, 0x01, /* bcdUSB = 1.1 */