usbhost.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __USB_HOST_H
18 #define __USB_HOST_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include <linux/version.h>
28 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
29 #include <linux/usb/ch9.h>
30 #else
31 #include <linux/usb_ch9.h>
32 #endif
33 
34 struct usb_host_context;
35 struct usb_endpoint_descriptor;
36 
38  unsigned char* config;
39  unsigned char* config_end;
40  unsigned char* curr_desc;
41 };
42 
44 {
45  struct usb_device *dev;
46  void* buffer;
50  void *private_data; /* struct usbdevfs_urb* */
51  int endpoint;
52  void *client_data; /* free for use by client */
53 };
54 
55 /* Callback for notification when new USB devices are attached.
56  * Return true to exit from usb_host_run.
57  */
58 typedef int (* usb_device_added_cb)(const char *dev_name, void *client_data);
59 
60 /* Callback for notification when USB devices are removed.
61  * Return true to exit from usb_host_run.
62  */
63 typedef int (* usb_device_removed_cb)(const char *dev_name, void *client_data);
64 
65 /* Callback indicating that initial device discovery is done.
66  * Return true to exit from usb_host_run.
67  */
68 typedef int (* usb_discovery_done_cb)(void *client_data);
69 
70 /* Call this to initialize the USB host library. */
71 struct usb_host_context *usb_host_init(void);
72 
73 /* Call this to cleanup the USB host library. */
74 void usb_host_cleanup(struct usb_host_context *context);
75 
76 /* Call this to get the inotify file descriptor. */
77 int usb_host_get_fd(struct usb_host_context *context);
78 
79 /* Call this to initialize the usb host context. */
80 int usb_host_load(struct usb_host_context *context,
81  usb_device_added_cb added_cb,
82  usb_device_removed_cb removed_cb,
83  usb_discovery_done_cb discovery_done_cb,
84  void *client_data);
85 
86 /* Call this to read and handle occuring usb event. */
87 int usb_host_read_event(struct usb_host_context *context);
88 
89 /* Call this to monitor the USB bus for new and removed devices.
90  * This is intended to be called from a dedicated thread,
91  * as it will not return until one of the callbacks returns true.
92  * added_cb will be called immediately for each existing USB device,
93  * and subsequently each time a new device is added.
94  * removed_cb is called when USB devices are removed from the bus.
95  * discovery_done_cb is called after the initial discovery of already
96  * connected devices is complete.
97  */
98 void usb_host_run(struct usb_host_context *context,
99  usb_device_added_cb added_cb,
100  usb_device_removed_cb removed_cb,
101  usb_discovery_done_cb discovery_done_cb,
102  void *client_data);
103 
104 /* Creates a usb_device object for a USB device */
105 struct usb_device *usb_device_open(const char *dev_name);
106 
107 /* Releases all resources associated with the USB device */
108 void usb_device_close(struct usb_device *device);
109 
110 /* Creates a usb_device object for already open USB device */
111 struct usb_device *usb_device_new(const char *dev_name, int fd);
112 
113 /* Returns the file descriptor for the usb_device */
114 int usb_device_get_fd(struct usb_device *device);
115 
116 /* Returns the name for the USB device, which is the same as
117  * the dev_name passed to usb_device_open()
118  */
119 const char* usb_device_get_name(struct usb_device *device);
120 
121 /* Returns a unique ID for the device.
122  *Currently this is generated from the dev_name path.
123  */
125 
126 /* Returns a unique ID for the device name.
127  * Currently this is generated from the device path.
128  */
130 
131 /* Returns the device name for the unique ID.
132  * Call free() to deallocate the returned string */
134 
135 /* Returns the USB vendor ID from the device descriptor for the USB device */
137 
138 /* Returns the USB product ID from the device descriptor for the USB device */
140 
141 /* Returns a pointer to device descriptor */
142 const struct usb_device_descriptor* usb_device_get_device_descriptor(struct usb_device *device);
143 
144 /* Returns a USB descriptor string for the given string ID.
145  * Return value: < 0 on error. 0 on success.
146  * The string is returned in ucs2_out in USB-native UCS-2 encoding.
147  *
148  * parameters:
149  * id - the string descriptor index.
150  * timeout - in milliseconds (see Documentation/driver-api/usb/usb.rst)
151  * ucs2_out - Must point to null on call.
152  * Will be filled in with a buffer on success.
153  * If this is non-null on return, it must be free()d.
154  * response_size - size, in bytes, of ucs-2 string in ucs2_out.
155  * The size isn't guaranteed to include null termination.
156  * Call free() to free the result when you are done with it.
157  */
158 int usb_device_get_string_ucs2(struct usb_device* device, int id, int timeout, void** ucs2_out,
159  size_t* response_size);
160 
161 /* Returns the length in bytes read into the raw descriptors array */
163 
164 /* Returns a pointer to the raw descriptors array */
165 const unsigned char* usb_device_get_raw_descriptors(const struct usb_device* device);
166 
167 /* Returns a USB descriptor string for the given string ID.
168  * Used to implement usb_device_get_manufacturer_name,
169  * usb_device_get_product_name and usb_device_get_serial.
170  * Returns ascii - non ascii characters will be replaced with '?'.
171  * Call free() to free the result when you are done with it.
172  */
173 char* usb_device_get_string(struct usb_device *device, int id, int timeout);
174 
175 /* Returns the manufacturer name for the USB device.
176  * Call free() to free the result when you are done with it.
177  */
179 
180 /* Returns the product name for the USB device.
181  * Call free() to free the result when you are done with it.
182  */
184 
185 /* Returns the version number for the USB device.
186  */
188 
189 /* Returns the USB serial number for the USB device.
190  * Call free() to free the result when you are done with it.
191  */
192 char* usb_device_get_serial(struct usb_device *device, int timeout);
193 
194 /* Returns true if we have write access to the USB device,
195  * and false if we only have access to the USB device configuration.
196  */
198 
199 /* Initializes a usb_descriptor_iter, which can be used to iterate through all
200  * the USB descriptors for a USB device.
201  */
203 
204 /* Returns the next USB descriptor for a device, or NULL if we have reached the
205  * end of the list.
206  */
207 struct usb_descriptor_header *usb_descriptor_iter_next(struct usb_descriptor_iter *iter);
208 
209 /* Claims the specified interface of a USB device */
210 int usb_device_claim_interface(struct usb_device *device, unsigned int interface);
211 
212 /* Releases the specified interface of a USB device */
213 int usb_device_release_interface(struct usb_device *device, unsigned int interface);
214 
215 /* Requests the kernel to connect or disconnect its driver for the specified interface.
216  * This can be used to ask the kernel to disconnect its driver for a device
217  * so usb_device_claim_interface can claim it instead.
218  */
220  unsigned int interface, int connect);
221 
222 /* Sets the current configuration for the device to the specified configuration */
223 int usb_device_set_configuration(struct usb_device *device, int configuration);
224 
225 /* Sets the specified interface of a USB device */
226 int usb_device_set_interface(struct usb_device *device, unsigned int interface,
227  unsigned int alt_setting);
228 
229 /* Sends a control message to the specified device on endpoint zero */
231  int requestType,
232  int request,
233  int value,
234  int index,
235  void* buffer,
236  int length,
237  unsigned int timeout);
238 
239 /* Reads or writes on a bulk endpoint.
240  * Returns number of bytes transferred, or negative value for error.
241  */
243  int endpoint,
244  void* buffer,
245  unsigned int length,
246  unsigned int timeout);
247 
249 int usb_device_reset(struct usb_device *device);
250 
251 /* Creates a new usb_request. */
252 struct usb_request *usb_request_new(struct usb_device *dev,
253  const struct usb_endpoint_descriptor *ep_desc);
254 
255 /* Releases all resources associated with the request */
256 void usb_request_free(struct usb_request *req);
257 
258 /* Submits a read or write request on the specified device */
259 int usb_request_queue(struct usb_request *req);
260 
261 /* Waits for the results of a previous usb_request_queue operation. timeoutMillis == -1 requests
262  * to wait forever.
263  * Returns a usb_request, or NULL for error.
264  */
265 struct usb_request *usb_request_wait(struct usb_device *dev, int timeoutMillis);
266 
267 /* Cancels a pending usb_request_queue() operation. */
268 int usb_request_cancel(struct usb_request *req);
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 #endif /* __USB_HOST_H */
void * buffer
Definition: usbhost.h:46
void usb_request_free(struct usb_request *req)
Definition: usbhost.c:720
struct usb_request * usb_request_wait(struct usb_device *dev, int timeoutMillis)
Definition: usbhost.c:742
int(* usb_device_removed_cb)(const char *dev_name, void *client_data)
Definition: usbhost.h:63
const struct usb_device_descriptor * usb_device_get_device_descriptor(struct usb_device *device)
Definition: usbhost.c:462
struct usb_request * usb_request_new(struct usb_device *dev, const struct usb_endpoint_descriptor *ep_desc)
Definition: usbhost.c:687
GLuint const GLchar * name
int usb_host_load(struct usb_host_context *context, usb_device_added_cb added_cb, usb_device_removed_cb removed_cb, usb_discovery_done_cb discovery_done_cb, void *client_data)
Definition: usbhost.c:190
int usb_device_set_configuration(struct usb_device *device, int configuration)
Definition: usbhost.c:625
int usb_device_set_interface(struct usb_device *device, unsigned int interface, unsigned int alt_setting)
Definition: usbhost.c:630
uint16_t usb_device_get_vendor_id(struct usb_device *device)
Definition: usbhost.c:450
int usb_device_get_unique_id(struct usb_device *device)
Definition: usbhost.c:427
unsigned char * config_end
Definition: usbhost.h:39
const char * usb_device_get_name(struct usb_device *device)
Definition: usbhost.c:422
GLfloat value
int usb_device_bulk_transfer(struct usb_device *device, int endpoint, void *buffer, unsigned int length, unsigned int timeout)
Definition: usbhost.c:666
struct usb_device * dev
Definition: usbhost.h:45
unsigned char * config
Definition: usbhost.h:38
unsigned short uint16_t
Definition: stdint.h:79
int(* usb_discovery_done_cb)(void *client_data)
Definition: usbhost.h:68
struct usb_descriptor_header * usb_descriptor_iter_next(struct usb_descriptor_iter *iter)
Definition: usbhost.c:594
GLenum GLfloat * buffer
unsigned char * curr_desc
Definition: usbhost.h:40
int usb_device_control_transfer(struct usb_device *device, int requestType, int request, int value, int index, void *buffer, int length, unsigned int timeout)
Definition: usbhost.c:640
GLuint index
char * usb_device_get_manufacturer_name(struct usb_device *device, int timeout)
Definition: usbhost.c:558
void * client_data
Definition: usbhost.h:52
int endpoint
Definition: usbhost.h:51
int usb_device_get_fd(struct usb_device *device)
Definition: usbhost.c:415
char * usb_device_get_name_from_unique_id(int id)
Definition: usbhost.c:441
int usb_device_claim_interface(struct usb_device *device, unsigned int interface)
Definition: usbhost.c:604
int usb_device_connect_kernel_driver(struct usb_device *device, unsigned int interface, int connect)
Definition: usbhost.c:614
def connect(spec=None)
Definition: acroname.py:67
int usb_device_is_writeable(struct usb_device *device)
Definition: usbhost.c:582
uint16_t usb_device_get_product_id(struct usb_device *device)
Definition: usbhost.c:456
int(* usb_device_added_cb)(const char *dev_name, void *client_data)
Definition: usbhost.h:58
int actual_length
Definition: usbhost.h:48
size_t usb_device_get_descriptors_length(const struct usb_device *device)
Definition: usbhost.c:466
int usb_device_get_string_ucs2(struct usb_device *device, int id, int timeout, void **ucs2_out, size_t *response_size)
Definition: usbhost.c:488
void usb_host_run(struct usb_host_context *context, usb_device_added_cb added_cb, usb_device_removed_cb removed_cb, usb_discovery_done_cb discovery_done_cb, void *client_data)
Definition: usbhost.c:307
int usb_device_get_unique_id_from_name(const char *name)
Definition: usbhost.c:434
int usb_host_get_fd(struct usb_host_context *context)
Definition: usbhost.c:185
struct usb_device * usb_device_new(const char *dev_name, int fd)
Definition: usbhost.c:370
int buffer_length
Definition: usbhost.h:47
int usb_request_cancel(struct usb_request *req)
Definition: usbhost.c:776
GLbitfield GLuint64 timeout
char * usb_device_get_product_name(struct usb_device *device, int timeout)
Definition: usbhost.c:564
char * usb_device_get_serial(struct usb_device *device, int timeout)
Definition: usbhost.c:576
const unsigned char * usb_device_get_raw_descriptors(const struct usb_device *device)
Definition: usbhost.c:470
int usb_device_release_interface(struct usb_device *device, unsigned int interface)
Definition: usbhost.c:609
void usb_host_cleanup(struct usb_host_context *context)
Definition: usbhost.c:179
void * private_data
Definition: usbhost.h:50
void usb_device_close(struct usb_device *device)
Definition: usbhost.c:364
GLenum GLuint GLenum GLsizei length
int usb_request_queue(struct usb_request *req)
Definition: usbhost.c:726
GLuint64 GLenum GLint fd
Definition: glext.h:7768
char dev_name[64]
Definition: usbhost.c:82
int usb_device_get_version(struct usb_device *device)
Definition: usbhost.c:570
struct usb_device * usb_device_open(const char *dev_name)
Definition: usbhost.c:323
int usb_device_reset(struct usb_device *device)
Definition: usbhost.c:682
void usb_descriptor_iter_init(struct usb_device *device, struct usb_descriptor_iter *iter)
Definition: usbhost.c:587
int usb_host_read_event(struct usb_host_context *context)
Definition: usbhost.c:229
struct usb_host_context * usb_host_init(void)
Definition: usbhost.c:163
auto device
Definition: pyrs_net.cpp:17
int max_packet_size
Definition: usbhost.h:49
char * usb_device_get_string(struct usb_device *device, int id, int timeout)
Definition: usbhost.c:537


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:13