struct usb_device *usb_add_device()
{
struct usb_device *dev = (struct usb_device *) malloc(sizeof(struct usb_device));
+ dev->conf = (struct usb_conf *) malloc(sizeof(struct usb_conf));
dev->address = 0;
/* send at first time only 8 bytes */
dev->bMaxPacketSize0 = 8;
s8 ret;
memset(buf, 0, sizeof(buf));
- ret = usb_get_dev_desc_simple(dev, buf, sizeof(buf));
+ ret = usb_get_desc_dev_simple(dev, buf, sizeof(buf));
#ifdef _DU_CORE_ADD
printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc_simple(ret: %d):\n", buf, ret);
hexdump(buf, sizeof(buf));
#endif
memset(buf, 0, sizeof(buf));
- ret = usb_get_dev_desc(dev, buf, sizeof(buf));
+ ret = usb_get_desc_dev(dev, buf, sizeof(buf));
#ifdef _DU_CORE_ADD
printf("=============\nbuf: 0x%08X\nafter usb_get_dev_desc(ret: %d):\n", buf, ret);
hexdump(buf, sizeof(buf));
if(dev->iManufacturer) {
memset(buf, 0, sizeof(buf));
man = usb_get_string_simple(dev, dev->iManufacturer, buf, sizeof(buf));
- printf("iManufacturer:\n");
- hexdump(buf, sizeof(buf));
} else {
man = (char*) malloc(11);
memset(man, '\0', sizeof(man));
memset(buf, 0, sizeof(buf));
/* in the most cases usb devices have just one configuration descriptor */
- ret = usb_get_configuration(dev, 0, buf, sizeof(buf));
- printf("=============\nbuf: 0x%08X\nafter usb_get_configuration(ret: %d):\n", buf, ret);
+ ret = usb_get_desc_configuration(dev, 0, buf, sizeof(buf));
+ printf("=============\nbuf: 0x%08X\nafter usb_get_desc_configuration(ret: %d):\n", buf, ret);
hexdump(buf, sizeof(buf));
+ printf("interfaces: %d\n", dev->conf->bNumInterfaces);
+ u8 i;
+ for(i = 1; i <= dev->conf->bNumInterfaces; i++) {
+ memset(buf, 0, sizeof(buf));
+ ret = usb_get_desc_interface(dev, i, buf, sizeof(buf));
+ printf("=============\nbuf: 0x%08X\nafter usb_get_desc_interface_%d(ret: %d):\n", buf, i, ret);
+ hexdump(buf, sizeof(buf));
+ }
+
+
/*
usb_get_descriptor(dev, DEVICE, 0, buf, 8);
/* ask first 8 bytes of device descriptor with this special
* GET Descriptor Request, when device address = 0
*/
-s8 usb_get_dev_desc_simple(struct usb_device *dev, u8 *buf, u8 size)
+s8 usb_get_desc_dev_simple(struct usb_device *dev, u8 *buf, u8 size)
{
if(size < 8) {
return -1;
return 0;
}
-s8 usb_get_dev_desc(struct usb_device *dev, u8 *buf, u8 size)
+s8 usb_get_desc_dev(struct usb_device *dev, u8 *buf, u8 size)
{
- if (size < 0x12 || usb_get_dev_desc_simple(dev, buf, size) < 0) {
+ if (size < 0x12 || usb_get_desc_dev_simple(dev, buf, size) < 0) {
return -1;
}
usb_get_descriptor(dev, DEVICE, 0, buf, size >= buf[0] ? buf[0] : size);
return 0;
}
-s8 usb_get_configuration(struct usb_device *dev, u8 index, u8 *buf, u8 size)
+s8 usb_get_desc_configuration(struct usb_device *dev, u8 index, u8 *buf, u8 size)
{
- if(size < 8) {
+ if(size < 9) {
return -1;
}
usb_get_descriptor(dev, CONFIGURATION, index, buf, 8);
usb_get_descriptor(dev, CONFIGURATION, index, buf, size >= buf[0] ? buf[0] : size);
+
+ dev->conf->bLength = buf[0];
+ dev->conf->bDescriptorType = buf[1];
+ dev->conf->wTotalLength = (u16) (buf[3] << 8 | buf[2]);
+ dev->conf->bNumInterfaces = buf[4];
+ dev->conf->bConfigurationValue = buf[5];
+ dev->conf->iConfiguration = buf[6];
+ dev->conf->bmAttributes = buf[7];
+ dev->conf->bMaxPower = buf[8];
+ return 0;
+}
+
+s8 usb_get_desc_interface(struct usb_device *dev, u8 index, u8 *buf, u8 size)
+{
+ if(size < 9) {
+ return -1;
+ }
+ usb_get_descriptor(dev, INTERFACE, index, buf, 8);
+ usb_get_descriptor(dev, INTERFACE, index, buf, size >= buf[0] ? buf[0] : size);
+
return 0;
}
s8 usb_close(struct usb_device *dev);
-s8 usb_get_device_descriptor(struct usb_device *dev, u8 *buf, u8 buflen);
-s8 usb_set_address(struct usb_device *dev, u8 address);
-s8 usb_set_configuration(struct usb_device *dev, u8 configuration);
-s8 usb_set_altinterface(struct usb_device *dev, u8 alternate);
-
-
/**
* usb_reset resets the specified device by sending a RESET down the port
* it is connected to. Returns 0 on success or < 0 on error.
/******************* Control Transfer **********************/
s8 usb_control_msg(struct usb_device *dev, u8 requesttype, u8 request, u16 value, u16 index, u16 length, u8 *buf, u16 timeout);
-s8 usb_get_string(struct usb_device *dev, u8 index, u8 langid, u8 *buf, u8 buflen);
-char *usb_get_string_simple(struct usb_device *dev, u8 index, u8 *buf, u8 size);
-s8 usb_get_dev_desc_simple(struct usb_device *dev, u8 *buf, u8 size);
-s8 usb_get_configuration(struct usb_device *dev, u8 index, u8 *buf, u8 size);
-s8 usb_get_dev_desc(struct usb_device *dev, u8 *buf, u8 size);
s8 usb_get_descriptor(struct usb_device *dev, u8 type, u8 index, u8 *buf, u8 size);
+s8 usb_get_desc_dev_simple(struct usb_device *dev, u8 *buf, u8 size);
+s8 usb_get_desc_dev(struct usb_device *dev, u8 *buf, u8 size);
+s8 usb_get_desc_configuration(struct usb_device *dev, u8 index, u8 *buf, u8 size);
+s8 usb_get_desc_interface(struct usb_device *dev, u8 index, u8 *buf, u8 size);
+
+char *usb_get_string_simple(struct usb_device *dev, u8 index, u8 *buf, u8 size);
+s8 usb_get_string(struct usb_device *dev, u8 index, u8 langid, u8 *buf, u8 buflen);
+
+s8 usb_set_address(struct usb_device *dev, u8 address);
+s8 usb_set_configuration(struct usb_device *dev, u8 configuration);
+s8 usb_set_altinterface(struct usb_device *dev, u8 alternate);
/******************* Bulk Transfer **********************/