summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/staging/usbip/userspace/libsrc/names.c495
-rw-r--r--drivers/staging/usbip/userspace/libsrc/names.h21
2 files changed, 67 insertions, 449 deletions
diff --git a/drivers/staging/usbip/userspace/libsrc/names.c b/drivers/staging/usbip/userspace/libsrc/names.c
index 72480fb9976e..3c8d28b771e0 100644
--- a/drivers/staging/usbip/userspace/libsrc/names.c
+++ b/drivers/staging/usbip/userspace/libsrc/names.c
@@ -1,4 +1,3 @@
-/*****************************************************************************/
/*
* names.c -- USB name database manipulation routines
*
@@ -19,15 +18,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
- */
-
-/*
+ *
+ *
+ *
* Copyright (C) 2005 Takahiro Hirofuchi
* - names_deinit() is added.
+ *
*/
-/*****************************************************************************/
-
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -39,11 +37,8 @@
#include <stdio.h>
#include <ctype.h>
-
#include "names.h"
-
-
-/* ---------------------------------------------------------------------- */
+#include "usbip_common.h"
struct vendor {
struct vendor *next;
@@ -75,19 +70,12 @@ struct protocol {
char name[1];
};
-struct audioterminal {
- struct audioterminal *next;
- u_int16_t termt;
- char name[1];
-};
-
struct genericstrtable {
struct genericstrtable *next;
unsigned int num;
char name[1];
};
-/* ---------------------------------------------------------------------- */
#define HASH1 0x10
#define HASH2 0x02
@@ -103,75 +91,12 @@ static unsigned int hashnum(unsigned int num)
return num & (HASHSZ-1);
}
-/* ---------------------------------------------------------------------- */
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 audioterminal *audioterminals[HASHSZ] = { NULL, };
-static struct genericstrtable *hiddescriptors[HASHSZ] = { NULL, };
-static struct genericstrtable *reports[HASHSZ] = { NULL, };
-static struct genericstrtable *huts[HASHSZ] = { NULL, };
-static struct genericstrtable *biass[HASHSZ] = { NULL, };
-static struct genericstrtable *physdess[HASHSZ] = { NULL, };
-static struct genericstrtable *hutus[HASHSZ] = { NULL, };
-static struct genericstrtable *langids[HASHSZ] = { NULL, };
-static struct genericstrtable *countrycodes[HASHSZ] = { NULL, };
-
-/* ---------------------------------------------------------------------- */
-
-static const char *names_genericstrtable(struct genericstrtable *t[HASHSZ],
- unsigned int index)
-{
- struct genericstrtable *h;
-
- for (h = t[hashnum(index)]; h; h = h->next)
- if (h->num == index)
- return h->name;
- return NULL;
-}
-
-const char *names_hid(u_int8_t hidd)
-{
- return names_genericstrtable(hiddescriptors, hidd);
-}
-
-const char *names_reporttag(u_int8_t rt)
-{
- return names_genericstrtable(reports, rt);
-}
-
-const char *names_huts(unsigned int data)
-{
- return names_genericstrtable(huts, data);
-}
-
-const char *names_hutus(unsigned int data)
-{
- return names_genericstrtable(hutus, data);
-}
-
-const char *names_langid(u_int16_t langid)
-{
- return names_genericstrtable(langids, langid);
-}
-
-const char *names_physdes(u_int8_t ph)
-{
- return names_genericstrtable(physdess, ph);
-}
-
-const char *names_bias(u_int8_t b)
-{
- return names_genericstrtable(biass, b);
-}
-
-const char *names_countrycode(unsigned int countrycode)
-{
- return names_genericstrtable(countrycodes, countrycode);
-}
const char *names_vendor(u_int16_t vendorid)
{
@@ -231,20 +156,7 @@ const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
return NULL;
}
-const char *names_audioterminal(u_int16_t termt)
-{
- struct audioterminal *at;
-
- at = audioterminals[hashnum(termt)];
- for (; at; at = at->next)
- if (at->termt == termt)
- return at->name;
- return NULL;
-}
-
-/* ---------------------------------------------------------------------- */
/* add a cleanup function by takahiro */
-
struct pool {
struct pool *next;
void *mem;
@@ -291,8 +203,6 @@ void names_free(void)
}
}
-/* ---------------------------------------------------------------------- */
-
static int new_vendor(const char *name, u_int16_t vendorid)
{
struct vendor *v;
@@ -396,87 +306,6 @@ static int new_protocol(const char *name, u_int8_t classid, u_int8_t subclassid,
return 0;
}
-static int new_audioterminal(const char *name, u_int16_t termt)
-{
- struct audioterminal *at;
- unsigned int h = hashnum(termt);
-
- at = audioterminals[h];
- for (; at; at = at->next)
- if (at->termt == termt)
- return -1;
- at = my_malloc(sizeof(struct audioterminal) + strlen(name));
- if (!at)
- return -1;
- strcpy(at->name, name);
- at->termt = termt;
- at->next = audioterminals[h];
- audioterminals[h] = at;
- return 0;
-}
-
-static int new_genericstrtable(struct genericstrtable *t[HASHSZ],
- const char *name, unsigned int index)
-{
- struct genericstrtable *g;
- unsigned int h = hashnum(index);
-
- for (g = t[h]; g; g = g->next)
- if (g->num == index)
- return -1;
- g = my_malloc(sizeof(struct genericstrtable) + strlen(name));
- if (!g)
- return -1;
- strcpy(g->name, name);
- g->num = index;
- g->next = t[h];
- t[h] = g;
- return 0;
-}
-
-static int new_hid(const char *name, u_int8_t hidd)
-{
- return new_genericstrtable(hiddescriptors, name, hidd);
-}
-
-static int new_reporttag(const char *name, u_int8_t rt)
-{
- return new_genericstrtable(reports, name, rt);
-}
-
-static int new_huts(const char *name, unsigned int data)
-{
- return new_genericstrtable(huts, name, data);
-}
-
-static int new_hutus(const char *name, unsigned int data)
-{
- return new_genericstrtable(hutus, name, data);
-}
-
-static int new_langid(const char *name, u_int16_t langid)
-{
- return new_genericstrtable(langids, name, langid);
-}
-
-static int new_physdes(const char *name, u_int8_t ph)
-{
- return new_genericstrtable(physdess, name, ph);
-}
-static int new_bias(const char *name, u_int8_t b)
-{
- return new_genericstrtable(biass, name, b);
-}
-
-static int new_countrycode(const char *name, unsigned int countrycode)
-{
- return new_genericstrtable(countrycodes, name, countrycode);
-}
-
-/* ---------------------------------------------------------------------- */
-
-#define DBG(x)
-
static void parse(FILE *f)
{
char buf[512], *cp;
@@ -500,109 +329,27 @@ static void parse(FILE *f)
if (buf[0] == '#' || !buf[0])
continue;
cp = buf;
- if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y'
- && buf[3] == 'S' && buf[4] == 'D' && buf[5] == 'E'
- && buf[6] == 'S' && /*isspace(buf[7])*/ buf[7] == ' ') {
- cp = buf + 8;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid Physdes type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid Physdes type at line %u\n",
- linectr);
- continue;
- }
- if (new_physdes(cp, u))
- fprintf(stderr, "Duplicate Physdes type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u physdes type %02x %s\n", linectr,
- u, cp));
+ if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y' &&
+ buf[3] == 'S' && buf[4] == 'D' &&
+ buf[5] == 'E' && buf[6] == 'S' && /*isspace(buf[7])*/
+ buf[7] == ' ') {
continue;
-
}
- if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y'
- && /*isspace(buf[3])*/ buf[3] == ' ') {
- cp = buf + 4;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid PHY type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid PHY type at line %u\n",
- linectr);
- continue;
- }
- if (new_physdes(cp, u))
- fprintf(stderr, "Duplicate PHY type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u PHY type %02x %s\n", linectr, u,
- cp));
+ if (buf[0] == 'P' && buf[1] == 'H' &&
+ buf[2] == 'Y' && /*isspace(buf[3])*/ buf[3] == ' ') {
continue;
-
}
- if (buf[0] == 'B' && buf[1] == 'I' && buf[2] == 'A'
- && buf[3] == 'S' && /*isspace(buf[4])*/ buf[4] == ' ') {
- cp = buf + 5;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid BIAS type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid BIAS type at line %u\n",
- linectr);
- continue;
- }
- if (new_bias(cp, u))
- fprintf(stderr, "Duplicate BIAS type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u BIAS type %02x %s\n", linectr, u,
- cp));
+ if (buf[0] == 'B' && buf[1] == 'I' && buf[2] == 'A' &&
+ buf[3] == 'S' && /*isspace(buf[4])*/ buf[4] == ' ') {
continue;
-
}
if (buf[0] == 'L' && /*isspace(buf[1])*/ buf[1] == ' ') {
- cp = buf+2;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid LANGID spec at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid LANGID spec at line %u\n",
- linectr);
- continue;
- }
- if (new_langid(cp, u))
- fprintf(stderr, "Duplicate LANGID spec at line %u language-id %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u LANGID %02x %s\n", linectr, u,
- cp));
lasthut = lastclass = lastvendor = lastsubclass = -1;
- lastlang = u;
+ /*
+ * set 1 as pseudo-id to indicate that the parser is
+ * in a `L' section.
+ */
+ lastlang = 1;
continue;
}
if (buf[0] == 'C' && /*isspace(buf[1])*/ buf[1] == ' ') {
@@ -611,75 +358,31 @@ static void parse(FILE *f)
while (isspace(*cp))
cp++;
if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid class spec at line %u\n",
- linectr);
+ err("Invalid class spec at line %u", linectr);
continue;
}
u = strtoul(cp, &cp, 16);
while (isspace(*cp))
cp++;
if (!*cp) {
- fprintf(stderr, "Invalid class spec at line %u\n",
- linectr);
+ err("Invalid class spec at line %u", linectr);
continue;
}
if (new_class(cp, u))
- fprintf(stderr, "Duplicate class spec at line %u class %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u class %02x %s\n", linectr, u, cp));
+ err("Duplicate class spec at line %u class %04x %s",
+ linectr, u, cp);
+ dbg("line %5u class %02x %s", linectr, u, cp);
lasthut = lastlang = lastvendor = lastsubclass = -1;
lastclass = u;
continue;
}
if (buf[0] == 'A' && buf[1] == 'T' && isspace(buf[2])) {
/* audio terminal type spec */
- cp = buf+3;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid audio terminal type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid audio terminal type at line %u\n",
- linectr);
- continue;
- }
- if (new_audioterminal(cp, u))
- fprintf(stderr, "Duplicate audio terminal type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u audio terminal type %02x %s\n",
- linectr, u, cp));
continue;
}
if (buf[0] == 'H' && buf[1] == 'C' && buf[2] == 'C'
&& isspace(buf[3])) {
/* HID Descriptor bCountryCode */
- cp = buf+3;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid HID country code at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 10);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid HID country code at line %u\n",
- linectr);
- continue;
- }
- if (new_countrycode(cp, u))
- fprintf(stderr, "Duplicate HID country code at line %u country %02u %s\n",
- linectr, u, cp);
- DBG(printf("line %5u keyboard country code %02u %s\n",
- linectr, u, cp));
continue;
}
if (isxdigit(*cp)) {
@@ -688,15 +391,13 @@ static void parse(FILE *f)
while (isspace(*cp))
cp++;
if (!*cp) {
- fprintf(stderr, "Invalid vendor spec at line %u\n",
- linectr);
+ err("Invalid vendor spec at line %u", linectr);
continue;
}
if (new_vendor(cp, u))
- fprintf(stderr, "Duplicate vendor spec at line %u vendor %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u vendor %04x %s\n", linectr, u,
- cp));
+ err("Duplicate vendor spec at line %u vendor %04x %s",
+ linectr, u, cp);
+ dbg("line %5u vendor %04x %s", linectr, u, cp);
lastvendor = u;
lasthut = lastlang = lastclass = lastsubclass = -1;
continue;
@@ -707,41 +408,37 @@ static void parse(FILE *f)
while (isspace(*cp))
cp++;
if (!*cp) {
- fprintf(stderr, "Invalid product/subclass spec at line %u\n",
- linectr);
+ err("Invalid product/subclass spec at line %u",
+ linectr);
continue;
}
if (lastvendor != -1) {
if (new_product(cp, lastvendor, u))
- fprintf(stderr, "Duplicate product spec at line %u product %04x:%04x %s\n",
- linectr, lastvendor, u, cp);
- DBG(printf("line %5u product %04x:%04x %s\n",
- linectr, lastvendor, u, cp));
+ err("Duplicate product spec at line %u product %04x:%04x %s",
+ linectr, lastvendor, u, cp);
+ dbg("line %5u product %04x:%04x %s", linectr,
+ lastvendor, u, cp);
continue;
}
if (lastclass != -1) {
if (new_subclass(cp, lastclass, u))
- fprintf(stderr, "Duplicate subclass spec at line %u class %02x:%02x %s\n",
- linectr, lastclass, u, cp);
- DBG(printf("line %5u subclass %02x:%02x %s\n",
- linectr, lastclass, u, cp));
+ err("Duplicate subclass spec at line %u class %02x:%02x %s",
+ linectr, lastclass, u, cp);
+ dbg("line %5u subclass %02x:%02x %s", linectr,
+ lastclass, u, cp);
lastsubclass = u;
continue;
}
if (lasthut != -1) {
- if (new_hutus(cp, (lasthut << 16)+u))
- fprintf(stderr, "Duplicate HUT Usage Spec at line %u\n",
- linectr);
+ /* do not store hut */
continue;
}
if (lastlang != -1) {
- if (new_langid(cp, lastlang+(u<<10)))
- fprintf(stderr, "Duplicate LANGID Usage Spec at line %u\n",
- linectr);
+ /* do not store langid */
continue;
}
- fprintf(stderr, "Product/Subclass spec without prior Vendor/Class spec at line %u\n",
- linectr);
+ err("Product/Subclass spec without prior Vendor/Class spec at line %u",
+ linectr);
continue;
}
if (buf[0] == '\t' && buf[1] == '\t' && isxdigit(buf[2])) {
@@ -750,110 +447,48 @@ static void parse(FILE *f)
while (isspace(*cp))
cp++;
if (!*cp) {
- fprintf(stderr, "Invalid protocol spec at line %u\n",
- linectr);
+ err("Invalid protocol spec at line %u",
+ linectr);
continue;
}
if (lastclass != -1 && lastsubclass != -1) {
- if (new_protocol(cp, lastclass, lastsubclass, u))
- fprintf(stderr, "Duplicate protocol spec at line %u class %02x:%02x:%02x %s\n",
- linectr, lastclass, lastsubclass, u, cp);
- DBG(printf("line %5u protocol %02x:%02x:%02x %s\n",
- linectr, lastclass, lastsubclass, u, cp));
+ if (new_protocol(cp, lastclass, lastsubclass,
+ u))
+ err("Duplicate protocol spec at line %u class %02x:%02x:%02x %s",
+ linectr, lastclass, lastsubclass,
+ u, cp);
+ dbg("line %5u protocol %02x:%02x:%02x %s",
+ linectr, lastclass, lastsubclass, u, cp);
continue;
}
- fprintf(stderr, "Protocol spec without prior Class and Subclass spec at line %u\n",
- linectr);
+ err("Protocol spec without prior Class and Subclass spec at line %u",
+ linectr);
continue;
}
- if (buf[0] == 'H' && buf[1] == 'I' && buf[2] == 'D'
- && /*isspace(buf[3])*/ buf[3] == ' ') {
- cp = buf + 4;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid HID type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid HID type at line %u\n",
- linectr);
- continue;
- }
- if (new_hid(cp, u))
- fprintf(stderr, "Duplicate HID type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u HID type %02x %s\n", linectr, u,
- cp));
+ if (buf[0] == 'H' && buf[1] == 'I' &&
+ buf[2] == 'D' && /*isspace(buf[3])*/ buf[3] == ' ') {
continue;
-
}
- if (buf[0] == 'H' && buf[1] == 'U' && buf[2] == 'T'
- && /*isspace(buf[3])*/ buf[3] == ' ') {
- cp = buf + 4;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid HUT type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid HUT type at line %u\n",
- linectr);
- continue;
- }
- if (new_huts(cp, u))
- fprintf(stderr, "Duplicate HUT type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
+ if (buf[0] == 'H' && buf[1] == 'U' &&
+ buf[2] == 'T' && /*isspace(buf[3])*/ buf[3] == ' ') {
lastlang = lastclass = lastvendor = lastsubclass = -1;
- lasthut = u;
- DBG(printf("line %5u HUT type %02x %s\n", linectr, u,
- cp));
+ /*
+ * set 1 as pseudo-id to indicate that the parser is
+ * in a `HUT' section.
+ */
+ lasthut = 1;
continue;
-
}
- if (buf[0] == 'R' && buf[1] == ' ') {
- cp = buf + 2;
- while (isspace(*cp))
- cp++;
- if (!isxdigit(*cp)) {
- fprintf(stderr, "Invalid Report type at line %u\n",
- linectr);
- continue;
- }
- u = strtoul(cp, &cp, 16);
- while (isspace(*cp))
- cp++;
- if (!*cp) {
- fprintf(stderr, "Invalid Report type at line %u\n",
- linectr);
- continue;
- }
- if (new_reporttag(cp, u))
- fprintf(stderr, "Duplicate Report type spec at line %u terminal type %04x %s\n",
- linectr, u, cp);
- DBG(printf("line %5u Report type %02x %s\n", linectr,
- u, cp));
+ if (buf[0] == 'R' && buf[1] == ' ')
continue;
- }
- if (buf[0] == 'V' && buf[1] == 'T') {
- /* add here */
+ if (buf[0] == 'V' && buf[1] == 'T')
continue;
- }
- fprintf(stderr, "Unknown line at line %u\n", linectr);
+
+ err("Unknown line at line %u", linectr);
}
}
-/* ---------------------------------------------------------------------- */
int names_init(char *n)
{
diff --git a/drivers/staging/usbip/userspace/libsrc/names.h b/drivers/staging/usbip/userspace/libsrc/names.h
index 28dafc59f5b0..680926512de2 100644
--- a/drivers/staging/usbip/userspace/libsrc/names.h
+++ b/drivers/staging/usbip/userspace/libsrc/names.h
@@ -1,5 +1,3 @@
-/*****************************************************************************/
-
/*
* names.h -- USB name database manipulation routines
*
@@ -20,39 +18,24 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
- */
-
-/*
+ *
* Copyright (C) 2005 Takahiro Hirofuchi
* - names_free() is added.
*/
-/*****************************************************************************/
-
#ifndef _NAMES_H
#define _NAMES_H
#include <sys/types.h>
-/* ---------------------------------------------------------------------- */
-
+/* used by usbip_common.c */
extern const char *names_vendor(u_int16_t vendorid);
extern const char *names_product(u_int16_t vendorid, u_int16_t productid);
extern const char *names_class(u_int8_t classid);
extern const char *names_subclass(u_int8_t classid, u_int8_t subclassid);
extern const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
u_int8_t protocolid);
-extern const char *names_audioterminal(u_int16_t termt);
-extern const char *names_hid(u_int8_t hidd);
-extern const char *names_reporttag(u_int8_t rt);
-extern const char *names_huts(unsigned int data);
-extern const char *names_hutus(unsigned int data);
-extern const char *names_langid(u_int16_t langid);
-extern const char *names_physdes(u_int8_t ph);
-extern const char *names_bias(u_int8_t b);
-extern const char *names_countrycode(unsigned int countrycode);
extern int names_init(char *n);
extern void names_free(void);
-/* ---------------------------------------------------------------------- */
#endif /* _NAMES_H */