- #include <stdio.h>
- #include <usb.h>
- static struct usb_device *find_device(uint16_t vendor, uint16_t product);
- static char data_pkt_0[] =
- { 0x07, 0x27, 0x00, 0x00, 0xD8, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static char wht_pkt_1[] =
- { 0x7F, 0x01, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x07, 0x77, 0x00, 0x00, 0x07, 0x70, 0x00, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x70, 0x00, 0x70, 0x77, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x70, 0x00, 0x00, 0x77,
- 0x00, 0x00, 0x70, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x07, 0x00, 0x77 };
- static char wht_pkt_2[] =
- { 0x7F, 0x02, 0x3C, 0x00, 0x00, 0x00, 0x70, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x07, 0x00, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x07, 0x77, 0x00, 0x00,
- 0x07, 0x70, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x70, 0x00, 0x70, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x70, 0x00, 0x00, 0x77, 0x00, 0x00, 0x70, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77 };
- static char wht_pkt_3[] =
- { 0x7F, 0x03, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x07, 0x00, 0x77,
- 0x00, 0x00, 0x70, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x00, 0x07, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
- 0x07, 0x77, 0x00, 0x00, 0x07, 0x70, 0x00, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x70, 0x00, 0x70, 0x77, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x70, 0x00, 0x00, 0x77 };
- static char wht_pkt_4[] =
- { 0x7F, 0x04, 0x24, 0x00, 0x00, 0x00, 0x70, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x00, 0x07, 0x00, 0x77, 0x00, 0x00, 0x70, 0x00,
- 0x00, 0x77, 0x00, 0x00, 0x00, 0x07, 0x00, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static char blk_pkt_1[] =
- { 0x7F, 0x01, 0x3C, 0x00, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77 };
- static char blk_pkt_2[] =
- { 0x7F, 0x02, 0x3C, 0x00, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x07, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77 };
- static char blk_pkt_3[] =
- { 0x7F, 0x03, 0x3C, 0x00, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x07, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77 };
- static char blk_pkt_4[] =
- { 0x7F, 0x04, 0x24, 0x00, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
- 0x77, 0x77, 0x77, 0x77, 0x07, 0x77, 0x77, 0x77,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- int main(int argc, char **argv)
- {
- struct usb_device *dev;
- struct usb_dev_handle *handle;
- int bytes_written = 0;
- int status = 0;
- printf("Searching for Corsair K70 RGB keyboard...\n");
- dev = find_device(0x1B1C, 0x1B13);
- if(dev == NULL)
- {
- printf("Corsair K70 RGB keyboard not detected :(\n");
- return 1;
- }
- else
- {
- printf("Corsair K70 RGB keyboard detected successfully :)\n");
- }
- handle = usb_open(dev);
- if(handle == NULL)
- {
- printf("USB device handle did not open :(\n");
- return 1;
- }
- else
- {
- printf("USB device handle opened successfully :)\n");
- }
- status = usb_claim_interface(handle, 3);
- usb_detach_kernel_driver_np(handle, 3);
- //if(status == 0)
- //{
- // printf("USB interface claimed successfully :)\n");
- //}
- //else
- //{
- // printf("USB interface claim failed with error %d :(\n", status);
- // return 1;
- //}
- // Perform USB control message to keyboard
- //
- // Request Type: 0x21
- // Request: 0x09
- // Value 0x0300
- // Index: 0x03
- // Size: 64
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, wht_pkt_1, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, wht_pkt_2, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, wht_pkt_3, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, wht_pkt_4, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, data_pkt_0, 64, 1000);
- sleep(1);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, blk_pkt_1, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, blk_pkt_2, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, blk_pkt_3, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, blk_pkt_4, 64, 1000);
- bytes_written = usb_control_msg(handle, 0x21, 0x09, 0x0300, 0x03, data_pkt_0, 64, 1000);
- return 0;
- }
- static struct usb_device *find_device(uint16_t vendor, uint16_t product)
- {
- struct usb_bus *bus;
- struct usb_device *dev;
- struct usb_bus *busses;
- usb_init();
- usb_find_busses();
- usb_find_devices();
- busses = usb_get_busses();
- for(bus = busses; bus; bus = bus->next)
- {
- for(dev = bus->devices; dev; dev = dev->next)
- {
- if((dev->descriptor.idVendor == vendor) && (dev->descriptor.idProduct == product))
- {
- return dev;
- }
- }
- }
- return NULL;
- }
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data

