Working on PoC, trying to get bulk_transfer to work
This commit is contained in:
commit
840566635b
|
@ -0,0 +1,136 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define EZP2010_VID 0x10c4
|
||||
#define EZP2010_PID 0xf5a0
|
||||
|
||||
/* $ lsusb -d 10c4:f5a0 -v
|
||||
|
||||
Bus 001 Device 053: ID 10c4:f5a0 Cygnal Integrated Products, Inc.
|
||||
Couldn't open device, some information will be missing
|
||||
Device Descriptor:
|
||||
bLength 18
|
||||
bDescriptorType 1
|
||||
bcdUSB 2.00
|
||||
bDeviceClass 0
|
||||
bDeviceSubClass 0
|
||||
bDeviceProtocol 0
|
||||
bMaxPacketSize0 64
|
||||
idVendor 0x10c4 Cygnal Integrated Products, Inc.
|
||||
idProduct 0xf5a0
|
||||
bcdDevice 0.00
|
||||
iManufacturer 0
|
||||
iProduct 0
|
||||
iSerial 0
|
||||
bNumConfigurations 1
|
||||
Configuration Descriptor:
|
||||
bLength 9
|
||||
bDescriptorType 2
|
||||
wTotalLength 0x0020
|
||||
bNumInterfaces 1
|
||||
bConfigurationValue 1
|
||||
iConfiguration 0
|
||||
bmAttributes 0x80
|
||||
(Bus Powered)
|
||||
MaxPower 480mA
|
||||
Interface Descriptor:
|
||||
bLength 9
|
||||
bDescriptorType 4
|
||||
bInterfaceNumber 0
|
||||
bAlternateSetting 0
|
||||
bNumEndpoints 2
|
||||
bInterfaceClass 0
|
||||
bInterfaceSubClass 0
|
||||
bInterfaceProtocol 0
|
||||
iInterface 0
|
||||
Endpoint Descriptor:
|
||||
bLength 7
|
||||
bDescriptorType 5
|
||||
bEndpointAddress 0x81 EP 1 IN
|
||||
bmAttributes 2
|
||||
Transfer Type Bulk
|
||||
Synch Type None
|
||||
Usage Type Data
|
||||
wMaxPacketSize 0x0040 1x 64 bytes
|
||||
bInterval 5
|
||||
Endpoint Descriptor:
|
||||
bLength 7
|
||||
bDescriptorType 5
|
||||
bEndpointAddress 0x02 EP 2 OUT
|
||||
bmAttributes 2
|
||||
Transfer Type Bulk
|
||||
Synch Type None
|
||||
Usage Type Data
|
||||
wMaxPacketSize 0x0040 1x 64 bytes
|
||||
bInterval 5
|
||||
*/
|
||||
|
||||
libusb_context *ctx;
|
||||
libusb_device_handle *dev;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int r = 0;
|
||||
int transfered = 0;
|
||||
|
||||
libusb_init(&ctx);
|
||||
libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
|
||||
|
||||
dev = libusb_open_device_with_vid_pid(ctx, EZP2010_VID, EZP2010_PID);
|
||||
if (dev) {
|
||||
r = libusb_set_configuration(dev, 0);
|
||||
if (r > 0) {
|
||||
perror("libusb_set_configuration");
|
||||
}
|
||||
|
||||
r = libusb_claim_interface(dev, 0);
|
||||
if (r > 0) {
|
||||
perror("libusb_claim_interface");
|
||||
}
|
||||
|
||||
r = libusb_set_interface_alt_setting(dev, 0, 0);
|
||||
if (r > 0) {
|
||||
perror("libusb_set_configuration");
|
||||
}
|
||||
|
||||
printf("set control\n");
|
||||
// LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT = 0x40
|
||||
r = libusb_control_transfer(dev, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, 0, 0xffff, 0, NULL, 0, 500);
|
||||
if (r > 0) {
|
||||
perror("libusb_control_transfer");
|
||||
}
|
||||
|
||||
r = libusb_control_transfer(dev, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, 1, 0x2000, 0, NULL, 0, 500);
|
||||
if (r > 0) {
|
||||
perror("libusb_control_transfer");
|
||||
}
|
||||
|
||||
printf("set control\n");
|
||||
|
||||
unsigned char bufferOut[2] = {'\x17', '\0'};
|
||||
r = libusb_bulk_transfer(dev, 0x81, bufferOut, 2, &transfered, 500);
|
||||
if (r > 0) {
|
||||
perror("libusb_bulk_transfer");
|
||||
}
|
||||
printf("Bytes sent: %d\n", transfered);
|
||||
|
||||
unsigned char bufferIn[256] = {0};
|
||||
r = libusb_interrupt_transfer(dev, 0x02, bufferIn, 0x20, &transfered, 500);
|
||||
if (r > 0) {
|
||||
perror("libusb_bulk_transfer");
|
||||
}
|
||||
printf("Bytes received: %d\n", transfered);
|
||||
printf("Packet: %s\n", bufferIn);
|
||||
|
||||
r = libusb_release_interface(dev, 0);
|
||||
if (r > 0) {
|
||||
perror("libusb_release_interface");
|
||||
}
|
||||
libusb_close(dev);
|
||||
}
|
||||
|
||||
libusb_exit(ctx);
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
project(8051)
|
||||
|
||||
add_definitions('-g')
|
||||
add_definitions('-Wall')
|
||||
|
||||
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} usb-1.0)
|
Loading…
Reference in New Issue