Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Tom Gundersen
On Fri, Sep 13, 2013 at 12:47 AM, Greg Kroah-Hartman
 wrote:
> On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
>> Most of the information in usb.ids is now contained in udev's hwdb. Read the
>> information from the hwdb instead of usb.ids.
>>
>> This would allow distributions to no longer ship (most of) usb.ids by 
>> default,
>> but rather keep all the usb device information in the hwdb.
>>
>> This patch introduces a dependency on libusb >= 196.
>
> You mean 'libudev' here, right?  I don't think libusb has that version
> number quite yet :)

Hehe, precisely :-)

-t
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Greg Kroah-Hartman
On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
> Most of the information in usb.ids is now contained in udev's hwdb. Read the
> information from the hwdb instead of usb.ids.
> 
> This would allow distributions to no longer ship (most of) usb.ids by default,
> but rather keep all the usb device information in the hwdb.
> 
> This patch introduces a dependency on libusb >= 196.
> 
> v2: drop support from reading data from usb.ids which is already in hwdb
> 
> Cc: Greg Kroah-Hartman 
> ---
>  Makefile.am  |   5 +-
>  configure.ac |   2 +
>  names.c  | 361 
> +++
>  3 files changed, 45 insertions(+), 323 deletions(-)

Applied, thanks.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Greg Kroah-Hartman
On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
> Most of the information in usb.ids is now contained in udev's hwdb. Read the
> information from the hwdb instead of usb.ids.
> 
> This would allow distributions to no longer ship (most of) usb.ids by default,
> but rather keep all the usb device information in the hwdb.
> 
> This patch introduces a dependency on libusb >= 196.

You mean 'libudev' here, right?  I don't think libusb has that version
number quite yet :)

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Greg Kroah-Hartman
On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
 Most of the information in usb.ids is now contained in udev's hwdb. Read the
 information from the hwdb instead of usb.ids.
 
 This would allow distributions to no longer ship (most of) usb.ids by default,
 but rather keep all the usb device information in the hwdb.
 
 This patch introduces a dependency on libusb = 196.

You mean 'libudev' here, right?  I don't think libusb has that version
number quite yet :)

thanks,

greg k-h
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Greg Kroah-Hartman
On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
 Most of the information in usb.ids is now contained in udev's hwdb. Read the
 information from the hwdb instead of usb.ids.
 
 This would allow distributions to no longer ship (most of) usb.ids by default,
 but rather keep all the usb device information in the hwdb.
 
 This patch introduces a dependency on libusb = 196.
 
 v2: drop support from reading data from usb.ids which is already in hwdb
 
 Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
 ---
  Makefile.am  |   5 +-
  configure.ac |   2 +
  names.c  | 361 
 +++
  3 files changed, 45 insertions(+), 323 deletions(-)

Applied, thanks.

greg k-h
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-12 Thread Tom Gundersen
On Fri, Sep 13, 2013 at 12:47 AM, Greg Kroah-Hartman
gre...@linuxfoundation.org wrote:
 On Wed, Sep 04, 2013 at 02:47:07PM +0200, Tom Gundersen wrote:
 Most of the information in usb.ids is now contained in udev's hwdb. Read the
 information from the hwdb instead of usb.ids.

 This would allow distributions to no longer ship (most of) usb.ids by 
 default,
 but rather keep all the usb device information in the hwdb.

 This patch introduces a dependency on libusb = 196.

 You mean 'libudev' here, right?  I don't think libusb has that version
 number quite yet :)

Hehe, precisely :-)

-t
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-04 Thread Tom Gundersen
Most of the information in usb.ids is now contained in udev's hwdb. Read the
information from the hwdb instead of usb.ids.

This would allow distributions to no longer ship (most of) usb.ids by default,
but rather keep all the usb device information in the hwdb.

This patch introduces a dependency on libusb >= 196.

v2: drop support from reading data from usb.ids which is already in hwdb

Cc: Greg Kroah-Hartman 
---
 Makefile.am  |   5 +-
 configure.ac |   2 +
 names.c  | 361 +++
 3 files changed, 45 insertions(+), 323 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 1e85a1e..70b9de9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,11 +23,12 @@ lsusb_SOURCES = \
usbmisc.c usbmisc.h
 
 lsusb_CPPFLAGS = \
-   $(AM_CPPFLAGS) $(LIBUSB_CFLAGS) \
+   $(AM_CPPFLAGS) $(LIBUSB_CFLAGS) $(UDEV_CFLAGS) \
-DDATADIR=\"$(datadir)\"
 
 lsusb_LDADD = \
-   $(LIBUSB_LIBS)
+   $(LIBUSB_LIBS) \
+   $(UDEV_LIBS)
 
 if HAVE_ZLIB
 lsusb_CPPFLAGS += -DHAVE_LIBZ
diff --git a/configure.ac b/configure.ac
index adfb4b6..b4b0880 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,8 @@ AM_CONDITIONAL([INSTALL_USBIDS], [test "x$enable_usbids" != 
"xno"])
 
 PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= 1.0.0)
 
+PKG_CHECK_MODULES(UDEV, libudev >= 196)
+
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_FILES([
Makefile
diff --git a/names.c b/names.c
index 12cbd60..f543240 100644
--- a/names.c
+++ b/names.c
@@ -3,6 +3,7 @@
  *  names.c  --  USB name database manipulation routines
  *
  *  Copyright (C) 1999, 2000  Thomas Sailer (sai...@ife.ee.ethz.ch)
+ *  Copyright (C) 2013  Tom Gundersen (t...@jklm.no)
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -34,6 +35,8 @@
 #include 
 #include 
 
+#include 
+
 #ifdef HAVE_LIBZ
 #include 
 #defineusb_filegzFile
@@ -52,36 +55,6 @@
 
 /* -- */
 
-struct vendor {
-   struct vendor *next;
-   u_int16_t vendorid;
-   char name[1];
-};
-
-struct product {
-   struct product *next;
-   u_int16_t vendorid, productid;
-   char name[1];
-};
-
-struct class {
-   struct class *next;
-   u_int8_t classid;
-   char name[1];
-};
-
-struct subclass {
-   struct subclass *next;
-   u_int8_t classid, subclassid;
-   char name[1];
-};
-
-struct protocol {
-   struct protocol *next;
-   u_int8_t classid, subclassid, protocolid;
-   char name[1];
-};
-
 struct audioterminal {
struct audioterminal *next;
u_int16_t termt;
@@ -118,11 +91,8 @@ static unsigned int hashnum(unsigned int num)
 
 /* -- */
 
-static struct vendor *vendors[HASHSZ] = { NULL, };
-static struct product *products[HASHSZ] = { NULL, };
-static struct class *classes[HASHSZ] = { NULL, };
-static struct subclass *subclasses[HASHSZ] = { NULL, };
-static struct protocol *protocols[HASHSZ] = { NULL, };
+static struct udev *udev = NULL;
+static struct udev_hwdb *hwdb = NULL;
 static struct audioterminal *audioterminals[HASHSZ] = { NULL, };
 static struct videoterminal *videoterminals[HASHSZ] = { NULL, };
 static struct genericstrtable *hiddescriptors[HASHSZ] = { NULL, };
@@ -187,59 +157,55 @@ const char *names_countrycode(unsigned int countrycode)
return names_genericstrtable(countrycodes, countrycode);
 }
 
-const char *names_vendor(u_int16_t vendorid)
+static const char *hwdb_get(const char *modalias, const char *key)
 {
-   struct vendor *v;
+   struct udev_list_entry *entry;
+
+   udev_list_entry_foreach(entry, 
udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
+   if (strcmp(udev_list_entry_get_name(entry), key) == 0)
+   return udev_list_entry_get_value(entry);
 
-   v = vendors[hashnum(vendorid)];
-   for (; v; v = v->next)
-   if (v->vendorid == vendorid)
-   return v->name;
return NULL;
 }
 
+const char *names_vendor(u_int16_t vendorid)
+{
+   char modalias[64];
+
+   sprintf(modalias, "usb:v%04X*", vendorid);
+   return hwdb_get(modalias, "ID_VENDOR_FROM_DATABASE");
+}
+
 const char *names_product(u_int16_t vendorid, u_int16_t productid)
 {
-   struct product *p;
+   char modalias[64];
 
-   p = products[hashnum((vendorid << 16) | productid)];
-   for (; p; p = p->next)
-   if (p->vendorid == vendorid && p->productid == productid)
-   return p->name;
-   return NULL;
+   sprintf(modalias, "usb:v%04Xp%04X*", vendorid, productid);
+   return hwdb_get(modalias, "ID_MODEL_FROM_DATABASE");
 }
 
 const char *names_class(u_int8_t classid)
 {
-   struct class *c;
+   char modalias[64];
 
-   c = 

[PATCH 1/2][usbutils] lsusb: port to hwdb

2013-09-04 Thread Tom Gundersen
Most of the information in usb.ids is now contained in udev's hwdb. Read the
information from the hwdb instead of usb.ids.

This would allow distributions to no longer ship (most of) usb.ids by default,
but rather keep all the usb device information in the hwdb.

This patch introduces a dependency on libusb = 196.

v2: drop support from reading data from usb.ids which is already in hwdb

Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 Makefile.am  |   5 +-
 configure.ac |   2 +
 names.c  | 361 +++
 3 files changed, 45 insertions(+), 323 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 1e85a1e..70b9de9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,11 +23,12 @@ lsusb_SOURCES = \
usbmisc.c usbmisc.h
 
 lsusb_CPPFLAGS = \
-   $(AM_CPPFLAGS) $(LIBUSB_CFLAGS) \
+   $(AM_CPPFLAGS) $(LIBUSB_CFLAGS) $(UDEV_CFLAGS) \
-DDATADIR=\$(datadir)\
 
 lsusb_LDADD = \
-   $(LIBUSB_LIBS)
+   $(LIBUSB_LIBS) \
+   $(UDEV_LIBS)
 
 if HAVE_ZLIB
 lsusb_CPPFLAGS += -DHAVE_LIBZ
diff --git a/configure.ac b/configure.ac
index adfb4b6..b4b0880 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,8 @@ AM_CONDITIONAL([INSTALL_USBIDS], [test x$enable_usbids != 
xno])
 
 PKG_CHECK_MODULES(LIBUSB, libusb-1.0 = 1.0.0)
 
+PKG_CHECK_MODULES(UDEV, libudev = 196)
+
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_FILES([
Makefile
diff --git a/names.c b/names.c
index 12cbd60..f543240 100644
--- a/names.c
+++ b/names.c
@@ -3,6 +3,7 @@
  *  names.c  --  USB name database manipulation routines
  *
  *  Copyright (C) 1999, 2000  Thomas Sailer (sai...@ife.ee.ethz.ch)
+ *  Copyright (C) 2013  Tom Gundersen (t...@jklm.no)
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -34,6 +35,8 @@
 #include stdio.h
 #include ctype.h
 
+#include libudev.h
+
 #ifdef HAVE_LIBZ
 #include zlib.h
 #defineusb_filegzFile
@@ -52,36 +55,6 @@
 
 /* -- */
 
-struct vendor {
-   struct vendor *next;
-   u_int16_t vendorid;
-   char name[1];
-};
-
-struct product {
-   struct product *next;
-   u_int16_t vendorid, productid;
-   char name[1];
-};
-
-struct class {
-   struct class *next;
-   u_int8_t classid;
-   char name[1];
-};
-
-struct subclass {
-   struct subclass *next;
-   u_int8_t classid, subclassid;
-   char name[1];
-};
-
-struct protocol {
-   struct protocol *next;
-   u_int8_t classid, subclassid, protocolid;
-   char name[1];
-};
-
 struct audioterminal {
struct audioterminal *next;
u_int16_t termt;
@@ -118,11 +91,8 @@ static unsigned int hashnum(unsigned int num)
 
 /* -- */
 
-static struct vendor *vendors[HASHSZ] = { NULL, };
-static struct product *products[HASHSZ] = { NULL, };
-static struct class *classes[HASHSZ] = { NULL, };
-static struct subclass *subclasses[HASHSZ] = { NULL, };
-static struct protocol *protocols[HASHSZ] = { NULL, };
+static struct udev *udev = NULL;
+static struct udev_hwdb *hwdb = NULL;
 static struct audioterminal *audioterminals[HASHSZ] = { NULL, };
 static struct videoterminal *videoterminals[HASHSZ] = { NULL, };
 static struct genericstrtable *hiddescriptors[HASHSZ] = { NULL, };
@@ -187,59 +157,55 @@ const char *names_countrycode(unsigned int countrycode)
return names_genericstrtable(countrycodes, countrycode);
 }
 
-const char *names_vendor(u_int16_t vendorid)
+static const char *hwdb_get(const char *modalias, const char *key)
 {
-   struct vendor *v;
+   struct udev_list_entry *entry;
+
+   udev_list_entry_foreach(entry, 
udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
+   if (strcmp(udev_list_entry_get_name(entry), key) == 0)
+   return udev_list_entry_get_value(entry);
 
-   v = vendors[hashnum(vendorid)];
-   for (; v; v = v-next)
-   if (v-vendorid == vendorid)
-   return v-name;
return NULL;
 }
 
+const char *names_vendor(u_int16_t vendorid)
+{
+   char modalias[64];
+
+   sprintf(modalias, usb:v%04X*, vendorid);
+   return hwdb_get(modalias, ID_VENDOR_FROM_DATABASE);
+}
+
 const char *names_product(u_int16_t vendorid, u_int16_t productid)
 {
-   struct product *p;
+   char modalias[64];
 
-   p = products[hashnum((vendorid  16) | productid)];
-   for (; p; p = p-next)
-   if (p-vendorid == vendorid  p-productid == productid)
-   return p-name;
-   return NULL;
+   sprintf(modalias, usb:v%04Xp%04X*, vendorid, productid);
+   return hwdb_get(modalias, ID_MODEL_FROM_DATABASE);
 }
 
 const char *names_class(u_int8_t classid)
 {
-   struct class *c;
+   char