summaryrefslogtreecommitdiff
path: root/lib/unifying.h
blob: 16fd88895d465a9cd395d18e35214d97837f2f6c (plain)
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
/*
 * Generic routines for communicating with Logitech Unifying devices.
 *
 * Copyright (C) 2014 Peter Wu <peter@lekensteyn.nl>
 *
 * This program 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UNIFYING_H
#define UNIFYING_H
#include <stdint.h>

typedef struct UnifyingState UnifyingState;

typedef enum {
	FWVER_MAIN = 0, /**< Main firmware version */
	FWVER_BL,       /**< Bootloader version */
	FWVER_HW,       /**< Hardware version */
} FirmwareType;

typedef struct {
	char prefix[4]; /**< Prefix of the firmware version (if any) */
	uint8_t major;
	uint8_t minor;
	uint16_t build;
} FirmwareVersion;

/**
 * Attempts to open a Unifying device.
 *
 * @param fd    File descriptor of the hidraw device.
 * @return A pointer to a structure that must be released by
 *         unifying_device_close(), or NULL on error.
 */
UnifyingState *unifying_new(int fd);

/**
 * Closes the file descriptor associated with this device and releases memory
 * claimed for this structure.
 *
 * @param s     State to be freed.
 */
void unifying_close(UnifyingState *s);

int unifying_rvr_get_version(UnifyingState *s, FirmwareType type,
                             FirmwareVersion *fw);
int unifying_rvr_get_serial(UnifyingState *s, uint32_t *serial);

/* general device information */
int unifying_dev_get_version(UnifyingState *s, uint8_t ix, FirmwareType type,
                             FirmwareVersion *fw);
int unifying_dev_get_short_name(UnifyingState *s, uint8_t ix, char *name);
int unifying_dev_get_name(UnifyingState *s, uint8_t ix, char **name);
int unifying_dev_get_wpid(UnifyingState *s, uint8_t ix, uint16_t *wpid);
int unifying_dev_get_type(UnifyingState *s, uint8_t ix, uint8_t *devtype);
int unifying_dev_get_serial(UnifyingState *s, uint8_t ix, uint32_t *serial);

/* pairing related */
/**
 * Allows new devices to pair with the receiver.
 *
 * @param s     Unifying device state.
 * @param timeout Open lock timeout in seconds (0 is default, 30s).
 */
int unifying_dev_pairing_open(UnifyingState *s, uint8_t timeout);
int unifying_dev_pairing_unpair(UnifyingState *s, uint8_t ix);
int unifying_dev_pairing_close(UnifyingState *s);
#endif