1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-26 01:55:53 +03:00

libusbgx: Change gadget attributes size and names.

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>
This commit is contained in:
Krzysztof Opasiak 2014-02-11 15:44:48 +01:00
parent 6ce3bdaad3
commit 652d2dd8ca
3 changed files with 68 additions and 61 deletions

View file

@ -30,16 +30,16 @@
void show_gadget(struct gadget *g) void show_gadget(struct gadget *g)
{ {
fprintf(stdout, "ID %04x:%04x '%s'\n", 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, " UDC\t\t\t%s\n", g->udc);
fprintf(stdout, " bDeviceClass\t\t0x%02x\n", g->attrs.dclass); fprintf(stdout, " bDeviceClass\t\t0x%02x\n", g->attrs.bDeviceClass);
fprintf(stdout, " bDeviceSubClass\t0x%02x\n", g->attrs.dsubclass); fprintf(stdout, " bDeviceSubClass\t0x%02x\n", g->attrs.bDeviceSubClass);
fprintf(stdout, " bDeviceProtocol\t0x%02x\n", g->attrs.dproto); fprintf(stdout, " bDeviceProtocol\t0x%02x\n", g->attrs.bDeviceProtocol);
fprintf(stdout, " bMaxPacketSize0\t0x%02x\n", g->attrs.maxpacket); fprintf(stdout, " bMaxPacketSize0\t0x%02x\n", g->attrs.bMaxPacketSize0);
fprintf(stdout, " bcdDevice\t\t0x%04x\n", g->attrs.bcddevice); fprintf(stdout, " bcdDevice\t\t0x%04x\n", g->attrs.bcdDevice);
fprintf(stdout, " bcdUSB\t\t0x%04x\n", g->attrs.bcdusb); fprintf(stdout, " bcdUSB\t\t0x%04x\n", g->attrs.bcdUSB);
fprintf(stdout, " idVendor\t\t0x%04x\n", g->attrs.vendor); fprintf(stdout, " idVendor\t\t0x%04x\n", g->attrs.idVendor);
fprintf(stdout, " idProduct\t\t0x%04x\n", g->attrs.product); fprintf(stdout, " idProduct\t\t0x%04x\n", g->attrs.idProduct);
fprintf(stdout, " Serial Number\t\t%s\n", g->str_ser); fprintf(stdout, " Serial Number\t\t%s\n", g->str_ser);
fprintf(stdout, " Manufacturer\t\t%s\n", g->str_mnf); fprintf(stdout, " Manufacturer\t\t%s\n", g->str_mnf);
fprintf(stdout, " Product\t\t%s\n", g->str_prd); fprintf(stdout, " Product\t\t%s\n", g->str_prd);

View file

@ -20,6 +20,7 @@
#include <dirent.h> #include <dirent.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <netinet/ether.h> #include <netinet/ether.h>
#include <stdint.h>
/** /**
* @file include/usbg/usbg.h * @file include/usbg/usbg.h
@ -57,14 +58,14 @@ struct state
*/ */
struct gadget_attrs struct gadget_attrs
{ {
int bcdusb; uint16_t bcdUSB;
int dclass; uint8_t bDeviceClass;
int dsubclass; uint8_t bDeviceSubClass;
int dproto; uint8_t bDeviceProtocol;
int maxpacket; uint8_t bMaxPacketSize0;
int vendor; uint16_t idVendor;
int product; uint16_t idProduct;
int bcddevice; 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 * @brief Create a new USB gadget device
* @param s Pointer to state * @param s Pointer to state
* @param name Name of the gadget * @param name Name of the gadget
* @param vendor Gadget vendor ID * @param idVendor Gadget vendor ID
* @param product Gadget product ID * @param idProduct Gadget product ID
* @return Pointer to gadget or NULL if the gadget cannot be created * @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 * @brief Set the USB gadget device class code
* @param g Pointer to gadget * @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 * @brief Set the USB gadget protocol code
* @param g Pointer to gadget * @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 * @brief Set the USB gadget device subclass code
* @param g Pointer to gadget * @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 * @brief Set the maximum packet size for a gadget
* @param g Pointer to 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 * @brief Set the gadget device BCD release number
* @param g Pointer to gadget * @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 * @brief Set the gadget device BCD USB version
* @param g Pointer to gadget * @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 * @brief Set the serial number for a gadget

View file

@ -325,14 +325,14 @@ static void usbg_parse_gadget_attrs(char *path, char *name,
struct gadget_attrs *g_attrs) struct gadget_attrs *g_attrs)
{ {
/* Actual attributes */ /* Actual attributes */
g_attrs->dclass = usbg_read_hex(path, name, "bDeviceClass"); g_attrs->bcdUSB = (uint16_t)usbg_read_hex(path, name, "bcdUSB");
g_attrs->dsubclass = usbg_read_hex(path, name, "bDeviceSubClass"); g_attrs->bDeviceClass = (uint8_t)usbg_read_hex(path, name, "bDeviceClass");
g_attrs->dproto = usbg_read_hex(path, name, "bDeviceProtocol"); g_attrs->bDeviceSubClass = (uint8_t)usbg_read_hex(path, name, "bDeviceSubClass");
g_attrs->maxpacket = usbg_read_hex(path, name, "bMaxPacketSize0"); g_attrs->bDeviceProtocol = (uint8_t)usbg_read_hex(path, name, "bDeviceProtocol");
g_attrs->bcddevice = usbg_read_hex(path, name, "bcdDevice"); g_attrs->bMaxPacketSize0 = (uint8_t)usbg_read_hex(path, name, "bMaxPacketSize0");
g_attrs->bcdusb = usbg_read_hex(path, name, "bcdUSB"); g_attrs->idVendor = (uint16_t)usbg_read_hex(path, name, "idVendor");
g_attrs->vendor = usbg_read_hex(path, name, "idVendor"); g_attrs->idProduct = (uint16_t)usbg_read_hex(path, name, "idProduct");
g_attrs->product = 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) 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, 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]; char gpath[USBG_MAX_PATH_LENGTH];
struct gadget *g, *cur; struct gadget *g, *cur;
@ -544,8 +544,8 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
return NULL; return NULL;
} }
usbg_write_hex16(s->path, name, "idVendor", vendor); usbg_write_hex16(s->path, name, "idVendor", idVendor);
usbg_write_hex16(s->path, name, "idProduct", product); usbg_write_hex16(s->path, name, "idProduct", idProduct);
usbg_parse_gadget_attrs(s->path, name, &g->attrs); usbg_parse_gadget_attrs(s->path, name, &g->attrs);
usbg_parse_strings(s->path, g); usbg_parse_strings(s->path, g);
@ -566,40 +566,40 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
return g; 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; g->attrs.bDeviceClass = bDeviceClass;
usbg_write_hex8(g->path, "", "bDeviceClass", dclass); 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; g->attrs.bDeviceProtocol = bDeviceProtocol;
usbg_write_hex8(g->path, "", "bDeviceProtocol", dproto); 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; g->attrs.bDeviceSubClass = bDeviceSubClass;
usbg_write_hex8(g->path, "", "bDeviceSubClass", dsubclass); 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; g->attrs.bMaxPacketSize0 = bMaxPacketSize0;
usbg_write_hex8(g->path, "", "bMaxPacketSize0", maxpacket); 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; g->attrs.bcdDevice = bcdDevice;
usbg_write_hex16(g->path, "", "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; g->attrs.bcdUSB = bcdUSB;
usbg_write_hex16(g->path, "", "bcdUSB", bcdusb); usbg_write_hex16(g->path, "", "bcdUSB", bcdUSB);
} }
void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno) void usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno)