コード例 #1
0
/**
 * Function to send to device, get response, and actually check the response
 */
struct razer_report razer_send_payload(struct usb_device *usb_dev, struct razer_report *request_report)
{
    int retval = -1;
    struct razer_report response_report = {0};

    request_report->crc = razer_calculate_crc(request_report);

    retval = razer_get_report(usb_dev, request_report, &response_report);

    if(retval == 0) {
        // Check the packet number, class and command are the same
        if(response_report.remaining_packets != request_report->remaining_packets ||
           response_report.command_class != request_report->command_class ||
           response_report.command_id.id != request_report->command_id.id) {
            print_erroneous_report(&response_report, "razermousemat", "Response doesn't match request");
//		} else if (response_report.status == RAZER_CMD_BUSY) {
//			print_erroneous_report(&response_report, "razermousemat", "Device is busy");
        } else if (response_report.status == RAZER_CMD_FAILURE) {
            print_erroneous_report(&response_report, "razermousemat", "Command failed");
        } else if (response_report.status == RAZER_CMD_NOT_SUPPORTED) {
            print_erroneous_report(&response_report, "razermousemat", "Command not supported");
        } else if (response_report.status == RAZER_CMD_TIMEOUT) {
            print_erroneous_report(&response_report, "razermousemat", "Command timed out");
        }
    } else {
        print_erroneous_report(&response_report, "razermousemat", "Invalid Report Length");
    }

    return response_report;
}
コード例 #2
0
/**
 * Get the devices serial number
 *
 * Makes a request like normal, this must change a variable in the mouse as then we
 * tell it give us data (same request for get_battery in the mouse driver) and it 
 * gives us a report.
 *
 * Supported Devices:
 *   Razer Chroma
 *   Razer BlackWidow Ultimate 2013*
 * 
 * *Untested but should work
 */
void razer_get_serial(struct usb_device *usb_dev, unsigned char* serial_string)
{
    struct razer_report response_report;
    struct razer_report request_report;
    int retval;
    int i;

    razer_prepare_report(&request_report);

    request_report.parameter_bytes_num = 0x16;
    request_report.reserved2 = 0x00;
    request_report.command = 0x82;
    request_report.sub_command = 0x00;
    request_report.command_parameters[0] = 0x00;
    request_report.crc = razer_calculate_crc(&request_report);


    retval = razer_get_usb_response(usb_dev, 0x01, &request_report, 0x01, &response_report, RAZER_BLACKWIDOW_CHROMA_WAIT_MIN_US, RAZER_BLACKWIDOW_CHROMA_WAIT_MAX_US);

    if(retval == 0)
    {
        if(response_report.report_start_marker == 0x02 && response_report.reserved2 == 0x00 && response_report.command == 0x82)
        {
            unsigned char* pointer = &response_report.sub_command;
            for(i = 0; i < 20; ++i)
            {
                serial_string[i] = *pointer;
                ++pointer;
            }
        } else
        {
            print_erroneous_report(&response_report, "razerkbd", "Invalid Report Type");
        }
    } else
    {
      print_erroneous_report(&response_report, "razerkbd", "Invalid Report Length");
    }
}