Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
hid.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <errno.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
#include <fcntl.h>
#include <poll.h>
#include <linux/hidraw.h>
#include <linux/version.h>
#include <linux/input.h>
#include "hidapi.h"
+ Include dependency graph for hid.c:

Go to the source code of this file.

Classes

struct  hid_device_
 

Macros

#define HIDIOCSFEATURE(len)   _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)
 
#define HIDIOCGFEATURE(len)   _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
 

Typedefs

typedef const char *(* hid_wrapper_udev_device_get_devnode_type) (struct udev_device *udev_device)
 
typedef struct udev_device *(* hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type) (struct udev_device *udev_device, const char *subsystem, const char *devtype)
 
typedef const char *(* hid_wrapper_udev_device_get_sysattr_value_type) (struct udev_device *udev_device, const char *sysattr)
 
typedef struct udev_device *(* hid_wrapper_udev_device_new_from_devnum_type) (struct udev *udev, char type, dev_t devnum)
 
typedef struct udev_device *(* hid_wrapper_udev_device_new_from_syspath_type) (struct udev *udev, const char *syspath)
 
typedef struct udev_device *(* hid_wrapper_udev_device_unref_type) (struct udev_device *udev_device)
 
typedef int(* hid_wrapper_udev_enumerate_add_match_subsystem_type) (struct udev_enumerate *udev_enumerate, const char *subsystem)
 
typedef struct udev_list_entry *(* hid_wrapper_udev_enumerate_get_list_entry_type) (struct udev_enumerate *udev_enumerate)
 
typedef struct udev_enumerate *(* hid_wrapper_udev_enumerate_new_type) (struct udev *udev)
 
typedef int(* hid_wrapper_udev_enumerate_scan_devices_type) (struct udev_enumerate *udev_enumerate)
 
typedef struct udev_enumerate *(* hid_wrapper_udev_enumerate_unref_type) (struct udev_enumerate *udev_enumerate)
 
typedef const char *(* hid_wrapper_udev_list_entry_get_name_type) (struct udev_list_entry *list_entry)
 
typedef struct udev_list_entry *(* hid_wrapper_udev_list_entry_get_next_type) (struct udev_list_entry *list_entry)
 
typedef struct udev *(* hid_wrapper_udev_new_type) (void)
 
typedef struct udev *(* hid_wrapper_udev_unref_type) (struct udev *udev)
 

Enumerations

enum  device_string_id { DEVICE_STRING_MANUFACTURER , DEVICE_STRING_PRODUCT , DEVICE_STRING_SERIAL , DEVICE_STRING_COUNT }
 

Functions

static void hid_wrapper_udev_close ()
 
static int hid_wrapper_udev_init ()
 
static __u32 detect_kernel_version (void)
 
static hid_devicenew_hid_device (void)
 
static wchar_t * utf8_to_wchar_t (const char *utf8)
 
static wchar_t * copy_udev_string (struct udev_device *dev, const char *udev_name)
 
static int uses_numbered_reports (__u8 *report_descriptor, __u32 size)
 
static int parse_uevent_info (const char *uevent, int *bus_type, unsigned short *vendor_id, unsigned short *product_id, char **serial_number_utf8, char **product_name_utf8)
 
static int get_device_string (hid_device *dev, enum device_string_id key, wchar_t *string, size_t maxlen)
 
int HID_API_EXPORT hid_init (void)
 Initialize the HIDAPI library.
 
int HID_API_EXPORT hid_exit (void)
 Finalize the HIDAPI library.
 
struct hid_device_info HID_API_EXPORThid_enumerate (unsigned short vendor_id, unsigned short product_id)
 Enumerate the HID Devices.
 
void HID_API_EXPORT hid_free_enumeration (struct hid_device_info *devs)
 Free an enumeration Linked List.
 
hid_devicehid_open (unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
 Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
 
hid_device *HID_API_EXPORT hid_open_path (const char *path)
 Open a HID device by its path name.
 
int HID_API_EXPORT hid_write (hid_device *dev, const unsigned char *data, size_t length)
 Write an Output report to a HID device.
 
int HID_API_EXPORT hid_read_timeout (hid_device *dev, unsigned char *data, size_t length, int milliseconds)
 Read an Input report from a HID device with timeout.
 
int HID_API_EXPORT hid_read (hid_device *dev, unsigned char *data, size_t length)
 Read an Input report from a HID device.
 
int HID_API_EXPORT hid_set_nonblocking (hid_device *dev, int nonblock)
 Set the device handle to be non-blocking.
 
int HID_API_EXPORT hid_send_feature_report (hid_device *dev, const unsigned char *data, size_t length)
 Send a Feature report to the device.
 
int HID_API_EXPORT hid_get_feature_report (hid_device *dev, unsigned char *data, size_t length)
 Get a feature report from a HID device.
 
void HID_API_EXPORT hid_close (hid_device *dev)
 Close a HID device.
 
int HID_API_EXPORT_CALL hid_get_manufacturer_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Manufacturer String from a HID device.
 
int HID_API_EXPORT_CALL hid_get_product_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Product String from a HID device.
 
int HID_API_EXPORT_CALL hid_get_serial_number_string (hid_device *dev, wchar_t *string, size_t maxlen)
 Get The Serial Number String from a HID device.
 
int HID_API_EXPORT_CALL hid_get_indexed_string (hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
 Get a string from a HID device, based on its string index.
 
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error (hid_device *dev)
 Get a string describing the last error which occurred.
 

Variables

voidhid_wrapper_handle = NULL
 
static hid_wrapper_udev_device_get_devnode_type hid_wrapper_udev_device_get_devnode = NULL
 
static hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type hid_wrapper_udev_device_get_parent_with_subsystem_devtype = NULL
 
static hid_wrapper_udev_device_get_sysattr_value_type hid_wrapper_udev_device_get_sysattr_value = NULL
 
static hid_wrapper_udev_device_new_from_devnum_type hid_wrapper_udev_device_new_from_devnum = NULL
 
static hid_wrapper_udev_device_new_from_syspath_type hid_wrapper_udev_device_new_from_syspath = NULL
 
static hid_wrapper_udev_device_unref_type hid_wrapper_udev_device_unref = NULL
 
static hid_wrapper_udev_enumerate_add_match_subsystem_type hid_wrapper_udev_enumerate_add_match_subsystem = NULL
 
static hid_wrapper_udev_enumerate_get_list_entry_type hid_wrapper_udev_enumerate_get_list_entry = NULL
 
static hid_wrapper_udev_enumerate_new_type hid_wrapper_udev_enumerate_new = NULL
 
static hid_wrapper_udev_enumerate_scan_devices_type hid_wrapper_udev_enumerate_scan_devices = NULL
 
static hid_wrapper_udev_enumerate_unref_type hid_wrapper_udev_enumerate_unref = NULL
 
static hid_wrapper_udev_list_entry_get_name_type hid_wrapper_udev_list_entry_get_name = NULL
 
static hid_wrapper_udev_list_entry_get_next_type hid_wrapper_udev_list_entry_get_next = NULL
 
static hid_wrapper_udev_new_type hid_wrapper_udev_new = NULL
 
static hid_wrapper_udev_unref_type hid_wrapper_udev_unref = NULL
 
static const char * hid_wrapper_libudev_paths []
 
const char * device_string_names []
 
static __u32 kernel_version = 0
 

Class Documentation

◆ hid_device_

struct hid_device_
+ Collaboration diagram for hid_device_:
Class Members
pthread_barrier_t barrier
int blocking
BOOL blocking
pthread_cond_t condition
int device_handle
IOHIDDeviceRef device_handle
HANDLE device_handle
int disconnected
uint8_t * input_report_buf
size_t input_report_length
struct input_report * input_reports
DWORD last_error_num
void * last_error_str
CFIndex max_input_report_len
pthread_mutex_t mutex
OVERLAPPED ol
USHORT output_report_length
char * read_buf
BOOL read_pending
CFRunLoopRef run_loop
CFStringRef run_loop_mode
pthread_barrier_t shutdown_barrier
int shutdown_thread
CFRunLoopSourceRef source
pthread_t thread
int uses_numbered_reports

Macro Definition Documentation

◆ HIDIOCGFEATURE

#define HIDIOCGFEATURE (   len)    _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)

◆ HIDIOCSFEATURE

#define HIDIOCSFEATURE (   len)    _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)

Typedef Documentation

◆ hid_wrapper_udev_device_get_devnode_type

typedef const char *(* hid_wrapper_udev_device_get_devnode_type) (struct udev_device *udev_device)

◆ hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type

typedef struct udev_device *(* hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type) (struct udev_device *udev_device, const char *subsystem, const char *devtype)

◆ hid_wrapper_udev_device_get_sysattr_value_type

typedef const char *(* hid_wrapper_udev_device_get_sysattr_value_type) (struct udev_device *udev_device, const char *sysattr)

◆ hid_wrapper_udev_device_new_from_devnum_type

typedef struct udev_device *(* hid_wrapper_udev_device_new_from_devnum_type) (struct udev *udev, char type, dev_t devnum)

◆ hid_wrapper_udev_device_new_from_syspath_type

typedef struct udev_device *(* hid_wrapper_udev_device_new_from_syspath_type) (struct udev *udev, const char *syspath)

◆ hid_wrapper_udev_device_unref_type

typedef struct udev_device *(* hid_wrapper_udev_device_unref_type) (struct udev_device *udev_device)

◆ hid_wrapper_udev_enumerate_add_match_subsystem_type

typedef int(* hid_wrapper_udev_enumerate_add_match_subsystem_type) (struct udev_enumerate *udev_enumerate, const char *subsystem)

◆ hid_wrapper_udev_enumerate_get_list_entry_type

typedef struct udev_list_entry *(* hid_wrapper_udev_enumerate_get_list_entry_type) (struct udev_enumerate *udev_enumerate)

◆ hid_wrapper_udev_enumerate_new_type

typedef struct udev_enumerate *(* hid_wrapper_udev_enumerate_new_type) (struct udev *udev)

◆ hid_wrapper_udev_enumerate_scan_devices_type

typedef int(* hid_wrapper_udev_enumerate_scan_devices_type) (struct udev_enumerate *udev_enumerate)

◆ hid_wrapper_udev_enumerate_unref_type

typedef struct udev_enumerate *(* hid_wrapper_udev_enumerate_unref_type) (struct udev_enumerate *udev_enumerate)

◆ hid_wrapper_udev_list_entry_get_name_type

typedef const char *(* hid_wrapper_udev_list_entry_get_name_type) (struct udev_list_entry *list_entry)

◆ hid_wrapper_udev_list_entry_get_next_type

typedef struct udev_list_entry *(* hid_wrapper_udev_list_entry_get_next_type) (struct udev_list_entry *list_entry)

◆ hid_wrapper_udev_new_type

typedef struct udev *(* hid_wrapper_udev_new_type) (void)

◆ hid_wrapper_udev_unref_type

typedef struct udev *(* hid_wrapper_udev_unref_type) (struct udev *udev)

Enumeration Type Documentation

◆ device_string_id

Enumerator
DEVICE_STRING_MANUFACTURER 
DEVICE_STRING_PRODUCT 
DEVICE_STRING_SERIAL 
DEVICE_STRING_COUNT 
193 {
197
199};
@ DEVICE_STRING_SERIAL
Definition hid.c:196
@ DEVICE_STRING_COUNT
Definition hid.c:198
@ DEVICE_STRING_MANUFACTURER
Definition hid.c:194
@ DEVICE_STRING_PRODUCT
Definition hid.c:195

Function Documentation

◆ copy_udev_string()

static wchar_t * copy_udev_string ( struct udev_device *  dev,
const char *  udev_name 
)
static
263{
265}
static wchar_t * utf8_to_wchar_t(const char *utf8)
Definition hid.c:243
static hid_wrapper_udev_device_get_sysattr_value_type hid_wrapper_udev_device_get_sysattr_value
Definition hid.c:74

References hid_wrapper_udev_device_get_sysattr_value, and utf8_to_wchar_t().

Referenced by hid_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ detect_kernel_version()

static __u32 detect_kernel_version ( void  )
static
211{
212 struct utsname name;
213 int major, minor, release;
214 int ret;
215
216 uname(&name);
217 ret = sscanf(name.release, "%d.%d.%d", &major, &minor, &release);
218 if (ret == 3) {
219 return KERNEL_VERSION(major, minor, release);
220 }
221
222 ret = sscanf(name.release, "%d.%d", &major, &minor);
223 if (ret == 2) {
224 return KERNEL_VERSION(major, minor, 0);
225 }
226
227 printf("Couldn't determine kernel version from version string \"%s\"\n", name.release);
228 return 0;
229}

Referenced by hid_init().

+ Here is the caller graph for this function:

◆ get_device_string()

static int get_device_string ( hid_device dev,
enum device_string_id  key,
wchar_t *  string,
size_t  maxlen 
)
static
388{
389 struct udev *udev;
390 struct udev_device *udev_dev, *parent, *hid_dev;
391 struct stat s;
392 int ret = -1;
393 char *serial_number_utf8 = NULL;
394 char *product_name_utf8 = NULL;
395
396 /* Create the udev object */
397 udev = hid_wrapper_udev_new();
398 if (!udev) {
399 printf("Can't create udev\n");
400 return -1;
401 }
402
403 /* Get the dev_t (major/minor numbers) from the file handle. */
404 ret = fstat(dev->device_handle, &s);
405 if (-1 == ret)
406 return ret;
407 /* Open a udev device from the dev_t. 'c' means character device. */
408 udev_dev = hid_wrapper_udev_device_new_from_devnum(udev, 'c', s.st_rdev);
409 if (udev_dev) {
411 udev_dev,
412 "hid",
413 NULL);
414 if (hid_dev) {
415 unsigned short dev_vid;
416 unsigned short dev_pid;
417 int bus_type;
418 size_t retm;
419
420 ret = parse_uevent_info(
422 &bus_type,
423 &dev_vid,
424 &dev_pid,
425 &serial_number_utf8,
426 &product_name_utf8);
427
428 if (bus_type == BUS_BLUETOOTH) {
429 switch (key) {
431 wcsncpy(string, L"", maxlen);
432 ret = 0;
433 break;
435 retm = mbstowcs(string, product_name_utf8, maxlen);
436 ret = (retm == (size_t)-1)? -1: 0;
437 break;
439 retm = mbstowcs(string, serial_number_utf8, maxlen);
440 ret = (retm == (size_t)-1)? -1: 0;
441 break;
443 default:
444 ret = -1;
445 break;
446 }
447 }
448 else {
449 /* This is a USB device. Find its parent USB Device node. */
451 udev_dev,
452 "usb",
453 "usb_device");
454 if (parent) {
455 const char *str;
456 const char *key_str = NULL;
457
458 if (key >= 0 && key < DEVICE_STRING_COUNT) {
459 key_str = device_string_names[key];
460 } else {
461 ret = -1;
462 goto end;
463 }
464
465 str = hid_wrapper_udev_device_get_sysattr_value(parent, key_str);
466 if (str) {
467 /* Convert the string from UTF-8 to wchar_t */
468 retm = mbstowcs(string, str, maxlen);
469 ret = (retm == (size_t)-1)? -1: 0;
470 goto end;
471 }
472 }
473 }
474 }
475 }
476
477end:
478 free(serial_number_utf8);
479 free(product_name_utf8);
480
482 /* parent and hid_dev don't need to be (and can't be) unref'd.
483 I'm not sure why, but they'll throw double-free() errors. */
485
486 return ret;
487}
void free(void *)
const char * device_string_names[]
Definition hid.c:186
static hid_wrapper_udev_unref_type hid_wrapper_udev_unref
Definition hid.c:86
static hid_wrapper_udev_new_type hid_wrapper_udev_new
Definition hid.c:85
static int parse_uevent_info(const char *uevent, int *bus_type, unsigned short *vendor_id, unsigned short *product_id, char **serial_number_utf8, char **product_name_utf8)
Definition hid.c:334
static hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type hid_wrapper_udev_device_get_parent_with_subsystem_devtype
Definition hid.c:73
static hid_wrapper_udev_device_unref_type hid_wrapper_udev_device_unref
Definition hid.c:77
static hid_wrapper_udev_device_new_from_devnum_type hid_wrapper_udev_device_new_from_devnum
Definition hid.c:75
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620
#define L(s)
Definition I18N.hpp:18
#define stat
Definition unistd.h:53
int device_handle
Definition hid.c:202

References hid_device_::device_handle, DEVICE_STRING_COUNT, DEVICE_STRING_MANUFACTURER, device_string_names, DEVICE_STRING_PRODUCT, DEVICE_STRING_SERIAL, free(), hid_wrapper_udev_device_get_parent_with_subsystem_devtype, hid_wrapper_udev_device_get_sysattr_value, hid_wrapper_udev_device_new_from_devnum, hid_wrapper_udev_device_unref, hid_wrapper_udev_new, hid_wrapper_udev_unref, L, parse_uevent_info(), and stat.

Referenced by hid_get_manufacturer_string(), hid_get_product_string(), and hid_get_serial_number_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hid_wrapper_udev_close()

static void hid_wrapper_udev_close ( )
static
89{
91 dlclose(hid_wrapper_handle);
92 hid_wrapper_handle = NULL;
108}
static hid_wrapper_udev_enumerate_add_match_subsystem_type hid_wrapper_udev_enumerate_add_match_subsystem
Definition hid.c:78
static hid_wrapper_udev_enumerate_unref_type hid_wrapper_udev_enumerate_unref
Definition hid.c:82
static hid_wrapper_udev_device_new_from_syspath_type hid_wrapper_udev_device_new_from_syspath
Definition hid.c:76
static hid_wrapper_udev_enumerate_get_list_entry_type hid_wrapper_udev_enumerate_get_list_entry
Definition hid.c:79
static hid_wrapper_udev_list_entry_get_name_type hid_wrapper_udev_list_entry_get_name
Definition hid.c:83
static hid_wrapper_udev_enumerate_scan_devices_type hid_wrapper_udev_enumerate_scan_devices
Definition hid.c:81
static hid_wrapper_udev_list_entry_get_next_type hid_wrapper_udev_list_entry_get_next
Definition hid.c:84
static hid_wrapper_udev_enumerate_new_type hid_wrapper_udev_enumerate_new
Definition hid.c:80
static hid_wrapper_udev_device_get_devnode_type hid_wrapper_udev_device_get_devnode
Definition hid.c:72
void * hid_wrapper_handle
Definition hid.c:71

References hid_wrapper_handle, hid_wrapper_udev_device_get_devnode, hid_wrapper_udev_device_get_parent_with_subsystem_devtype, hid_wrapper_udev_device_get_sysattr_value, hid_wrapper_udev_device_new_from_devnum, hid_wrapper_udev_device_new_from_syspath, hid_wrapper_udev_device_unref, hid_wrapper_udev_enumerate_add_match_subsystem, hid_wrapper_udev_enumerate_get_list_entry, hid_wrapper_udev_enumerate_new, hid_wrapper_udev_enumerate_scan_devices, hid_wrapper_udev_enumerate_unref, hid_wrapper_udev_list_entry_get_name, hid_wrapper_udev_list_entry_get_next, hid_wrapper_udev_new, and hid_wrapper_udev_unref.

Referenced by hid_exit(), and hid_wrapper_udev_init().

+ Here is the caller graph for this function:

◆ hid_wrapper_udev_init()

static int hid_wrapper_udev_init ( )
static
115{
116 int i;
117
119
120 // Search for the libudev0 or libudev1 library.
121 for (i = 0; i < sizeof(hid_wrapper_libudev_paths) / sizeof(hid_wrapper_libudev_paths[0]); ++ i)
122 if ((hid_wrapper_handle = dlopen(hid_wrapper_libudev_paths[i], RTLD_NOW | RTLD_GLOBAL)) != NULL)
123 break;
124
125 if (hid_wrapper_handle == NULL) {
126 // Error, close the shared library handle and finish.
128 return -1;
129 }
130
131 // Resolve the functions.
147
148 // Were all the funcions resolved?
149 if (hid_wrapper_handle == NULL ||
163 hid_wrapper_udev_new == NULL ||
165 {
166 // Error, close the shared library handle and finish.
168 return -2;
169 }
170
171 // Success.
172 return 0;
173}
struct udev_device *(* hid_wrapper_udev_device_new_from_syspath_type)(struct udev *udev, const char *syspath)
Definition hid.c:59
struct udev *(* hid_wrapper_udev_new_type)(void)
Definition hid.c:68
struct udev_device *(* hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type)(struct udev_device *udev_device, const char *subsystem, const char *devtype)
Definition hid.c:56
struct udev_list_entry *(* hid_wrapper_udev_enumerate_get_list_entry_type)(struct udev_enumerate *udev_enumerate)
Definition hid.c:62
int(* hid_wrapper_udev_enumerate_scan_devices_type)(struct udev_enumerate *udev_enumerate)
Definition hid.c:64
static void hid_wrapper_udev_close()
Definition hid.c:88
struct udev_enumerate *(* hid_wrapper_udev_enumerate_new_type)(struct udev *udev)
Definition hid.c:63
const char *(* hid_wrapper_udev_list_entry_get_name_type)(struct udev_list_entry *list_entry)
Definition hid.c:66
static const char * hid_wrapper_libudev_paths[]
Definition hid.c:110
struct udev_list_entry *(* hid_wrapper_udev_list_entry_get_next_type)(struct udev_list_entry *list_entry)
Definition hid.c:67
struct udev_enumerate *(* hid_wrapper_udev_enumerate_unref_type)(struct udev_enumerate *udev_enumerate)
Definition hid.c:65
struct udev_device *(* hid_wrapper_udev_device_new_from_devnum_type)(struct udev *udev, char type, dev_t devnum)
Definition hid.c:58
struct udev *(* hid_wrapper_udev_unref_type)(struct udev *udev)
Definition hid.c:69
struct udev_device *(* hid_wrapper_udev_device_unref_type)(struct udev_device *udev_device)
Definition hid.c:60
int(* hid_wrapper_udev_enumerate_add_match_subsystem_type)(struct udev_enumerate *udev_enumerate, const char *subsystem)
Definition hid.c:61
const char *(* hid_wrapper_udev_device_get_sysattr_value_type)(struct udev_device *udev_device, const char *sysattr)
Definition hid.c:57
const char *(* hid_wrapper_udev_device_get_devnode_type)(struct udev_device *udev_device)
Definition hid.c:55

References hid_wrapper_handle, hid_wrapper_libudev_paths, hid_wrapper_udev_close(), hid_wrapper_udev_device_get_devnode, hid_wrapper_udev_device_get_parent_with_subsystem_devtype, hid_wrapper_udev_device_get_sysattr_value, hid_wrapper_udev_device_new_from_devnum, hid_wrapper_udev_device_new_from_syspath, hid_wrapper_udev_device_unref, hid_wrapper_udev_enumerate_add_match_subsystem, hid_wrapper_udev_enumerate_get_list_entry, hid_wrapper_udev_enumerate_new, hid_wrapper_udev_enumerate_scan_devices, hid_wrapper_udev_enumerate_unref, hid_wrapper_udev_list_entry_get_name, hid_wrapper_udev_list_entry_get_next, hid_wrapper_udev_new, and hid_wrapper_udev_unref.

Referenced by hid_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_hid_device()

static hid_device * new_hid_device ( void  )
static
232{
233 hid_device *dev = calloc(1, sizeof(hid_device));
234 dev->device_handle = -1;
235 dev->blocking = 1;
236 dev->uses_numbered_reports = 0;
237
238 return dev;
239}
int uses_numbered_reports
Definition hid.c:204
int blocking
Definition hid.c:203
Definition hid.c:201

References hid_device_::blocking, hid_device_::device_handle, and hid_device_::uses_numbered_reports.

◆ parse_uevent_info()

static int parse_uevent_info ( const char *  uevent,
int *  bus_type,
unsigned short *  vendor_id,
unsigned short *  product_id,
char **  serial_number_utf8,
char **  product_name_utf8 
)
static
   type vendor   product

HID_ID=0003:000005AC:00008242

337{
338 char *tmp = strdup(uevent);
339 char *saveptr = NULL;
340 char *line;
341 char *key;
342 char *value;
343
344 int found_id = 0;
345 int found_serial = 0;
346 int found_name = 0;
347
348 line = strtok_r(tmp, "\n", &saveptr);
349 while (line != NULL) {
350 /* line: "KEY=value" */
351 key = line;
352 value = strchr(line, '=');
353 if (!value) {
354 goto next_line;
355 }
356 *value = '\0';
357 value++;
358
359 if (strcmp(key, "HID_ID") == 0) {
364 int ret = sscanf(value, "%x:%hx:%hx", bus_type, vendor_id, product_id);
365 if (ret == 3) {
366 found_id = 1;
367 }
368 } else if (strcmp(key, "HID_NAME") == 0) {
369 /* The caller has to free the product name */
370 *product_name_utf8 = strdup(value);
371 found_name = 1;
372 } else if (strcmp(key, "HID_UNIQ") == 0) {
373 /* The caller has to free the serial number */
374 *serial_number_utf8 = strdup(value);
375 found_serial = 1;
376 }
377
378next_line:
379 line = strtok_r(NULL, "\n", &saveptr);
380 }
381
382 free(tmp);
383 return (found_id && found_name && found_serial);
384}

References free().

Referenced by get_device_string(), and hid_enumerate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uses_numbered_reports()

static int uses_numbered_reports ( __u8 *  report_descriptor,
__u32  size 
)
static
269 {
270 unsigned int i = 0;
271 int size_code;
272 int data_len, key_size;
273
274 while (i < size) {
275 int key = report_descriptor[i];
276
277 /* Check for the Report ID key */
278 if (key == 0x85/*Report ID*/) {
279 /* This device has a Report ID, which means it uses
280 numbered reports. */
281 return 1;
282 }
283
284 //printf("key: %02hhx\n", key);
285
286 if ((key & 0xf0) == 0xf0) {
287 /* This is a Long Item. The next byte contains the
288 length of the data section (value) for this key.
289 See the HID specification, version 1.11, section
290 6.2.2.3, titled "Long Items." */
291 if (i+1 < size)
292 data_len = report_descriptor[i+1];
293 else
294 data_len = 0; /* malformed report */
295 key_size = 3;
296 }
297 else {
298 /* This is a Short Item. The bottom two bits of the
299 key contain the size code for the data section
300 (value) for this key. Refer to the HID
301 specification, version 1.11, section 6.2.2.2,
302 titled "Short Items." */
303 size_code = key & 0x3;
304 switch (size_code) {
305 case 0:
306 case 1:
307 case 2:
308 data_len = size_code;
309 break;
310 case 3:
311 data_len = 4;
312 break;
313 default:
314 /* Can't ever happen since size_code is & 0x3 */
315 data_len = 0;
316 break;
317 };
318 key_size = 1;
319 }
320
321 /* Skip over this key and it's associated data */
322 i += data_len + key_size;
323 }
324
325 /* Didn't find a Report ID key. Device doesn't use numbered reports. */
326 return 0;
327}

Referenced by hid_open_path().

+ Here is the caller graph for this function:

◆ utf8_to_wchar_t()

static wchar_t * utf8_to_wchar_t ( const char *  utf8)
static
244{
245 wchar_t *ret = NULL;
246
247 if (utf8) {
248 size_t wlen = mbstowcs(NULL, utf8, 0);
249 if ((size_t) -1 == wlen) {
250 return wcsdup(L"");
251 }
252 ret = calloc(wlen+1, sizeof(wchar_t));
253 mbstowcs(ret, utf8, wlen+1);
254 ret[wlen] = 0x0000;
255 }
256
257 return ret;
258}

References L.

Referenced by copy_udev_string(), and hid_enumerate().

+ Here is the caller graph for this function:

Variable Documentation

◆ device_string_names

const char* device_string_names[]
Initial value:
= {
"manufacturer",
"product",
"serial",
}

Referenced by get_device_string(), and hid_enumerate().

◆ hid_wrapper_handle

void* hid_wrapper_handle = NULL

◆ hid_wrapper_libudev_paths

const char* hid_wrapper_libudev_paths[]
static
Initial value:
= {
"libudev.so.1", "libudev.so.0"
}

Referenced by hid_wrapper_udev_init().

◆ hid_wrapper_udev_device_get_devnode

hid_wrapper_udev_device_get_devnode_type hid_wrapper_udev_device_get_devnode = NULL
static

◆ hid_wrapper_udev_device_get_parent_with_subsystem_devtype

hid_wrapper_udev_device_get_parent_with_subsystem_devtype_type hid_wrapper_udev_device_get_parent_with_subsystem_devtype = NULL
static

◆ hid_wrapper_udev_device_get_sysattr_value

◆ hid_wrapper_udev_device_new_from_devnum

hid_wrapper_udev_device_new_from_devnum_type hid_wrapper_udev_device_new_from_devnum = NULL
static

◆ hid_wrapper_udev_device_new_from_syspath

hid_wrapper_udev_device_new_from_syspath_type hid_wrapper_udev_device_new_from_syspath = NULL
static

◆ hid_wrapper_udev_device_unref

◆ hid_wrapper_udev_enumerate_add_match_subsystem

hid_wrapper_udev_enumerate_add_match_subsystem_type hid_wrapper_udev_enumerate_add_match_subsystem = NULL
static

◆ hid_wrapper_udev_enumerate_get_list_entry

hid_wrapper_udev_enumerate_get_list_entry_type hid_wrapper_udev_enumerate_get_list_entry = NULL
static

◆ hid_wrapper_udev_enumerate_new

hid_wrapper_udev_enumerate_new_type hid_wrapper_udev_enumerate_new = NULL
static

◆ hid_wrapper_udev_enumerate_scan_devices

hid_wrapper_udev_enumerate_scan_devices_type hid_wrapper_udev_enumerate_scan_devices = NULL
static

◆ hid_wrapper_udev_enumerate_unref

hid_wrapper_udev_enumerate_unref_type hid_wrapper_udev_enumerate_unref = NULL
static

◆ hid_wrapper_udev_list_entry_get_name

hid_wrapper_udev_list_entry_get_name_type hid_wrapper_udev_list_entry_get_name = NULL
static

◆ hid_wrapper_udev_list_entry_get_next

hid_wrapper_udev_list_entry_get_next_type hid_wrapper_udev_list_entry_get_next = NULL
static

◆ hid_wrapper_udev_new

◆ hid_wrapper_udev_unref

◆ kernel_version

__u32 kernel_version = 0
static

Referenced by hid_init(), and hid_read_timeout().