[PATCH 01/25] libusbg: Separate gadget attributes from gadget.

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

 



Gadget attributes should be placed in external structure
because they are almost that same as USB device descriptor.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 examples/show-gadgets.c |   18 +++++++++---------
 include/usbg/usbg.h     |   28 ++++++++++++++++++++--------
 src/usbg.c              |   35 ++++++++++++++++++-----------------
 3 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index fa90b88..cc86fdf 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->vendor, g->product, g->name);
+		g->attrs.vendor, g->attrs.product, g->name);
 	fprintf(stdout, "  UDC\t\t\t%s\n", g->udc);
-	fprintf(stdout, "  bDeviceClass\t\t0x%02x\n", g->dclass);
-	fprintf(stdout, "  bDeviceSubClass\t0x%02x\n", g->dsubclass);
-	fprintf(stdout, "  bDeviceProtocol\t0x%02x\n", g->dproto);
-	fprintf(stdout, "  bMaxPacketSize0\t0x%02x\n", g->maxpacket);
-	fprintf(stdout, "  bcdDevice\t\t0x%04x\n", g->bcddevice);
-	fprintf(stdout, "  bcdUSB\t\t0x%04x\n", g->bcdusb);
-	fprintf(stdout, "  idVendor\t\t0x%04x\n", g->vendor);
-	fprintf(stdout, "  idProduct\t\t0x%04x\n", g->product);
+	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, "  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 d2c9f0c..afd788c 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -52,22 +52,34 @@ struct state
 };
 
 /**
- * @struct gadget
+ * @struct gadget_attrs
  * @brief USB gadget device attributes
  */
-struct gadget
+struct gadget_attrs
 {
-	char name[USBG_MAX_NAME_LENGTH];
-	char path[USBG_MAX_PATH_LENGTH];
-	char udc[USBG_MAX_STR_LENGTH];
+	int bcdusb;
 	int dclass;
 	int dsubclass;
 	int dproto;
 	int maxpacket;
-	int bcddevice;
-	int bcdusb;
-	int product;
 	int vendor;
+	int product;
+	int bcddevice;
+};
+
+
+/**
+ * @struct gadget
+ * @brief USB gadget device
+ */
+struct gadget
+{
+	char name[USBG_MAX_NAME_LENGTH];
+	char path[USBG_MAX_PATH_LENGTH];
+	char udc[USBG_MAX_STR_LENGTH];
+
+	struct gadget_attrs attrs;
+
 	char str_ser[USBG_MAX_STR_LENGTH];
 	char str_mnf[USBG_MAX_STR_LENGTH];
 	char str_prd[USBG_MAX_STR_LENGTH];
diff --git a/src/usbg.c b/src/usbg.c
index b2d3596..c926229 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -321,17 +321,18 @@ static int usbg_parse_configs(char *path, struct gadget *g)
 	return 0;
 }
 
-static void usbg_parse_attrs(char *path, struct gadget *g)
+static void usbg_parse_gadget_attrs(char *path, char *name,
+		struct gadget_attrs *g_attrs)
 {
 	/* Actual attributes */
-	g->dclass = usbg_read_hex(path, g->name, "bDeviceClass");
-	g->dsubclass = usbg_read_hex(path, g->name, "bDeviceSubClass");
-	g->dproto = usbg_read_hex(path, g->name, "bDeviceProtocol");
-	g->maxpacket = usbg_read_hex(path, g->name, "bMaxPacketSize0");
-	g->bcddevice = usbg_read_hex(path, g->name, "bcdDevice");
-	g->bcdusb = usbg_read_hex(path, g->name, "bcdUSB");
-	g->vendor = usbg_read_hex(path, g->name, "idVendor");
-	g->product = usbg_read_hex(path, g->name, "idProduct");
+	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");
 }
 
 static void usbg_parse_strings(char *path, struct gadget *g)
@@ -363,7 +364,7 @@ static int usbg_parse_gadgets(char *path, struct state *s)
 		g->parent = s;
 		/* UDC bound to, if any */
 		usbg_read_string(path, g->name, "UDC", g->udc);
-		usbg_parse_attrs(path, g);
+		usbg_parse_gadget_attrs(path, g->name, &g->attrs);
 		usbg_parse_strings(path, g);
 		usbg_parse_functions(path, g);
 		usbg_parse_configs(path, g);
@@ -546,7 +547,7 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
 	usbg_write_hex16(s->path, name, "idVendor", vendor);
 	usbg_write_hex16(s->path, name, "idProduct", product);
 
-	usbg_parse_attrs(s->path, g);
+	usbg_parse_gadget_attrs(s->path, name, &g->attrs);
 	usbg_parse_strings(s->path, g);
 
 	/* Insert in string order */
@@ -567,37 +568,37 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
 
 void usbg_set_gadget_device_class(struct gadget *g, int dclass)
 {
-	g->dclass = dclass;
+	g->attrs.dclass = dclass;
 	usbg_write_hex8(g->path, "", "bDeviceClass", dclass);
 }
 
 void usbg_set_gadget_device_protocol(struct gadget *g, int dproto)
 {
-	g->dproto = dproto;
+	g->attrs.dproto = dproto;
 	 usbg_write_hex8(g->path, "", "bDeviceProtocol", dproto);
 }
 
 void usbg_set_gadget_device_subclass(struct gadget *g, int dsubclass)
 {
-	g->dsubclass = dsubclass;
+	g->attrs.dsubclass = dsubclass;
 	usbg_write_hex8(g->path, "", "bDeviceSubClass", dsubclass);
 }
 
 void usbg_set_gadget_device_max_packet(struct gadget *g, int maxpacket)
 {
-	g->maxpacket = maxpacket;
+	g->attrs.maxpacket = maxpacket;
 	usbg_write_hex8(g->path, "", "bMaxPacketSize0", maxpacket);
 }
 
 void usbg_set_gadget_device_bcd_device(struct gadget *g, int bcddevice)
 {
-	g->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)
 {
-	g->bcdusb = bcdusb;
+	g->attrs.bcdusb = bcdusb;
 	usbg_write_hex16(g->path, "", "bcdUSB", bcdusb);
 }
 
-- 
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