libusbgx: Change gadget attributes size and names.
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 11 Feb 2014 14:44:48 +0000 (15:44 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 19:33:56 +0000 (20:33 +0100)
Rename all gadget attributes to be consistent with usb
standard and libusb. Change also field size and order
to allow direct memcpy from libusb_device_descriptor.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
examples/show-gadgets.c
include/usbg/usbg.h
src/usbg.c

index cc86fdf..29a30d3 100644 (file)
 void show_gadget(struct gadget *g)
 {
        fprintf(stdout, "ID %04x:%04x '%s'\n",
-               g->attrs.vendor, g->attrs.product, g->name);
+               g->attrs.idVendor, g->attrs.idProduct, g->name);
        fprintf(stdout, "  UDC\t\t\t%s\n", g->udc);
-       fprintf(stdout, "  bDeviceClass\t\t0x%02x\n", g->attrs.dclass);
-       fprintf(stdout, "  bDeviceSubClass\t0x%02x\n", g->attrs.dsubclass);
-       fprintf(stdout, "  bDeviceProtocol\t0x%02x\n", g->attrs.dproto);
-       fprintf(stdout, "  bMaxPacketSize0\t0x%02x\n", g->attrs.maxpacket);
-       fprintf(stdout, "  bcdDevice\t\t0x%04x\n", g->attrs.bcddevice);
-       fprintf(stdout, "  bcdUSB\t\t0x%04x\n", g->attrs.bcdusb);
-       fprintf(stdout, "  idVendor\t\t0x%04x\n", g->attrs.vendor);
-       fprintf(stdout, "  idProduct\t\t0x%04x\n", g->attrs.product);
+       fprintf(stdout, "  bDeviceClass\t\t0x%02x\n", g->attrs.bDeviceClass);
+       fprintf(stdout, "  bDeviceSubClass\t0x%02x\n", g->attrs.bDeviceSubClass);
+       fprintf(stdout, "  bDeviceProtocol\t0x%02x\n", g->attrs.bDeviceProtocol);
+       fprintf(stdout, "  bMaxPacketSize0\t0x%02x\n", g->attrs.bMaxPacketSize0);
+       fprintf(stdout, "  bcdDevice\t\t0x%04x\n", g->attrs.bcdDevice);
+       fprintf(stdout, "  bcdUSB\t\t0x%04x\n", g->attrs.bcdUSB);
+       fprintf(stdout, "  idVendor\t\t0x%04x\n", g->attrs.idVendor);
+       fprintf(stdout, "  idProduct\t\t0x%04x\n", g->attrs.idProduct);
        fprintf(stdout, "  Serial Number\t\t%s\n", g->str_ser);
        fprintf(stdout, "  Manufacturer\t\t%s\n", g->str_mnf);
        fprintf(stdout, "  Product\t\t%s\n", g->str_prd);
index 877af0a..1f31596 100644 (file)
@@ -20,6 +20,7 @@
 #include <dirent.h>
 #include <sys/queue.h>
 #include <netinet/ether.h>
+#include <stdint.h>
 
 /**
  * @file include/usbg/usbg.h
@@ -57,14 +58,14 @@ struct state
  */
 struct gadget_attrs
 {
-       int bcdusb;
-       int dclass;
-       int dsubclass;
-       int dproto;
-       int maxpacket;
-       int vendor;
-       int product;
-       int bcddevice;
+       uint16_t bcdUSB;
+       uint8_t bDeviceClass;
+       uint8_t bDeviceSubClass;
+       uint8_t bDeviceProtocol;
+       uint8_t bMaxPacketSize0;
+       uint16_t idVendor;
+       uint16_t idProduct;
+       uint16_t bcdDevice;
 };
 
 
@@ -256,53 +257,59 @@ extern struct config *usbg_get_config(struct gadget *g, const char *name);
  * @brief Create a new USB gadget device
  * @param s Pointer to state
  * @param name Name of the gadget
- * @param vendor Gadget vendor ID
- * @param product Gadget product ID
+ * @param idVendor Gadget vendor ID
+ * @param idProduct Gadget product ID
  * @return Pointer to gadget or NULL if the gadget cannot be created
  */
-extern struct gadget *usbg_create_gadget(struct state *s, char *name, int vendor, int product);
+extern struct gadget *usbg_create_gadget(struct state *s, char *name,
+               uint16_t idVendor, uint16_t idProduct);
 
 /**
  * @brief Set the USB gadget device class code
  * @param g Pointer to gadget
- * @param dclass USB device class code
+ * @param bDeviceClass USB device class code
  */
-extern void usbg_set_gadget_device_class(struct gadget *g, int dclass);
+extern void usbg_set_gadget_device_class(struct gadget *g,
+               uint8_t bDeviceClass);
 
 /**
  * @brief Set the USB gadget protocol code
  * @param g Pointer to gadget
- * @param dprotocol USB protocol code
+ * @param bDeviceProtocol USB protocol code
  */
-extern void usbg_set_gadget_device_protocol(struct gadget *g, int dproto);
+extern void usbg_set_gadget_device_protocol(struct gadget *g,
+               uint8_t bDeviceProtocol);
 
 /**
  * @brief Set the USB gadget device subclass code
  * @param g Pointer to gadget
- * @param dsubclass USB device subclass code
+ * @param bDeviceSubClass USB device subclass code
  */
-extern void usbg_set_gadget_device_subclass(struct gadget *g, int dsubclass);
+extern void usbg_set_gadget_device_subclass(struct gadget *g,
+               uint8_t bDeviceSubClass);
 
 /**
  * @brief Set the maximum packet size for a gadget
  * @param g Pointer to gadget
- * @param maxpacket Maximum packet size
+ * @param bMaxPacketSize0 Maximum packet size
  */
-extern void usbg_set_gadget_device_max_packet(struct gadget *g, int maxpacket);
+extern void usbg_set_gadget_device_max_packet(struct gadget *g,
+               uint8_t bMaxPacketSize0);
 
 /**
  * @brief Set the gadget device BCD release number
  * @param g Pointer to gadget
- * @param bcddevice BCD release number
+ * @param bcdDevice BCD release number
  */
-extern void usbg_set_gadget_device_bcd_device(struct gadget *g, int bcddevice);
+extern void usbg_set_gadget_device_bcd_device(struct gadget *g,
+               uint16_t bcdDevice);
 
 /**
  * @brief Set the gadget device BCD USB version
  * @param g Pointer to gadget
- * @param bcdusb BCD USB version
+ * @param bcdUSB BCD USB version
  */
-extern void usbg_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb);
+extern void usbg_set_gadget_device_bcd_usb(struct gadget *g, uint16_t bcdUSB);
 
 /**
  * @brief Set the serial number for a gadget
index c926229..f5e06ba 100644 (file)
@@ -325,14 +325,14 @@ static void usbg_parse_gadget_attrs(char *path, char *name,
                struct gadget_attrs *g_attrs)
 {
        /* Actual attributes */
-       g_attrs->dclass = usbg_read_hex(path, name, "bDeviceClass");
-       g_attrs->dsubclass = usbg_read_hex(path, name, "bDeviceSubClass");
-       g_attrs->dproto = usbg_read_hex(path, name, "bDeviceProtocol");
-       g_attrs->maxpacket = usbg_read_hex(path, name, "bMaxPacketSize0");
-       g_attrs->bcddevice = usbg_read_hex(path, name, "bcdDevice");
-       g_attrs->bcdusb = usbg_read_hex(path, name, "bcdUSB");
-       g_attrs->vendor = usbg_read_hex(path, name, "idVendor");
-       g_attrs->product = usbg_read_hex(path, name, "idProduct");
+       g_attrs->bcdUSB = (uint16_t)usbg_read_hex(path, name, "bcdUSB");
+       g_attrs->bDeviceClass = (uint8_t)usbg_read_hex(path, name, "bDeviceClass");
+       g_attrs->bDeviceSubClass = (uint8_t)usbg_read_hex(path, name, "bDeviceSubClass");
+       g_attrs->bDeviceProtocol = (uint8_t)usbg_read_hex(path, name, "bDeviceProtocol");
+       g_attrs->bMaxPacketSize0 = (uint8_t)usbg_read_hex(path, name, "bMaxPacketSize0");
+       g_attrs->idVendor = (uint16_t)usbg_read_hex(path, name, "idVendor");
+       g_attrs->idProduct = (uint16_t)usbg_read_hex(path, name, "idProduct");
+       g_attrs->bcdDevice = (uint16_t)usbg_read_hex(path, name, "bcdDevice");
 }
 
 static void usbg_parse_strings(char *path, struct gadget *g)
@@ -508,7 +508,7 @@ struct binding *usbg_get_link_binding(struct config *c, struct function *f)
 }
 
 struct gadget *usbg_create_gadget(struct state *s, char *name,
-                                   int vendor, int product)
+               uint16_t idVendor, uint16_t idProduct)
 {
        char gpath[USBG_MAX_PATH_LENGTH];
        struct gadget *g, *cur;
@@ -544,8 +544,8 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
                return NULL;
        }
 
-       usbg_write_hex16(s->path, name, "idVendor", vendor);
-       usbg_write_hex16(s->path, name, "idProduct", product);
+       usbg_write_hex16(s->path, name, "idVendor", idVendor);
+       usbg_write_hex16(s->path, name, "idProduct", idProduct);
 
        usbg_parse_gadget_attrs(s->path, name, &g->attrs);
        usbg_parse_strings(s->path, g);
@@ -566,40 +566,40 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
        return g;
 }
 
-void usbg_set_gadget_device_class(struct gadget *g, int dclass)
+void usbg_set_gadget_device_class(struct gadget *g, uint8_t bDeviceClass)
 {
-       g->attrs.dclass = dclass;
-       usbg_write_hex8(g->path, "", "bDeviceClass", dclass);
+       g->attrs.bDeviceClass = bDeviceClass;
+       usbg_write_hex8(g->path, "", "bDeviceClass", bDeviceClass);
 }
 
-void usbg_set_gadget_device_protocol(struct gadget *g, int dproto)
+void usbg_set_gadget_device_protocol(struct gadget *g, uint8_t bDeviceProtocol)
 {
-       g->attrs.dproto = dproto;
-        usbg_write_hex8(g->path, "", "bDeviceProtocol", dproto);
+       g->attrs.bDeviceProtocol = bDeviceProtocol;
+       usbg_write_hex8(g->path, "", "bDeviceProtocol", bDeviceProtocol);
 }
 
-void usbg_set_gadget_device_subclass(struct gadget *g, int dsubclass)
+void usbg_set_gadget_device_subclass(struct gadget *g, uint8_t bDeviceSubClass)
 {
-       g->attrs.dsubclass = dsubclass;
-       usbg_write_hex8(g->path, "", "bDeviceSubClass", dsubclass);
+       g->attrs.bDeviceSubClass = bDeviceSubClass;
+       usbg_write_hex8(g->path, "", "bDeviceSubClass", bDeviceSubClass);
 }
 
-void usbg_set_gadget_device_max_packet(struct gadget *g, int maxpacket)
+void usbg_set_gadget_device_max_packet(struct gadget *g, uint8_t bMaxPacketSize0)
 {
-       g->attrs.maxpacket = maxpacket;
-       usbg_write_hex8(g->path, "", "bMaxPacketSize0", maxpacket);
+       g->attrs.bMaxPacketSize0 = bMaxPacketSize0;
+       usbg_write_hex8(g->path, "", "bMaxPacketSize0", bMaxPacketSize0);
 }
 
-void usbg_set_gadget_device_bcd_device(struct gadget *g, int bcddevice)
+void usbg_set_gadget_device_bcd_device(struct gadget *g, uint16_t bcdDevice)
 {
-       g->attrs.bcddevice = bcddevice;
-       usbg_write_hex16(g->path, "", "bcdDevice", bcddevice);
+       g->attrs.bcdDevice = bcdDevice;
+       usbg_write_hex16(g->path, "", "bcdDevice", bcdDevice);
 }
 
-void usbg_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb)
+void usbg_set_gadget_device_bcd_usb(struct gadget *g, uint16_t bcdUSB)
 {
-       g->attrs.bcdusb = bcdusb;
-       usbg_write_hex16(g->path, "", "bcdUSB", bcdusb);
+       g->attrs.bcdUSB = bcdUSB;
+       usbg_write_hex16(g->path, "", "bcdUSB", bcdUSB);
 }
 
 void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno)