This source file includes following definitions.
- USBF_NORMAL_COMPLETION
- USBF_IN_PROGRESS
- USBF_NOT_STARTED
- USBF_INVAL
- USBF_NOMEM
- USBF_CANCELLED
- USBF_BAD_ADDRESS
- USBF_IOERROR
- USBF_TIMEOUT
- USBF_SHORT_XFER
- USBF_STALLED
- USBF_ERROR_MAX
- usbf_status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifndef _USBF_H_
24 #define _USBF_H_
25
26 typedef struct usbf_function *usbf_function_handle;
27 typedef struct usbf_bus *usbf_bus_handle;
28 typedef struct usbf_device *usbf_device_handle;
29 typedef struct usbf_config *usbf_config_handle;
30 typedef struct usbf_interface *usbf_interface_handle;
31 typedef struct usbf_endpoint *usbf_endpoint_handle;
32 typedef struct usbf_pipe *usbf_pipe_handle;
33 typedef struct usbf_xfer *usbf_xfer_handle;
34 typedef void *usbf_private_handle;
35
36
37
38
39 typedef enum {
40 USBF_NORMAL_COMPLETION = 0,
41 USBF_IN_PROGRESS,
42
43 USBF_NOT_STARTED,
44 USBF_INVAL,
45 USBF_NOMEM,
46 USBF_CANCELLED,
47 USBF_BAD_ADDRESS,
48 USBF_IOERROR,
49 USBF_TIMEOUT,
50 USBF_SHORT_XFER,
51 USBF_STALLED,
52 USBF_ERROR_MAX
53 } usbf_status;
54 #define USBF_ERROR_STRS { \
55 "NORMAL_COMPLETION", \
56 "IN_PROGRESS", \
57 "NOT_STARTED", \
58 "INVAL", \
59 "NOMEM", \
60 "CANCELLED", \
61 "BAD_ADDRESS", \
62 "IOERROR", \
63 "TIMEOUT", \
64 "SHORT_XFER", \
65 "STALLED", \
66 };
67
68 typedef void (*usbf_callback)(usbf_xfer_handle, usbf_private_handle,
69 usbf_status);
70
71
72
73
74 struct usbf_attach_arg {
75 usbf_device_handle device;
76 };
77
78 struct usbf_function_methods {
79 usbf_status (*set_config)(usbf_function_handle, usbf_config_handle);
80 usbf_status (*do_request)(usbf_function_handle,
81 usb_device_request_t *req, void **data);
82 };
83
84 struct usbf_function {
85 struct device bdev;
86
87 struct usbf_function_methods *methods;
88 };
89
90 #define USBF_EMPTY_STRING_ID (USB_LANGUAGE_TABLE+1)
91 #define USBF_STRING_ID_MIN (USB_LANGUAGE_TABLE+2)
92 #define USBF_STRING_ID_MAX 255
93
94
95
96
97
98
99 const char *usbf_errstr(usbf_status);
100
101
102 void usbf_devinfo_setup(usbf_device_handle, u_int8_t, u_int8_t,
103 u_int8_t, u_int16_t, u_int16_t, u_int16_t, const char *,
104 const char *, const char *);
105 char *usbf_devinfo_alloc(usbf_device_handle);
106 void usbf_devinfo_free(char *);
107 usb_device_descriptor_t *usbf_device_descriptor(usbf_device_handle);
108 usb_string_descriptor_t *usbf_string_descriptor(usbf_device_handle, u_int8_t);
109 usb_config_descriptor_t *usbf_config_descriptor(usbf_device_handle, u_int8_t);
110
111
112 u_int8_t usbf_add_string(usbf_device_handle, const char *);
113 usbf_status usbf_add_config(usbf_device_handle, usbf_config_handle *);
114 usbf_status usbf_add_config_desc(usbf_config_handle, usb_descriptor_t *,
115 usb_descriptor_t **);
116 usbf_status usbf_add_interface(usbf_config_handle, u_int8_t, u_int8_t,
117 u_int8_t, const char *, usbf_interface_handle *);
118 usbf_status usbf_add_endpoint(usbf_interface_handle, u_int8_t,
119 u_int8_t, u_int16_t, u_int8_t, usbf_endpoint_handle *);
120 usbf_status usbf_end_config(usbf_config_handle);
121 usbf_endpoint_handle usbf_config_endpoint(usbf_config_handle, u_int8_t);
122
123
124 int usbf_interface_number(usbf_interface_handle);
125 usbf_endpoint_handle usbf_iface_endpoint(usbf_interface_handle, u_int8_t);
126
127
128 u_int8_t usbf_endpoint_address(usbf_endpoint_handle);
129 u_int8_t usbf_endpoint_attributes(usbf_endpoint_handle);
130 #define usbf_endpoint_index(e) UE_GET_ADDR(usbf_endpoint_address((e)))
131 #define usbf_endpoint_dir(e) UE_GET_DIR(usbf_endpoint_address((e)))
132 #define usbf_endpoint_type(e) UE_GET_XFERTYPE(usbf_endpoint_attributes((e)))
133
134
135 usbf_status usbf_open_pipe(usbf_interface_handle, u_int8_t,
136 usbf_pipe_handle *);
137 void usbf_abort_pipe(usbf_pipe_handle);
138 void usbf_close_pipe(usbf_pipe_handle);
139 void usbf_stall_pipe(usbf_pipe_handle);
140
141
142 usbf_xfer_handle usbf_alloc_xfer(usbf_device_handle);
143 void usbf_free_xfer(usbf_xfer_handle);
144 void *usbf_alloc_buffer(usbf_xfer_handle, u_int32_t);
145 void usbf_free_buffer(usbf_xfer_handle);
146 void usbf_setup_xfer(usbf_xfer_handle, usbf_pipe_handle,
147 usbf_private_handle, void *, u_int32_t, u_int16_t,
148 u_int32_t, usbf_callback);
149 void usbf_setup_default_xfer(usbf_xfer_handle, usbf_pipe_handle,
150 usbf_private_handle, usb_device_request_t *, u_int16_t,
151 u_int32_t, usbf_callback);
152 void usbf_get_xfer_status(usbf_xfer_handle, usbf_private_handle *,
153 void **, u_int32_t *, usbf_status *);
154 usbf_status usbf_transfer(usbf_xfer_handle);
155
156
157
158
159
160
161 struct usbf_task {
162 TAILQ_ENTRY(usbf_task) next;
163 void (*fun)(void *);
164 void *arg;
165 char onqueue;
166 };
167
168 void usbf_add_task(usbf_device_handle, struct usbf_task *);
169 void usbf_rem_task(usbf_device_handle, struct usbf_task *);
170 #define usbf_init_task(t, f, a) ((t)->fun=(f), (t)->arg=(a), (t)->onqueue=0)
171
172 #endif