[PATCH 02/25] libusbg: Change gadget attributes size and names.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
 examples/show-gadgets.c |   18 +++++++--------
 include/usbg/usbg.h     |   53 ++++++++++++++++++++++++-------------------
 src/usbg.c              |   58 +++++++++++++++++++++++------------------------
 3 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index cc86fdf..29a30d3 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -30,16 +30,16 @@
 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);
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index afd788c..840c047 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -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
diff --git a/src/usbg.c b/src/usbg.c
index c926229..f5e06ba 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -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)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux