Debian Codegraph @

xpp/xtalk/xusb_common.h

raw
1 #ifndef XUSB_COMMON_H
2 #define XUSB_COMMON_H
3 /*
4 * Written by Oron Peled <[email protected]>
5 * Copyright (C) 2012, Xorcom
6 *
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25 #include <limits.h>
26 #include <xtalk/xusb.h>
27
28 /*
29 * XTALK_OPTIONS:
30 * - "use-clear-halt"
31 * - "no-use-clear-halt"
32 */
33 int xtalk_parse_options(void);
34 int xtalk_option_use_clear_halt(void);
35
36 enum xusb_transfer_type {
37 XUSB_TT_ILLEGAL = 0,
38 XUSB_TT_BULK,
39 XUSB_TT_INTERRUPT,
40 };
41
42 struct xusb_iface {
43 struct xusb_device *xusb_device;
44 int interface_num;
45 int ep_out;
46 int ep_in;
47 enum xusb_transfer_type transfer_type;
48 int is_claimed;
49 char iInterface[BUFSIZ];
50 };
51 struct libusb_implementation;
52
53 #define XUSB_MAX_INTERFACES 32
54
55 struct xusb_device {
56 struct libusb_implementation *impl;
57 const struct xusb_spec *spec;
58 int idVendor;
59 int idProduct;
60 char iManufacturer[BUFSIZ];
61 char iProduct[BUFSIZ];
62 char iSerialNumber[BUFSIZ];
63 char iInterface[BUFSIZ];
64 char devpath_tail[PATH_MAX + 1];
65 int bus_num;
66 int device_num;
67 int is_usb2;
68 size_t packet_size;
69 struct xusb_iface *interfaces[XUSB_MAX_INTERFACES];
70 };
71
72 #define EP_OUT(iface) ((iface)->ep_out)
73 #define EP_IN(iface) ((iface)->ep_in)
74
75 int match_devpath(const char *path, const char *tail);
76 int match_device(const struct xusb_device *xusb_device,
77 const struct xusb_spec *spec);
78 void xusb_list_dump(struct xlist_node *xusb_list);
79 void xusb_destroy_interface(struct xusb_iface *iface);
80 int xusb_close(struct xusb_device *xusb_device);
81
82 enum xusb_transfer_type xusb_transfer_type(const struct xusb_iface *iface);
83 const char *xusb_tt_name(enum xusb_transfer_type tt);
84
85
86 int xusb_printf(const struct xusb_iface *iface, int level, int debug_mask,
87 const char *prefix, const char *fmt, ...);
88
89 int xusb_printf_details(const struct xusb_iface *iface, int level, int debug_mask,
90 const char *file, int line, const char *severity, const char *func,
91 const char *fmt, ...);
92
93 #define XUSB_PRINT(iface, level, fmt, arg...) \
94 xusb_printf(iface, LOG_ ## level, 0, #level ": ", fmt, ## arg)
95
96 #define XUSB_PRINT_DETAILS(iface, level, debug_mask, fmt, arg...) \
97 xusb_printf_details(iface, LOG_ ## level, debug_mask, \
98 __FILE__, __LINE__, #level, __func__, fmt, ## arg)
99
100 #define XUSB_INFO(iface, fmt, arg...) XUSB_PRINT(iface, INFO, fmt, ## arg)
101 #define XUSB_ERR(iface, fmt, arg...) XUSB_PRINT_DETAILS(iface, ERR, 0, fmt, ## arg)
102 #define XUSB_DBG(iface, fmt, arg...) XUSB_PRINT_DETAILS(iface, DEBUG, DBG_MASK, fmt, ## arg)
103
104 #endif /* XUSB_COMMON_H */