-
Notifications
You must be signed in to change notification settings - Fork 126
/
core.c
120 lines (99 loc) · 3.15 KB
/
core.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* This file is part of OpenCorsairLink.
* Copyright (C) 2017-2020 Sean Nelson <audiohacked@gmail.com>
* OpenCorsairLink is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
* OpenCorsairLink is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with OpenCorsairLink. If not, see <http://www.gnu.org/licenses/>.
*/
#include "device.h"
#include "driver.h"
#include "lowlevel/coolit.h"
#include "logic/print.h"
#include "protocol/coolit.h"
#include <errno.h>
#include <libusb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
corsairlink_coolit_device_id(
struct corsair_device_info* dev, struct libusb_device_handle* handle, uint16_t* device_id )
{
int rr;
uint8_t response[64];
uint8_t commands[64];
memset( response, 0, sizeof( response ) );
memset( commands, 0, sizeof( commands ) );
uint8_t ii = 0;
commands[++ii] = CommandId++; // Command ID
commands[++ii] = ReadOneByte; // Command Opcode
commands[++ii] = DeviceID; // Command data...
commands[0] = ii; // Length
rr = dev->lowlevel->write( handle, dev->write_endpoint, commands, 64 );
rr = dev->lowlevel->read( handle, dev->read_endpoint, response, 64 );
memcpy( device_id, response + 2, 1 );
dump_packet( response, sizeof( response ) );
return 0;
}
int
corsairlink_coolit_name(
struct corsair_device_info* dev,
struct libusb_device_handle* handle,
char* name,
uint8_t name_size )
{
snprintf( name, name_size, "%s", dev->name );
return 0;
}
int
corsairlink_coolit_vendor(
struct corsair_device_info* dev,
struct libusb_device_handle* handle,
char* name,
uint8_t name_size )
{
snprintf( name, name_size, "Corsair" );
return 0;
}
int
corsairlink_coolit_product(
struct corsair_device_info* dev,
struct libusb_device_handle* handle,
char* name,
uint8_t name_size )
{
snprintf( name, name_size, "%s", dev->name );
return 0;
}
int
corsairlink_coolit_firmware_id(
struct corsair_device_info* dev,
struct libusb_device_handle* handle,
char* firmware,
uint8_t firmware_size )
{
int rr;
uint8_t response[64];
uint8_t commands[64];
memset( response, 0, sizeof( response ) );
memset( commands, 0, sizeof( commands ) );
uint8_t ii = 0;
commands[++ii] = CommandId++; // Command ID
commands[++ii] = ReadTwoBytes; // Command Opcode
commands[++ii] = FirmwareID; // Command data...
commands[0] = ii; // Length
rr = dev->lowlevel->write( handle, dev->write_endpoint, commands, 64 );
rr = dev->lowlevel->read( handle, dev->read_endpoint, response, 64 );
snprintf(
firmware, firmware_size, "%d.%d.%d", ( response[3] & 240 ) >> 4, ( response[3] & 15 ),
response[2] );
return 0;
}