/* * modification of gladiac's g5.c * USE AT OWN RISK!!!!! :) * * This is a implementation of the Logitech G5 protocol. * Compile it with: * * gcc -o g5-test -lusb g5.c && ./g5-test * * The lomoco team. * */ #include #include #define TIMEOUT 0x1000 #define VENDOR 0x046d #define MOUSE 0xc041 unsigned char buf[1024]={0}; usb_dev_handle *handle; int error_int; char kerneldriver[32]; void delbuf() { int d; for(d=0;d<1024;++d) buf[d]=0; } void printbuf(int cnt) { int d; for(d=0;d 0) { for (i=0; inext) { root_tree = bus->devices; for( device = root_tree; device; device = device->next ) { if ((device->descriptor.idVendor == VENDOR) && (device->descriptor.idProduct == MOUSE)) { handle = usb_open (device); /* * usbhid blocks the interface so we can't send a command * to the mouse. So remove it. It kills our mouse support * in X, but hey! */ /* get the kernel driver which blocks the interface */ usb_get_driver_np (handle, 0, kerneldriver, 32); printf("Interface 0 is used by: %s\n", kerneldriver); /* detach a kernel driver which blocks the interface */ error_int = usb_detach_kernel_driver_np (handle, 0); printf("%i\n", error_int); usb_get_driver_np (handle, 0, kerneldriver, 32); printf("Interface 0 is now used by: %s\n", kerneldriver); /* claim the interface */ error_int = usb_claim_interface (handle, 0); printf("%i\n", error_int); usb_get_string_simple (handle, device->descriptor.iProduct, string, sizeof(string)); printf ("%s\n",string); /* start here */ /* URB 1 */ desc (0x01, 0x00, 0x12); printf("urb 1:\n"); printbuf (0x12); /* URB 2 */ desc (0x02, 0x00, 0xff); printbuf (0x3b); printf("urb 2:\n"); printbuf (0x3b); /* URB 3 */ if (usb_set_configuration (handle, 0x01) < 0) perror ("urb 3:"); else printf("urb 3 succeeded\n"); /* URB 4 */ desc (0x01,0x00,0x12); printf("urb 4:\n"); printbuf (0x12); /* works till here */ // if (usb_release_interface(handle, 0) < 0) // perror ("claim"); error_int = usb_claim_interface (handle, 0); /* from usbsnoop2libusb generated file */ int ret = 0; ret = usb_control_msg(handle, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0xa, 0x000, 0x001, buf, 0x0000000, 1000); printf("5 control msg returned %d\n", ret); ret = usb_get_descriptor(handle, 0x0, 0x0, buf, 0x0000076); printf("6 get descriptor returned %d, bytes: ", ret); print_bytes(buf, ret); printf("\n"); ret = usb_get_descriptor(handle, 0x1, 0x0, buf, 0x0000012); printf("7 get descriptor returned %d, bytes: ", ret); print_bytes(buf, ret); printf("\n"); ret = usb_control_msg(handle, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0xa, 0x000, 0x000, buf, 0x0000000, 1000); printf("8 control msg returned %d", ret); printf("\n"); ret = usb_get_descriptor(handle, 0x0, 0x0, buf, 0x000009e); printf("9 get descriptor returned %d, bytes: ", ret); print_bytes(buf, ret); printf("\n"); /* URB 5? */ msg(0x21,0x0a,0x0000,0x0001,(char*)buf,0); printbuf(0); } } } return 0; }