summaryrefslogtreecommitdiff
path: root/include/hid_dump/iface.h
blob: 979928a87dfbaafffa5c7af7e594140ddf73798f (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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/** @file
 * @brief hid-dump - interface
 *
 * Copyright (C) 2010 Nikolai Kondrashov
 *
 * This file is part of hid-dump.
 *
 * Hid-dump 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
 * (at your option) any later version.
 *
 * Hid-dump 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 hid-dump; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @author Nikolai Kondrashov <spbnick@gmail.com>
 *
 * @(#) $Id$
 */

#ifndef __HID_DUMP_IFACE_H__
#define __HID_DUMP_IFACE_H__

#include <stdbool.h>
#include <libusb-1.0/libusb.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct hid_dump_iface hid_dump_iface;

struct hid_dump_iface {
    hid_dump_iface         *next;
    libusb_device_handle   *handle;     /**< Device handle */
    uint8_t                 number;     /**< Interface number */
    bool                    detached;   /**< True if the interface was
                                             detached from the kernel
                                             driver, false otherwise */
    bool                    claimed;    /**< True if the interface was
                                             claimed */
};

extern bool hid_dump_iface_valid(const hid_dump_iface *iface);

extern hid_dump_iface *hid_dump_iface_new(libusb_device_handle *handle, uint8_t number);

static inline bool
hid_dump_iface_list_empty(const hid_dump_iface *list)
{
    return list == NULL;
}


extern bool hid_dump_iface_list_valid(const hid_dump_iface *list);

extern void hid_dump_iface_list_free(hid_dump_iface *list);


/**
 * Fetch a list of specified class interfaces from a device.
 *
 * @param handle        The device handle to fetch interface list from.
 * @param iface_class   The interface class to match against.
 * @param plist         Location for the resulting list head; could be NULL.
 *
 * @return Libusb error code.
 */
enum libusb_error
hid_dump_iface_list_new_by_class(libusb_device_handle  *handle,
                                 uint8_t                iface_class,
                                 hid_dump_iface       **plist);

/**
 * Filter an interface list by an optional interface number, resulting
 * either in an empty, a single-interface, or an unmodified list.
 *
 * @param plist     The original list head.
 * @param number    The interface number to match against, or a negative
 *                  integer meaning there is no restriction.
 *
 * @return The resulting list head
 */
extern hid_dump_iface *hid_dump_iface_list_fltr_by_num(
                                                hid_dump_iface *list,
                                                int             number);

/**
 * Detach all interfaces in a list from their kernel drivers (if any).
 *
 * @param list  The list of interfaces to detach.
 *
 * @return Libusb error code.
 */
extern enum libusb_error hid_dump_iface_list_detach(hid_dump_iface *list);

/**
 * Attach all interfaces in a list to their kernel drivers (if were detached
 * before).
 *
 * @param list  The list of interfaces to attach.
 *
 * @return Libusb error code.
 */
extern enum libusb_error hid_dump_iface_list_attach(hid_dump_iface *list);

/**
 * Claim all interfaces in a list.
 *
 * @param list  The list of interfaces to claim.
 *
 * @return Libusb error code.
 */
extern enum libusb_error hid_dump_iface_list_claim(hid_dump_iface *list);

/**
 * Release all interfaces in a list (if were claimed before).
 *
 * @param list  The list of interfaces to release.
 *
 * @return Libusb error code.
 */
extern enum libusb_error hid_dump_iface_list_release(hid_dump_iface *list);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* __HID_DUMP_IFACE_H__ */